Extract filename from full path using perl
By: Sam Chen
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;
Most Viewed Articles (in Perl ) |
Latest Articles (in Perl) |
Comment on this tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview