> -----Original Message-----
> From: John W. Krahn [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, January 30, 2003 2:16 PM
> To: [EMAIL PROTECTED]
> Subject: Re: Parsing Fixed Length data
> 
> 
> Toby Stuart wrote:
> > 
> > use strict;
> > use warnings;
> > 
> > my %records;
> > 
> > my $surname;
> > my $given_name;
> > my $price;
> 
> You create these three variables because?
> 

whoops.  was playing around with alternative solutions and forgot to remove
them :(

> > my @fields;
> 
> You should declare this _inside_ the loop.
> 

point taken.

> > my $i=0;
> > while (<DATA>)
> > {
> >         @fields = unpack("A10A10A7", $_);
> 
>           my @fields = unpack 'A10A10A7', $_;
> 
> 
> >         $records{$i} = {
>                   ^^^^
> Why not just use an array?

different strokes for different strokes :)

> 
> 
> >                 given_name => $fields[0],
> >                 surname    => $fields[1],
> >                 price      => $fields[2]
> >         };
> 
>     push @records, { given_name => $fields[0],
>                      surname    => $fields[1],
>                      price      => $fields[2] };
> 
> Or:
> 
>     @{$records[$i++]}{ qw/given_name surname price/ } = unpack
> 'A10A10A7', $_;
> 

i like that!

> 
> >         $i++;
> > }
> > 
> > print "$records{0}{surname}\n";
> > print "$records{0}{given_name}\n";
> > print "$records{0}{price}\n";
> > 
> > print "\n";
> > 
> > print "$records{1}{surname}\n";
> > print "$records{1}{given_name}\n";
> > print "$records{1}{price}\n";
> > 
> > __DATA__
> > Kevin     Old       001.000
> > Someone   Else        1.000
> 
> 

> 

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

Reply via email to