PJT has asked for the wisdom of the Perl Monks concerning the following question:
Hi monks,
I'm trying to churn out my first perl prog and it's not going well. I have a log file from which I would like to extract 15 lines - I know there is exactly only 15 that will match the "if" case statement. When I extract them, I also want to insert a variable that contains the line number. For example:
should look like:
where $i is the variable that increase (only up to 15). When I run my program it spits out fifteen 1's and that's all. Any help is appreciated - PJT
call started 00:00:00, call ended 00:00:00, total modem active time 00 +:00:00
should look like:
Modem Line 0/$i : total modem active time 00:00:00
where $i is the variable that increase (only up to 15). When I run my program it spits out fifteen 1's and that's all. Any help is appreciated - PJT
#!/usr/sbin/perl -w # Program for modem pool log manipulation open(IN, $ARGV[0]) || die "cannot open $ARGV[0] for reading: $!"; open(OUT, ">$ARGV[1]") || die "cannot create $ARGV[1]: $!"; $i=0; while(<IN>){ if(/^call started/){ print OUT s/^call.*total/Modem Line 0\/$i : / ."\n"; $i++; } } close(IN); close(OUT);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: while loop, search & replace
by ikegami (Patriarch) on Oct 01, 2004 at 17:54 UTC | |
by Anonymous Monk on Oct 01, 2004 at 18:42 UTC | |
by ikegami (Patriarch) on Oct 01, 2004 at 19:12 UTC | |
Re: while loop, search, and replace while loop, search & replace
by tmoertel (Chaplain) on Oct 01, 2004 at 18:01 UTC |
Back to
Seekers of Perl Wisdom