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";
}

Google Python Class Day 1 Part 2

Google Python Class Day 1 Part 2: Lists, Sorting, and Tuples. By Nick Parlante. Support materials and exercises: code.google.com