in reply to A quit key when no chomp
Since you're going to have to rewrite the code to step through each entry individually, telling you this isn't cheating.
A common mistake for people learning Perl (even if they're experienced programmers) is to learn what those funny characters mean. You can't say:
- because the @ funny character indicates an array(see #1) .if (@input eq 'q') {
So @input indicates the whole array - making it nonsensical to ask if the array is equal to anything (see #2). If you want to ask if a particular element of an array is equal to anything, you have to refer to that element explicitly, using the $ funny character. So, to test the first element of an array, we do somthing like this:
@foo = ('Bob', 'Tim', 'Bongo - The Jungle Avenger'); if ($foo[0] eq 'Bob') { #The $ indicates a single element #and [0] indicates which one print "Everything has gone as planned"; }
#1 - Well, not exactly true. It indicates a list out of a data structure, so it could be an array or and array slice or a hash slice.
#2 - Also not entirely true. The @input is in scalar context, so it does make sense to ask if it's equal to something . . .just not the sense we think it does.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: A quit key when no chomp
by ellem (Hermit) on Mar 03, 2002 at 07:41 UTC | |
by erikharrison (Deacon) on Mar 03, 2002 at 07:46 UTC | |
by ellem (Hermit) on Mar 03, 2002 at 08:03 UTC |