-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Eko Budiharto wrote:
> Hi, I have data in an array and then compare each data with a
> certain condition. How can I retrieve each data in an array and
> then compare it?
>
Right idea as far as the code below goes, but it would be far simpler
to use grep to check if something exists.
> my $condition = data5;
>
> @array1 = data1, data2, data3, data4, etc.
The above two lines are ok.
>
> if ($condition eq @array1) {
Can't do this, like that. You're basically saying if $condition eq
@array1. You're comparing a variable to a array. Here is my take on
how that should read
if(grep(/$condition/,@array1) {
print "true";
}
A few notes about using grep.
If you say something like $count = grep(/$condition/,@array1); then
$count will a count of how many times the condition occurs. Now if you
say @count instead then grep will fill the array @count with all
occurrences of $condition. Effectively, filtering the array. The code
I wrote above should be what you're looking for as far as I can tell.
Hope this helps.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCoMofLzuLLJR0UfERAv0qAKCc3RdE3j2wi7swbrF1JKXxOc0+vACgw8O5
vm80Taev8y45Gr8di63t1gI=
=s2Ex
-----END PGP SIGNATURE-----
begin:vcard
fn:Paul Malcher
n:Malcher;Paul
org:Geek Garage Web Services,LLC
email;internet:[EMAIL PROTECTED]
tel;work:561-748-5857
note:This e-mail may contain material that is confidential, privileged and/or work product for the sole use of the intended recipient or their designee. If you are not the intended recipient or their designee, you are hereby notified that any review, reliance, or distribution of the contents of this e-mail is strictly prohibited, and you should contact the sender and delete all copies of this message.
x-mozilla-html:FALSE
url:http://www.ggws.net
version:2.1
end:vcard
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs