in reply to Issue with capturing a string after splitting on "/"

Our fellow Monks have provided solutions to your particular problem. Here is yet another way to retrieve the leaf directory (or file) from a long path. It uses the splitdir function from the File::Spec core module. splitdir splits up an OS-independent path specifier, and returns a list. The [-1] just grabs the last element of the list.
use strict; use warnings; use File::Spec; my $dir = (File::Spec->splitdir('/path/to/dir_i_want'))[-1]; print "$dir\n"; __END__ dir_i_want

Replies are listed 'Best First'.
Re^2: Issue with capturing a string after splitting on "/"
by lomSpace (Scribe) on Feb 06, 2009 at 15:12 UTC

    Hi toolic!
    Yes, the monks have provided me with far more than I had expected
    and I am grateful. The use File::Spec saves a lot of time.
    Thanks!
    Lom Space