Programming Tutorials

Extract filename from full path using perl

By: Sam Chen in Perl Tutorials on 2012-07-13  

This is a simple trick but comes in handy when you need to extract just the filename from the full path.

#!/usr/bin/perl -w
use strict;
my @temp;
my $string;
my $filename;
$string = "/var/spool/email2fax/1233123/Agoda-Booking-Sep-2012.tiff";
for ( reverse @{[ split( '', $string ) ]} )
{
   last if /\//;
   unshift @temp, $_;
}

$filename = join '', @temp;
print $filename;
exit;





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Perl )

Latest Articles (in Perl)