Bladernr has asked for the wisdom of the Perl Monks concerning the following question:
Okie... I know this is pretty boneheaded, but I am not entirely fluent in perl, and am at the point where I know just enought to be dangerous. <grin>
Heres what I need help on:
given a file called foo.log with lines of text that look like this:
Sep 15 14:18:54 203.146.91.228:23 202.88.143.72:23
I wanted to be able to strip that seconds field from the timestamp, so that 14:18:54 would become 14:18
so far, I have gotten an array of the items in each line, and from that array, created various scalars based on what the object is... i.e. month, day, time, data1, and data2
here is the code sofar:
##!/usr/bin/perl # #my @lines; #@lines=`cat foobar`; # #foreach (@lines) { # # my($month, $day, $time, $data1, $data2) = split / /; # open(NEWTIME, $time); # while (<NEWTIME>) { # my($hour, $minute, $second) = split /:/; # $time2 = join(':', $hour, $minute); # } # select NEWLOG; # print "$time2\n"; #open NEWLOG, ">>foofinal.txt"; #}
of course ignore the hashmarks...
Now, after testing each variable, they are all assigned as they should be...except for @time2. I cant get $time2 to reflect the result of the join statement, and then print it out to the final txt file.
The goal is to have $time2 be the HH:MM time format, and reinsert that into the logfile so that in the final file the lines would look like this:
Sep 15 14:18 203.146.91.228:23 202.88.143.72:23
I know I have probably made many errors, so please show me the light!
Oh, and I did originaly have use strict in the beginning, however, that continuously gave me errors with $time2 and removing the 'use strict' line cleared those errors (of course) and allowed the script to complete. However at teh end of each run with the time variable, $time2 is always printed as a " " instead of a join between $hour and $minute.
Thanks
Jeff
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: get my variable out of the hole!
by davorg (Chancellor) on Sep 18, 2002 at 09:22 UTC | |
by Bladernr (Novice) on Sep 18, 2002 at 10:49 UTC | |
|
Re: get my variable out of the hole!
by dws (Chancellor) on Sep 18, 2002 at 08:29 UTC | |
|
Re: get my variable out of the hole!
by davorg (Chancellor) on Sep 18, 2002 at 08:31 UTC | |
|
Re: get my variable out of the hole!
by AcidHawk (Vicar) on Sep 18, 2002 at 08:35 UTC |