Another simple, fast solution, based on a snippet found on page 23 of Dominus's book, Higher-Order Perl:

sub short { my $path = shift; $path = ˜ s{.*/}{}; $path; }
...or as a callback:
my $short = sub { my $path = shift; $path =~ s{.*/}{}; $path; };
Callback example:
perl -Mstrict -we ' + my $dir = shift or die "missing dir name...\n"; die "not a directory\n" unless -d $dir; my $short = sub { my $path = shift; $path =~ s{.*/}{}; $path; }; sub dosub { my $_dir = shift; opendir my $dh, $_dir or die "could not open $_dir\n"; while ( my $file = readdir($dh) ) { next if $file eq "." || $file eq ".."; if ( -d "$_dir/$file" ) { dosub ("$_dir/$file"); } else { print "full: $_dir/$file\n"; print "shortened: ", $short->("$_ +dir/$file"), "\n\n\n"; } } } dosub($dir); ' temp01 __output__ full: temp01/subtemp01/subsubtemp01/file01 shortened: file01 full: temp01/subtemp01/subsubtemp02/file02 shortened: file02 full: temp01/subtemp01/subsubtemp03/file03 shortened: file03 full: temp01/subtemp01/subsubtemp04/file04 shortened: file04

Edit: shortened output a bit...


In reply to Re: Regex for ignoring paths by dbuckhal
in thread Regex for ignoring paths by Amblikai

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.