arrays - Perl for loop error -
i new perl, trying execute simple program encoded below using strawberry perl 5, version 16:
#!usr/bin/perl use warnings; use strict; @array= {1,2,3,5,7,9}; $i; foreach $i (@array) { print qq(element $i\n); }
i getting below output:
element hash(0x3f8b4c)
however output should receive is:
element 1 element 2 element 3 element 5 element 7 element 9.
appreciate in this.
to initialize array, use list like
my @array = (1, 2, 3, 5, 7, 9);
note: parens sort out precedence, not special array syntax.
curlies delimit anonymous hashref, like
my $foobar = { foo => "bar", baz => "qux", };
so happened assigned array list of 1 anonymous hashref, like
my @array = ({ 1 => 2, 3 => 5, 7 => 9, })
would have worked.
Comments
Post a Comment