Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Interesting line which I read from Monk's snippets

by chanio (Priest)
on Jan 31, 2006 at 22:50 UTC ( [id://526912]=note: print w/replies, xml ) Need Help??


in reply to Interesting line which I read from Monk's snippets

I need to try $0 first!

If I am calling the script from far away (for example in windows: C:\perl\bin\eraseme.pl) , then $0 has also the path attached to the name... ($0 eq 'C:\perl\bin\eraseme.pl'). So, it would not work as expected.

I should first, get rid of the path...

$0=~s/^.*[\\\/]//;
UPDATE: see a better way with liverpole's comment.

Replies are listed 'Best First'.
Re^2: Interesting line which I read from Monk's snippets
by liverpole (Monsignor) on Feb 03, 2006 at 12:30 UTC
    An easier way to get rid of the path is:
    use File::Basename; my $iam = basename $0;
    I used to use a regex substitution instead, and my fingers still "remember" the sequence: (my $iam = $0) =~ s,.*/,,;

    But when I started coding in Perl for Windows in addition to (Li|U)n[ui]x, it was unwieldy to use a regex which accounted for all the different pathname symbols.  Someone told me about the File::Basename method, and I've used it ever since; it's easier to remember, easier to type, and part of the standard Perl distro on both systems.


    @ARGV=split//,"/:L"; map{print substr crypt($_,ord pop),2,3}qw"PerlyouC READPIPE provides"

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2024-03-28 10:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found