in reply to using basename on a list of filesnames

This is an XY Problem. You are using basename correctly. Try changing print "$file\n"; to push @Files, $file; and adding my $file = join(' ', @Files); just before line 24. Meditate upon those changes and you will gain understanding.

Replies are listed 'Best First'.
Re^2: using basename on a list of filesnames
by 1nickt (Canon) on Nov 13, 2019 at 05:03 UTC

    How is it correct usage to pass a list of filenames?! Only the first is handled as a filename; the rest are possible suffix matches.

    From the doc:

    $basename = basename($fullname,@suffixlist);

    $ perl -MFile::Basename -wE 'say basename("foo.psd","bar.psd",".psd")' foo


    The way forward always starts with a minimal test.

      You are right. I had misread the code because passing the entire list a loop is iterating over instead of the current item is not a mistake I have ever made.

      The change I suggested is still needed, since our questioner is currently iterating over a list, but only passing a single value to his output routine.