i have a file which contains something like this
name: A id: B cl: C
name: D id: E cl: F
name: I id: G cl: K
i am grep the contents after cl: and storing it in an array
#!/usr/bin/perl
@success=qw(C J K L);
@arr=qw(P M C);
my $pattern="is present here";
local $/;
open (<FILE>, sl.txt);
my $ln=<FILE>;
while($ln=<FILE>)
{
if($ln=~$pattern)
{
{local $/="\n"; @using=`grep "cl" sl.txt | cut -d " " -f 6 `;}
print "\n the using array is @using \n";
print "$using[0] ,$using[1] \n";
chomp(@using);
print" after chomp @using\n";
foreach my $lb (@using)
{
if($lb eq $success[2])
{
print " comparison true\n";
}
else
{
print " false comparison\n";
}
}
}
}
close(<FILE>);
please check why this comaprison is failing after grepping and chomp . the before chomp @using and after chomp @using is the same
Given this script:
And this data file
sl.txt
:Perl 5.18.1 on Mac OS X 10.9.1 yields:
This looks like the code behaves correctly. What do you get from each of your scripts when you put the debugging print loops in place? (Using
qx{ … }
is another way of writing back quotes.)