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:
>  
> my $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'
>   }
> ];
>  
> Can anyone help out with this?  
>  
> Much appreciated.


foreach my $hash (@$VAR1) {

  my ($rate, $name) = @{$hash}{qw/ rate name /};

  # Do stuff with $rate, $name
}

HTH,

Rob

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


Reply via email to