Arrays in Strings: Gotchas
- What's this?
@players = qw# Mario Luigi Toad Princess #; $x = '2 * 5'; print "Your name is $players[$x-7]\n";
- $x is interpolated before the index expression is, so it's '2*5'-7, which is 1-7, which is -6, which is index 2
| CPU: Perl, Fall 2005 | Perl, Week 3: More Arrays, Context, Subroutines, Lexical Variables | #16 |
@players = qw# Mario Luigi Toad Princess #; $x = '2 * 5'; print "Your name is $players[$x-7]\n";
| Copyright © 2005 Ian Langworth |