Extract filename from full path using perl
 


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;
 
 
 
 
 
COPYRIGHT © 2017 java-samples.com. ALL RIGHTS RESERVED.