Forum Moderators: coopster & phranque

Message Too Old, No Replies

my first perl script wont work

anyone care to take a stab at this? Pretty please?

         

jeremy goodrich

9:14 pm on Apr 5, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



open (INF, "<log_file>");
while ($line = <INF>)

{

@l = split("\n",$line);
if($l =~ /Mozilla/)
{
print $line;
}
}

close INF;

1;

I'm trying to seperate a log file line by line, then see if the line has mozilla in it. If so, print that line.

Once through the log, exit. And I'm trying to get it to print to the screen.

Any pointers greatly appreciated. My logic is messed up, or something.

Jeremy

sugarkane

9:44 pm on Apr 5, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Jeremy, the $line=<INF> part of your script automatically pulls in one line at a time, so you don't need to use split("\n",$line)

This will remove one level of complexity from the script - you can then match against $line directly:

if ($line=~/Mozilla/)

This should be enough to get things working - if not, just shout.

jeremy goodrich

4:51 pm on Apr 6, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Okay, I'm still having problems. Here is the current status of the script:

#!/usr/bin/perl -w

$filename = "my_log";
open (my_log, $filename) or die "Couldn't open $filename: $!";
while ($line = <my_log>)

{
if(/!=mozilla/ && /Apr..5/) { print; }

}

close INF;

1;

I'm getting

Use of uninitialized value in pattern match (m//) at mozGrap.cgi line 9, <my_log> line 134.

All down the screen...kind of cool, but not what I want. And if I don't use the -w switch, I don't get any output.

Thanks for the help before Sugarkane...anybody else want to take a stab at this now?

Jeremy

jeremy goodrich

5:00 pm on Apr 6, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



actually, I just got some help from a coworker...

if($_!~/mozilla/ && /Apr..5/) { print; }

apparently, that works. I guess there is a difference between matching a string within a pattern, and just comparing strings, according to what he said.

Jeremy