Results 1 to 3 of 3
I need to compare two values in same arrar and I don't want to hardcode it, need the logic (still trying to create some logic)..
Following is hardcoded example need ...
- 02-04-2008 #1Linux Newbie
- Join Date
- Jan 2008
- Posts
- 114
How to compare values in same array in of doing hardcoded in Perl
I need to compare two values in same arrar and I don't want to hardcode it, need the logic (still trying to create some logic)..
Following is hardcoded example need to change it:-
@test;
if ($test[0] != 1 && $test[1] != 1){
print "Test Passed\n";
}else {
Print "Test Failed\n";
}
Want to in this way
foreach $t1 (@test){
if (
Some thing like this, not hardcoded
Please suggest me
Thanks
- 02-04-2008 #2
How about something like this:
$all_match acts as a flag, and you can check its value after the loop.Code:my $all_match = 1; for my $val (@test) { $all_match = 0 if $val == 1; }DISTRO=Arch
Registered Linux User #388732
- 02-04-2008 #3Linux Newbie
- Join Date
- Jan 2008
- Posts
- 114
No this can not work, see below if condition, its passing following combinations:-
1 0, 0 1, 0 0
if ($test[0] != 1 && $test[1] != 1){
print "Test Passed\n";
}else {
Print "Test Failed\n";
}
but
my $all_match = 1;
for my $val (@test)
{
$all_match = 0 if $val == 1;
}
not passing all, suggest me
Thanks


Reply With Quote