in reply to split a path/filename
use strict; use warnings; my ($path, $file); while (<DATA>) { chomp; ($path, $file) = splitPath($_); print "My path is $path\n"; print "My file is $file\n\n"; } sub splitPath { if ($_[0] =~ m|(.*/)(.*)|) { return ($1, $2); } return ('', $_[0]); } __DATA__ a/b/c/filename1.someext b/c/filename2.sh d/e/f/g/filename3.exe filename.txt
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: split a path/filename
by afoken (Chancellor) on Dec 02, 2011 at 09:51 UTC | |
by TJPride (Pilgrim) on Dec 02, 2011 at 16:14 UTC |