0

数据存储在@emailaddresses 中,如下所示:

$VAR1 = { 'email' => 'abc@google.com' };
$VAR2 = { 'email' => 'cde@google.com' };
$VAR3 = { 'email' => 'efg@google.com' };
$VAR4 = { 'email' => 'hij@google.com' };

当我打印@emailaddresses(打印@emailaddresses)时,它会打印HASH(0x...)而不是数组中的值。如何打印值?

4

1 回答 1

1

只需遍历您的数组并打印出每个地址的“电子邮件”值:

my @emailaddresses = ...;

for my $addr ( @emailaddresses ) {
   print $addr->{email}, "\n";
}

更好的是,将此逻辑包装在一个函数中:

sub print_email_addresses {
   my @addresses = @_;

   for my $addr ( @addresses ) {
      print $addr->{email}, "\n";
   }
}
于 2013-07-01T18:14:41.543 回答