in reply to Just 1 line explanation
It goes through the values in @display_files, checking each of them in turn against the value of param('select') (which is almost certainly a CGI input parameter).
As the "grep" function is called in scalar context ("unless" evaluates its arguments in scalar context) then it returns the number of items in @display_files that matched param('select'). If that number is zero then the "unless" returns true.
Or more simply, it looks to see if the value of param('select') is found in @display_files and if it's not there, the code following the "unless" condition is executed.
And it does it all in a rather inefficient manner. A more efficient version might look something like this:
my $select = param('select'); my $found; foreach (@display_files) { if ($_ eq $select) { $found = 1; last; } } unless ($found) { # do something }
See perldoc -f grep for more explanation of "grep" and perldoc perlsyn for more explanation of "unless".
"The first rule of Perl club is you do not talk about Perl club." -- Chip Salzenberg
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Just 1 line explanation
by Anno (Deacon) on Mar 19, 2007 at 10:59 UTC | |
by mreece (Friar) on Mar 19, 2007 at 17:06 UTC | |
by Anno (Deacon) on Mar 19, 2007 at 17:51 UTC | |
|
Re^2: Just 1 line explanation
by Nik (Initiate) on Mar 19, 2007 at 11:30 UTC |