Using Perl and CGI Scripts by Bill Weinman – Chap 01 / Lesson 01
Using Perl and CGI Scripts by Bill Weinman
How do you pass (and dereference) an array of hashes to a Perl subroutine?
I though the code below would work but I think it is not dereferencing the array:
#!/usr/bin/perl
# ARRAY OF HASHES
$val[0]{‘CELL1′} = "0cell1";
$val[0]{‘CELL2′} = "0cell2";
$val[1]{‘CELL1′} = "1cell1";
$val[1]{‘CELL2′} = "1cell2";
for my $i (0..$#val) {
print "$val[$i]{‘CELL1′} $val[$i]{‘CELL2′}\n";
}
$res = &mysub(\@val);
print "RESULT: $res\n";
sub mysub {
my $ref = shift ; # $ref is a reference to an array of HASHES
my @valIN=@{$ref}; # try to dereference it
for my $i (0..$#valIN) {
print "$valIN[$i]{‘CELL1′} $valIN[$i]{‘CELL2′}\n";
}
return "DONE";
}
奇科電腦Perl Programming 程式語言視頻教學(1) Perl 簡介
奇科電腦提供台灣地區最優質、最專業的程式設計教學。意者請洽+886-2-27116373。 www.geego.com.tw; e-mail GeeGo Systems offer high quality and leading of training solution on Programming in Taiwan. More information about GeeGo, please call +886-2-27116373, www.geego.com or mail to service@geego.com.tw
奇科電腦Perl Programming 程式語言視頻教學(4) 正規表示法使用方式
奇科電腦提供台灣地區最優質、最專業的程式設計教學。意者請洽+886-2-27116373。 www.geego.com.tw; e-mail GeeGo Systems offer high quality and leading of training solution on Programming in Taiwan. More information about GeeGo, please call +886-2-27116373, www.geego.com or mail to service@geego.com.tw