Hi,
Background:
I have a @filelist that can have (guess what) several filenames.
I want to split the filenames in 3 arrays:
- if the file is in a directory *\templatedata\*\data\ it should go to array1;
- if the file is in a directory \binaries\* it should go to array2;
- any other file should go to array3;
My program is as follows, but I think someone around can make the same thing in 4 ir 5
lines :)
Several questions:
1) is there a way to specify on what var s/// works ?
2) any better way to see if the pattern matched ?
3) any smaller and faster way to do the same ?
sub is_data {
my $file = shift;
$file=~s/(.*?)templatedata(*.?)data\\//sig;
return $file;
}
sub is_binary {
my $file = shift;
$file=~s/^binaries//sig;
return $file;
}
my @array1=();
my @array2=();
my @array3=();
my @filelist=( "templatedata\\MyDir\\data\\0001.txt", "otherdir\\test.yxy",
"binaries\\movie.jpeg");
my $dummy;
foreach my $file (@filelist){
$dummy=is_data($file);
if($dummy eq $file){
$dummy=is_binary($file);
if($dummy eq $file){
push @array3, $dummy;
}
else
{
push @array2, $dummy;
}
}
else
{
push @array1, $dummy;
}
}
--
Duarte Manuel Cordeiro
Manager - IT - Security & Communications
mailto:[EMAIL PROTECTED] | msn: [EMAIL PROTECTED] |
http://www.neoris.com/
--
Neoris Portugal
Edificio Inova��o IV - Sala 819 - Taguspark * 2780-920 Oeiras * Portugal
Tel: +351 21 423-8350 | Fax: +351 21 421-7626 | Mob: +35191 613-5706
--
Privileged/Confidential Information may be contained in this message. If you are not
the addressee indicated in this message (or responsible for delivery of the message to
such person), you may not copy or deliver this message to anyone. In such case, you
should destroy this message and kindly notify the sender by reply email. Please advise
immediately if you or your employer does not consent to Internet email for messages of
this kind. Opinions, conclusions and other information in this message that do not
relate to the official business of my firm shall be understood as neither given nor
endorsed by it.