is there teamsite/perl command that I can grab dcrname using ipl?eg. /templatedata/SonyLC/article/data/mainfolder/folder/subfolder/subsubfolder/dcrnameNeed to grab dcrname. I can use regex but looking for other options.thanks!
His request is quite clear. He wants to get dcrname from the long string that he has supplied.I myself use regex. It has worked well in the past 4 years.#Examplemy $dcrname = "/templatedata/SonyLC/article/data/mainfolder/folder/subfolder/subsubfolder/s";$dcrname =~ s|.*/||g; # find the dcr name (without the path)
use File::Basename;my $dcrPath = '/templatedata/SonyLC/article/data/mainfolder/folder/subfolder/subsubfolder/dcrname';printf ("Dir - %s\nFile - %s\n", dirname($dcrPath), basename($dcrPath));
Alternatively:use File::Basename;my $dcrPath = '/templatedata/SonyLC/article/data/mainfolder/folder/subfolder/subsubfolder/dcrname';printf ("Dir - %s\nFile - %s\n", dirname($dcrPath), basename($dcrPath));
FYI - unless it's changed since last I profiled it - File::Basename does a lot of stuff to work across all different sorts of operating systems and tends to be inefficient performance-wise in comparison to using regex's
Nothing changed in 5.8, relatively poor performance is the price for portability. That said, in Perl almost any string manipulation is "inefficient performance-wise in comparison to using regex's"
While the portability is nice, and since I am often lazy, ok always, basename is an easy function to use. However when it comes to DCRs, IMHO, it is inappropriate.If I have a file:templatedata/category/type/data/some/sub/dir/DCR.xmlOften the information I will want is category, type, some/sub/dir, and DCR. Obviously if I use basename I can get the dir and DCR, then I need to regex the dir get the other fields I need.
Need to grab dcrname. I can use regex but looking for other options.
Perhaps, but that's what Rodigz indicated when he started the thread, Another option is all I've provided
cool. this one with work if the user selects a file but if the selected a folder it will not work. I will just use File::Find;thanks!
(my $dcr = $fullpath) =~ s|^.*/templatedata/.*?/.*?/data/||;
...my $dcr = q();$fullpath =~ tr|\\|/|;if ($fullpath =~ m|/templatedata/.*?/.?/data/(.*)$|){ $dcr = $1;}else { # whatever is in full path - is not a DCR # skip - or error?}...