#!/usr/bin/perl -w # -*-Perl-*- use strict; use CGI; my $cgi = new CGI(); # Just for the reference my $hrf = { 'a'=>['alpha','start','soup'], 'b'=>['beta','middle','fish'], 'z'=>['omega','finish','nuts'], }; my $n = "\n"; print "Value of my \$cgi:\t",$cgi,$n,$n; print "Successive dereferences of a reference to a\n"; print "hash of references to arrays:\n"; print "\$hrf:\t",$hrf,$n; print "\$hrf->{'a'}:\t",$hrf->{'a'},$n; print "\$hrf->{'a'}->[1]:\t",$hrf->{'a'}->[1],$n; print "\nTry forcing our \$hrf to be to an array:\n"; print "\@{\$hrf}[2]:\t"; print eval{@{$hrf}[2]} || $@, $n; print "Pole to polar phrases:$n"; for my $idx (0..2) { print join(' to ', map {$hrf->{$_}->[$idx]} sort keys %{$hrf} ),$n; } print $n; print "Our slice of the menu is:$n"; for ((sort keys %{$hrf})[0,-1]) { print @{$hrf->{$_}}[0, -1],"\n"; } #### Value of my $cgi: CGI=HASH(0x80cb854) Successive dereferences of a reference to a hash of references to arrays: $hrf: HASH(0x8173438) $hrf->{'a'}: ARRAY(0x80cb824) $hrf->{'a'}->[1]: start Try forcing our $hrf to be to an array: @{$hrf}[2]: Not an ARRAY reference at ./refs line 22. Pole to polar phrases: alpha to beta to omega start to middle to finish soup to fish to nuts Our slice of the menu is: alphasoup omeganuts