String in a array
am 11.07.2005 13:09:26 von Vitor Flausino
Hello all.
How do I check if there is a string in an array?
......................................................
@files = qx (cd /mnt/net/lisasn01/apps/App_Revman/server/data; find .
-name "NI1*.DAT" -type f -maxdepth 1);
Now I want to check if $my_file is in that array.
......................................................
In natural language, I want to check if there is a file named $my_file
on /mnt/net/lisasn01/apps/App_Revman/server/data directory.
Best regards,
-vcf
Re: String in a array
am 11.07.2005 22:03:22 von Paul Lalli
Vitor Flausino wrote:
> Hello all.
> How do I check if there is a string in an array?
> .....................................................
> @files = qx (cd /mnt/net/lisasn01/apps/App_Revman/server/data; find .
> -name "NI1*.DAT" -type f -maxdepth 1);
>
> Now I want to check if $my_file is in that array.
> .....................................................
>
> In natural language, I want to check if there is a file named $my_file
> on /mnt/net/lisasn01/apps/App_Revman/server/data directory.
You just want to know if $my_file occurs at least once?
my $there = 0;
for (@files){
if ($_ eq $my_file){
$there = 1;
last;
}
}
if ($there) {
#file found...
}
for more information and alternatives:
perldoc -q contains
Paul Lalli
Re: String in a array
am 11.07.2005 22:06:28 von Paul Lalli
Vitor Flausino wrote:
> Hello all.
> How do I check if there is a string in an array?
> .....................................................
> @files = qx (cd /mnt/net/lisasn01/apps/App_Revman/server/data; find .
> -name "NI1*.DAT" -type f -maxdepth 1);
>
> Now I want to check if $my_file is in that array.
> .....................................................
>
> In natural language, I want to check if there is a file named $my_file
> on /mnt/net/lisasn01/apps/App_Revman/server/data directory.
I just read this again, and didn't catch this last bit the first time.
All you want to do is find out if $my_file exists anywhere in that
specific directory? No recursion even? Then why are you farming out
this shell process?
if (-e "/mnt/net/lisasn01/apps/App_Revman/server/data/$my_file"){
#file exists...
}
Paul Lalli
Re: String in a array
am 13.07.2005 11:28:17 von Vitor Flausino
I agree, that your last solution is more clean.... The problem is that I
have to run several times (20 or more) per minute this procedure, and
"/mnt/net/lisasn01/apps/App_Revman/server/data" is mounted on a remote
filesystem very , very slow (when I make ls it takes, 10s). So I figured
that the best solution was make only one ls and then based in that, do
what I have to do.
Best regards,
-vcf
Paul Lalli wrote:
> Vitor Flausino wrote:
>
>>Hello all.
>>How do I check if there is a string in an array?
>>.....................................................
>>@files = qx (cd /mnt/net/lisasn01/apps/App_Revman/server/data; find .
>>-name "NI1*.DAT" -type f -maxdepth 1);
>>
>>Now I want to check if $my_file is in that array.
>>.....................................................
>>
>>In natural language, I want to check if there is a file named $my_file
>>on /mnt/net/lisasn01/apps/App_Revman/server/data directory.
>
>
> I just read this again, and didn't catch this last bit the first time.
> All you want to do is find out if $my_file exists anywhere in that
> specific directory? No recursion even? Then why are you farming out
> this shell process?
>
> if (-e "/mnt/net/lisasn01/apps/App_Revman/server/data/$my_file"){
> #file exists...
> }
>
> Paul Lalli
>