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

    What makes you think that every operating system uses the slash as directory separator?

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
      Obviously, not all do, but in this case he already specified his path format, and this sounds like a quick hack conversion, not a robust app. Enough people already suggested modules anyway.