zapdos has asked for the wisdom of the Perl Monks concerning the following question:
If I do print $rocks[$#rocks]; it prints nothing. Why? When I comment out $#rocks = 99; it prints 'lava' and when I comment out $#rocks = 2; it prints 'schist'. But when I maintain the two it prints nothing as I already said. And what the comments "add 97 undef elements (the forgotten rocks are gone forever)" and "forget all rocks after 'lava'" mean?$rocks[0] = 'bedrock'; $rocks[1] = 'slate'; $rocks[2]= 'lava'; $rocks[3] = 'crushed rock'; $rocks[99] = 'schist'; $#rocks = 2; # forget all rocks after 'lava' $#rocks = 99; # add 97 undef elements (the forgotten rocks are gone fo +rever)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: What's going on in array element assignment?
by AnomalousMonk (Archbishop) on Aug 11, 2020 at 02:17 UTC | |
| |
|
Re: What's going on in array element assignment?
by perlfan (Parson) on Aug 11, 2020 at 02:36 UTC | |
by zapdos (Sexton) on Aug 11, 2020 at 02:53 UTC | |
by perlfan (Parson) on Aug 11, 2020 at 03:20 UTC | |
by Athanasius (Archbishop) on Aug 11, 2020 at 07:15 UTC | |
by zapdos (Sexton) on Aug 12, 2020 at 04:37 UTC | |
| |
by zapdos (Sexton) on Aug 11, 2020 at 03:25 UTC |