|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Help!
Hi All,
newbie-ish question here. I have this script: foreach $test (@num) { foreach $record (@neet) { if ($record =~ /$test/){ print "$record \n"; print $test; } } } For some reason, the $test variable doesn't seem to be carrying into the second "foreach" loop. Does anyone know why this is so? I suspect it might be an issue with the "$" character having a special meaning within REs. Please assist. |
|
#2
|
|||
|
|||
|
|
|
#3
|
||||
|
||||
|
Anomander: Your code is fine, though there are more efficient methods, and you may not get the results you expect:
Code:
#!/usr/bin/perl
use strict;
use warnings;
my @num = qw/1 2 3 4/;
my @neet = qw/100 2 30 4/;
foreach my $test (@num) {
foreach my $record (@neet) {
if ($record =~ /$test/){
print "$record\n";
}
}
}
since an open match isn't the same as equality: Quote:
If the code doesn't match for you at all and it seems it should, perhaps you forgot to remove the line endings from data read from a file. cowboyroy: the $record and $test variables are undefined in your code. |
|
#4
|
||||
|
||||
|
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Help! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|