SPUG: regular expression difficulty, plus compiled perl

Scott Blachowicz scott at sabmail.rresearch.com
Tue Mar 28 13:51:01 CST 2000


On Tue, Mar 28, 2000 at 11:39:52AM -0800, Scott Blachowicz wrote:
> > Yours that does work:
> > $test =~ m#(.*\\)#;.
> 
> The parens actually capture part of the matching string.

And another way to accomplish the same thing is to use the
substitution operator:

	($test = $0) =~ s#(.*\\).*#$1#;

which assigns $0 to the variable $test, then does a 's' command on it
effectively getting rid of the part after the first backslash.  If
there's no backslash, then the match pattern doesn't, so no
substitution is made.  Since you're going after the the dir name,
that's not good, so maybe something like this would do it:

	($test = $0) =~ s#(.*\\).*#$1#;
	$test = "." if $0 !~ /\\/;

to set it to "." (the current dir) if there are no backslashes in $0.

Scott

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace "action" below by subscribe or unsubscribe
           Email to majordomo at pm.org: "action" spug-list your_address





More information about the spug-list mailing list