Re: $_ in condition

jason_at_cyberpine.com
Date: 08/12/04


Date: 12 Aug 2004 10:43:02 -0700


> chomp; # this should fix the problem

This did not appear to fix the issue, and actually the code only
appears to "pass" when I send it the last entry in the data.

$ perl m2.pl 'test2'
test2
 Failed!
$ perl m2.pl 'test3'
test3
 Passed!

The code I'm testing with:

#!/usr/bin/perl -w
use strict;
my $request = shift @ARGV;
print $request;
my $p='n';
while(<DATA>) {
  chomp;
  if ($request =~ $_)
{
$p='y';
}
   }
if ($p =~ 'y')
{
  print "\n Passed! \n";
}
else
{
  print "\n Failed! \n";

}
__DATA__
test1
test2
test3

Thanks for any help or information.



Relevant Pages

  • Re: $_ in condition
    ... > chomp; # this should fix the problem ... Did not appear to fix the problem. ... $ perl m2.pl test2 ... my $request = shift @ARGV; ...
    (comp.lang.perl)
  • Re: data comprised of regexs (while loop weirdness)
    ... > right of the if compare with $request? ... I'm not sure why it works at all without the chomp. ...
    (comp.lang.perl.misc)
  • Re: debian rename
    ... > for the benefit of the pedants.. ... > the problem was a newline char ... > to fix all I had to do was ... > chomp $mail ...
    (comp.lang.perl.misc)