Let's Add Some Spice
Randal L. Schwartz
merlyn at stonehenge.com
Tue Jun 6 12:09:10 CDT 2000
>>>>> "Aaron" == Aaron Jensen <atjensen at home.com> writes:
Aaron> 19 foreach(values %FIELDS){
Aaron> 20 grep(%ALL_FIELDS{$_}++, @$_);
Aaron> 21 }
If that's really line 20, Lincoln should be shot. The proper syntax
is $ALL_FIELDS{$_}++. Unfortunately, the current Perl compiler
doesn't catch this error.
Aaron> My question is, what is happening on lines 19 - 21? I've
Aaron> stared at it and stared at it, looked in Perl books,
Aaron> experimented, and have a very fuzzy approximation/guess of
Aaron> what is going on. I know what the result is, just not how
Aaron> that result is acheived. How can clear things up for me?
if $FIELDS{fred}[3] = "betty", then $ALL_FIELDS{"betty"} is set to true,
for any betty, fred, or 3. :) Walk through the dereferencing for
the details. I'd've written this as:
for (values %FIELDS) {
for (@$_) {
$ALL_FIELDS{$_} = 1;
}
}
Does that make more sense now?
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
TIMTOWTDI
More information about the Pdx-pm-list
mailing list