[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] getting filenames



At 10:51 96-04-26, kevin mason wrote:

>is it possible to get the "regular" filenames from @ARGV instead of the
>full pathnames... if not, i guess i'll have to massage an
>@ARGV copy with substitution?

Not directly, as you'd not be able to open the files, then!  If you
*really* want to do that, here's a hack:
    grep( s/^.*://, @ARGV );

Although I don't know why you'd want this.  If what you mean is that
you'd like the base name of a given full path, use a function like:

sub basename {
    local( $path, $base ) = $_[0] =~ /^(.*:)?(.*)$/;
    wantarray ? ( $path, $base ) : $base;
}

on each individual file name.  This will let you do things like:
while( <> ) {
    print "Reading from file " . &basename( $ARGV ), "\n"
        if $. == 1;
# your code here
    close( ARGV ) if eof( ARGV ); # reset line numbers
}

--Hal
Hal Wine <hal@dtor.com>     voice: 510/482-0597