Re: This is weird: Pop works but shift doesn't



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";
}


.



Relevant Pages

  • Re: Adding a new file extension for Pipe Delimited files
    ... Dim Temp As String ... Dim FileNumber As Long ... open and handle like CSV files? ... allow me to keep the pipe delimited format. ...
    (microsoft.public.excel.programming)
  • Temp Database problems with Access 2007
    ... I've been using Tony Toew's Temp table module and I've now upgraded to ... The database is still in 2003 format. ... ' This subroutine illustrates how to use a temporary MDB in your app. ...
    (comp.databases.ms-access)
  • RE: Export Table to fixed length txt file
    ... Make a temp table with all text fields set the the fixed length you require. ... Run a query to update the now populated temp table setting the format to fix ... You would ideally now have a table that has all of the data in string ... elements) say position 1500 for the main body- 250 for the header / trailer ...
    (microsoft.public.access.modulesdaovba)
  • Re: Best way to import text file into existing table on a daily ba
    ... file, temp table, and permanent table). ... table's field when you run an append query that appends that data item into ... If you need the input mask's format applied to the data for the ...
    (microsoft.public.access.externaldata)
  • Re: converting to FLOATING_POINT..
    ... Then, the max widths for each column are used in the sprintf function, (which uses a '*' as a placeholder, if thats an accurate term for the ... push @temp, $temp; # incorrect ... The format should be applied at this point so that that when the max_length is calculated below, the width of each $time and $temp variable will be as it will be when printed out. ...
    (perl.beginners)