Graeme McLaren wrote:
Hi all, I'm in need of a loop, can't seem to find what I'm looking for online. I want to loop over this array ref inserting each hash value into the DB at each iteration.I've got the following data structure which is assigned to $aref:

$VAR1 = [
          {
            'rate' => '1.98',
            'name' => 'Dollars -> Sterling'
          },
          {
            'rate' => '1.5',
            'name' => 'Sterling -> Euros'
          },
          {
            'rate' => '0.75',
            'name' => 'Dollars -> Euros'
          },
          {
            'rate' => '2.05',
            'name' => 'Sterling -> Dollars'
          },
          {
            'rate' => '0.72',
            'name' => 'Euro -> Sterling'
          },
          {
            'rate' => '1.52',
            'name' => 'Euro -> Dollars'
          },
          {
            'rate' => '1.98',
            'name' => 'Amex Exchange Rate'
          }
        ];

This is one way:

    foreach my $hashref ( @$aref ) {
        print "$hashref->{name}: $hashref->{rate}\n";
    }

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to