Re: This is weird: Pop works but shift doesn't
- From: Chris Cole <ithinkiam@xxxxxxxxx>
- Date: Tue, 05 Apr 2005 14:38:28 +0100
On Tue, 05 Apr 2005 04:19:07 -0700, John W. Krahn wrote:
> Harold Castro wrote:
>> Hi,
>
> Hello,
>
>> I'm parsing a log file that contains this format:
>>
>> 1112677214 31388202 181264589
>> 1112677214 8843 59460 8843 59460
>> 1112676919 10728 59045 10728 59045
>> 1112676900 10617 59006 10728 59045
>> 1112676600 8693 58389 9531 59661
>>
>>
>> These logs are in unix timestamp format:
>> I'm trying to convert the first column into scalar
>> localtime.
>>
>> Here's my code:
>>
>> our @temp;
>
> Why use our(), do you really need a package variable?
Agreed. You should always use strict and warnings:
use strict;
use warnings;
Then you'll need declare each variable the first time you use it.
>> open FILE, "./logfile.txt" or die $!;
>> while (<FILE>){
>> foreach my $time(split/\s+/, $_){
>> push @temp, $time;
>> }
>
> No need for a loop there:
>
> push @temp, split;
>
No need for a push either:
my @temp = split;
If you re-declare the @temp array you're effectively emptying it and your
shift version will work.
open FILE, "./logfile.txt" or die $!;
while (<FILE>){
my @temp = split;
print shift @temp, "\n";
}
.
- References:
- Re: This is weird: Pop works but shift doesn't
- From: John W. Krahn
- Re: This is weird: Pop works but shift doesn't
- Prev by Date: initialize arrays
- Next by Date: RE: datetime comparisons
- Previous by thread: Re: Newbie Regular expression question
- Next by thread: XML::XPath query
- Index(es):
Relevant Pages
|