如何将“哈希数组”的元素作为数组传递给函数?
例如,我想将 all$link->{text}
作为数组传递给sort()
函数。
#!/usr/bin/perl
use strict; use warnings;
my $field = <<EOS;
<a href="baboon.html">Baboon</a>
<a href="antelope.html">Antelope</a>
<a href="dog.html">dog</a>
<a href="cat.html">cat</a>
EOS
#/ this comment is to unconfuse the SO syntax highlighter.
my @array_of_links;
while ($field =~ m{<a.*?href="(.*?)".*?>(.*?)</a>}g) {
push @array_of_links, { url => $1, text => $2 };
}
for my $link (@array_of_links) {
print qq("$link->{text}" goes to -> "$link->{url}"\n);
}