Arrays in Strings: Gotchas, 2
- What if I want to print "gerbil[2]" ?
@foo = qw( red green blue ); $foo = 'gerbil'; print "$foo[2]\n";
- Nope! Instead,
print "$foo\[2]\n";
- or
print "${foo}[2]\n";
| CPU: Perl, Fall 2005 | Perl, Week 3: More Arrays, Context, Subroutines, Lexical Variables | #17 |
@foo = qw( red green blue ); $foo = 'gerbil'; print "$foo[2]\n";
print "$foo\[2]\n";
print "${foo}[2]\n";
| Copyright © 2005 Ian Langworth |