Closed Thread Icon

Topic awaiting preservation: RegEx/Perl (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=25179" title="Pages that link to Topic awaiting preservation: RegEx/Perl (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: RegEx/Perl <span class="small">(Page 1 of 1)</span>\

 
u-neek
Bipolar (III) Inmate

From: Berlin, Germany
Insane since: Jan 2001

posted posted 03-04-2005 17:45

Hi there!
It's been a while...


Is it possible to make this a One-Liner?

code:
$ENV{'SCRIPT_FILENAME'} =~ m/[^\/\\]+$/;	 # /../CGI-Executables/index.cgi
my $script_dir = $`; # /../CGI-Executables/



(Edited by u-neek on 03-04-2005 17:47)

hyperbole
Paranoid (IV) Inmate

From: Madison, Indiana, USA
Insane since: Aug 2000

posted posted 03-04-2005 17:52

Hi u-neek,

Long time non see.

I think what you want is

code:
($script_dir) - ( $ENV{'SCRIPT_FILENAME'} =~ m:([^/\\]+)$:);



I'm not really familiar with the $ values built-in to perl, but I think $` is the matched string. However, your variable name script_dir indicates otherwise.

So maybe what you want is

code:
($script_dir) - ( $ENV{'SCRIPT_FILENAME'} =~ m:^(.*)/[^/\\]+$:);





.

-- not necessarily stoned... just beautiful.

hyperbole
Paranoid (IV) Inmate

From: Madison, Indiana, USA
Insane since: Aug 2000

posted posted 03-04-2005 22:46

OK, I went to the documentation and looked up what $` does: It is a copy of everything in the string up to the point where the regular expression starts to match.

So the second one is the one you want.



.

-- not necessarily stoned... just beautiful.

u-neek
Bipolar (III) Inmate

From: Berlin, Germany
Insane since: Jan 2001

posted posted 03-05-2005 14:52

Thank you for your quick response.

This is my final line:

code:
my ($script_dir) = (($0 or $ENV{'SCRIPT_FILENAME'}) =~ m{^(.*/)[^/\\]+$});



And:
$´ what you said.
$` contains the copy of the string after the regular expression.
$+ contains the matched string.

« BackwardsOnwards »

Show Forum Drop Down Menu