CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
searching files depending on arguments

 



FigureSkater
Deleted

Mar 28, 2001, 4:09 AM

Post #1 of 1 (305 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)



 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives