Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: More than one way to do it???

by marius (Hermit)
on Dec 07, 2000 at 00:50 UTC ( [id://45311]=note: print w/replies, xml ) Need Help??


in reply to More than one way to do it???

i modified the regex to be s#.*/(.*)#$1#, and it seems to work for me.

Incidentally, perl complains about the \1 because you are doing it from the command line, and your shell is subject to processing escape characters as well. If you put the code above into a file, and do perl file.pl, it doesn't complain about using a \1.

-marius

Replies are listed 'Best First'.
Re: Answer: More than one way to do it???
by chipmunk (Parson) on Dec 07, 2000 at 01:28 UTC
    That explanation isn't accurate. Perl complains about using \1 in the right-hand side of a substitution because using $1 is preferred. Whether the script is entered on the command line or not isn't important.
    #!perl -w use diagnostics; $_ = 'foo'; s/(.)/\1/;
    This script produces the following output:
    \1 better written as $1 at tmp.pl line 5 (#1) (W) Outside of patterns, backreferences live on as variables. The + use of backslashes is grandfathered on the right-hand side of a substitution, but stylistically it's better to use the variable fo +rm because other Perl programmers will expect it, and it works better if there are more than 9 backreferences.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://45311]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-24 16:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found