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

Re: [MacPerl] getting filenames



At 10:51 26/04/96 -0700, kevin mason <km@primenet.com> wrote:
>is it possible to get the "regular" filenames from @ARGV instead of the
>full pathnames which include every folder and volume down to the hard
>drive, separated by colons?

If $fullpath is a string with the full path name, get both the path and the
file name using:

        (($dir,$file)=$fullpath~=/(.*:)(.*)/) or $file=$fullpath,$dir='';

This works because of the greedy nature of pattern matching: everything up
to the last colon is absorbed into $dir, and the rest gets into $file.

If this fails (because there is no colon), the second part is executed: $dir
is empty, and $file gets the whole filename.

Incorporating this principle into your example, I'd make this:

        @files=();
        foreach (@ARGV) {  # $_ instead of fullpath
                s/.*://;  # delete the path upto the last colon
                push @files;
        }


--- Embracing the KIS principle: Keep It Simple