perl fileparse and push into multiple arrays -


i have array contains file paths. split array give me file_name, dir_name , extension. trying use file::basename perl module.

can me achieve this:

foreach (@files) {     push((@file_basename,@dir_name,@ext), fileparse($_)); } 

i know doing not right.. can me fix above piece of code?

i know can this:

$filename = basename($file); 

and push value array. same dir , extensions. looking better way.

thanks in advance help.

looks you're missing 2nd parameter fileparse. @suffixes

stated in perldoc, you're looking should this:

my($filename, $directories, $suffix) = fileparse($path, @suffixes); 

if don't have list of suffixes, can this:

fileparse("/foo/bar/baz.txt", qr/\.[^.]*/); 

which should match extension.

then can fix push so:

for $file (@l){     ($name, $path, $suffix) = fileparse($file, qr/\.[^.]*/);      push @name_list, $name;     push @path_list, $path;     push @suffix_list, $suffix; } 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -