
FigureSkater
Deleted
Mar 28, 2001, 4:09 AM
Post #1 of 1
(156 views)
|
|
searching files depending on arguments
|
Can't Post
|
|
Suppose I need a perl program to search a file using arguments supplied on the command line. The arguments can be entered using different tags so that the program may have to search for only one pattern or maybe 2 different patterns. Is there any better way to do this than to have something like: ---------------------------------------------------- open file if(some tag is set) { while($line=FILE) { if ($line =~ $pattern1) { print $line; } } } elsif(someother tag is set) { while($line=FILE) { if ($line =~ $pattern2) { print $line; } } } elsif (both tags are set) { while($line=FILE) { if ($line =~ $pattern1|| $line =~ $pattern2) { print $line; } } } close file ------------------------------------------------------------- (The code is sort of half perl, half pseudocode)
|