Toby Stuart wrote:
> 
> use strict;
> use warnings;
> 
> my %records;
> 
> my $surname;
> my $given_name;
> my $price;

You create these three variables because?

> my @fields;

You should declare this _inside_ the loop.

> my $i=0;
> while (<DATA>)
> {
>         @fields = unpack("A10A10A7", $_);

          my @fields = unpack 'A10A10A7', $_;


>         $records{$i} = {
                  ^^^^
Why not just use an array?


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








John
-- 
use Perl;
program
fulfillment

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

Reply via email to