At the end of the post you will find the exemplification script; below there are more detailed comments over the exemplified cases:
#!/usr/bin/perl -w use Data::Dumper; print "Case 1: non existent\n"; exists $x->{'y'}->{'z'}; print Dumper $x; print "Case 2: undef\n"; $x = undef; exists $x->{'y'}->{'z'}; print Dumper $x; print "Case 3: hashref\n"; $x = {}; exists $x->{'y'}->{'z'}; print Dumper $x; print "Case 4: stopper scalar\n"; $x = 'stopper'; exists $x->{'y'}->{'z'}; print Dumper $x; print "Case 5: Even assignment won't do, and won't trigger warning or +runtime error!\n"; $x = 'stop2'; $x->{'y'}->{'z'} = 'something'; print Dumper $x; print "Case 6: use strict is your friend :)\n"; eval { use strict 'refs'; $x = 'stop3'; $x->{'y'}->{'z'} = 'something else'; print Dumper $x; }; $@ and print $@;
And here's the output.
Case 1: non existent $VAR1 = { 'y' => {} }; Case 2: undef $VAR1 = { 'y' => {} }; Case 3: hashref $VAR1 = { 'y' => {} }; Case 4: stopper scalar $VAR1 = 'stopper'; Case 5: Even assignment won't do, and won't trigger warning or runtime + error! $VAR1 = 'stop2'; Case 6: use strict is your friend :) Can't use string ("stop3") as a HASH ref while "strict refs" in use at + ./autoviv-stop.pl line 35.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Autovivification and soft refs
by hardburn (Abbot) on Jan 21, 2004 at 20:41 UTC | |
|
Re: Autovivification and soft refs
by dragonchild (Archbishop) on Jan 21, 2004 at 20:45 UTC | |
|
Re: Autovivification and soft refs
by Abigail-II (Bishop) on Jan 21, 2004 at 21:33 UTC | |
by pg (Canon) on Jan 22, 2004 at 04:05 UTC | |
by Abigail-II (Bishop) on Jan 22, 2004 at 09:35 UTC | |
by thelenm (Vicar) on Jan 22, 2004 at 05:03 UTC | |
|
Re: Autovivification and soft refs
by pg (Canon) on Jan 21, 2004 at 20:38 UTC | |
|
Re: Autovivification and soft refs
by ysth (Canon) on Jan 21, 2004 at 22:56 UTC |