in reply to Anything comparable to argv0 from C in Perl?

I usually use this to get only the last part of your script name:
#!/usr/bin/perl -w use strict; my @a=split(/\//,$0); my $myname=pop @a; if ($#ARGV != -1) { die "Usage: $myname parameters\n"; }

Replies are listed 'Best First'.
Re: Re: Anything comparable to argv0 from C in Perl?
by DrManhattan (Chaplain) on Mar 13, 2003 at 21:38 UTC
    Here's a one-liner to extract the base name from the full path without a temporary array:
    my ($basename) = $0 =~ m/.*\/(.*)/;
    You can also use split() like this:
    my $basename = (split /\//, $0)[-1];

    -Matt