> -----Original Message-----
> From: Pete Emerson [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, January 23, 2002 2:13 PM
> To: [EMAIL PROTECTED]
> Subject: Re: Help reqd. for collecting data
> 
> 
> Here's my stab at it:
> 
> #!/usr/bin/perl -w
> 
> use strict;
> 
> my %info;
> 
> open INFILE, "$ARGV[0]" or die "Can't open file: $!\n"; # 
> Open file specified on command line
> while (<INFILE>) {
>     chomp;
>     my ($date, @data)=split;          # Capture the date, 
> then the rest
>     $date=~s/_\d{4}$//;               # Remove the timestamp, 
> since we're summarizing the day
>     for (my $i=0; $i<=$#data; $i++) { # Add data to the 
> appropriate column
>         $info{$date}[$i]+=$data[$i];  # per date!
>     }
> }
> close INFILE;
> 
> foreach my $date (sort keys %info) {           # Print the 
> results by sorted date
>     print "$date";
>     for (my $i=0; $i<$#{$info{$date}}; $i++) { # Column by column
>         print " $info{$date}[$i]";
>     }

This loop can really be shortened to:

   print " $_" for @{$info{$date}};

or just:

   print "@{$info{$date}}";

which takes advantage of the $" variable's default value of ' ',
which is inserted between list items when they are interpolated inside
double quotes.

>     print "\n";
> }

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to