data comprised of regexs (while loop weirdness)
jason_at_cyberpine.com
Date: 08/12/04
- Next message: Anno Siegel: "Re: Reading next line, finding missing number in sequence"
- Previous message: AlV: "Re: What packages are installed?"
- Next in thread: Gunnar Hjalmarsson: "Re: data comprised of regexs (while loop weirdness)"
- Reply: Gunnar Hjalmarsson: "Re: data comprised of regexs (while loop weirdness)"
- Reply: Scott W Gifford: "Re: data comprised of regexs (while loop weirdness)"
- Reply: Tad McClellan: "Re: data comprised of regexs (while loop weirdness)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 12 Aug 2004 13:22:54 -0700
Sure this is a newbie issue. And please pardon any reposting I might
have done.
My simple example doesn't work and there are few quirks I'm trying to
understand about perl.
for the below code,
1. why do I only see a yes when passing the last data entry (test3) as
an argument?
2. Why do results vary depending on whether $_ is on the left or
right of the if compare with $request?
3. why does only my last entry display if I uncomment the chomp
My real objective is to read a text file with a list of regular
expression in it that I can test against user input (that file may
have 200 expressons). If none of the expression find a match my user
input, then I would reject the input with a message. Any help or
information is appreciated.
<code snipet>
#!/usr/bin/perl -w
use strict;
my $request = shift @ARGV;
my @data = <DATA>;
for(@data)
#chomp;
{
print $_;
if ($request =~ $_) {print 'yes';}
#if ($_ =~ $request) {print 'yes';}
#if ($request =~ /$_/) {print 'yes';} #what i really want to do is
test for regex match coming in from an a flat file.
}
__DATA__
test1
test2
test3
<end code snipet>
testing:
perl m3.pl test3
test1
test2
test3yes$
perl m3.pl test2
test1
test2
test3$
- Next message: Anno Siegel: "Re: Reading next line, finding missing number in sequence"
- Previous message: AlV: "Re: What packages are installed?"
- Next in thread: Gunnar Hjalmarsson: "Re: data comprised of regexs (while loop weirdness)"
- Reply: Gunnar Hjalmarsson: "Re: data comprised of regexs (while loop weirdness)"
- Reply: Scott W Gifford: "Re: data comprised of regexs (while loop weirdness)"
- Reply: Tad McClellan: "Re: data comprised of regexs (while loop weirdness)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|