in reply to Re^2: Array wierdness
in thread Array wierdness
What happens is that this does not modify the @PP array, instead it uses the value of $PP[1] as an array reference which points to the global(/package) variable @bar. To make this a bit clearer:my @PP = ("foo", "bar", "baz"); my @OO = ("AAA", "bar", "CCC"); $PP[1][0] = "foobar";
Output:#!/usr/bin/perl -l my @PP = ("foo", "bar", "baz"); my @OO = ("AAA", "bar", "CCC"); $PP[1][0] = "foobar"; print "\@PP: " . join(", ", @PP); print "\@OO: " . join(", ", @OO); print "\@bar: " . join(", ", @::bar);
@PP: foo, bar, baz @OO: AAA, bar, CCC @bar: foobarThe '@PP' and '@OO' array are unmodified; the '@bar' array however was created.
With use strict; you get the error: Can't use string ("bar") as an ARRAY ref while "strict refs" in use
|
|---|