On Jun 7, Shawn said:
>Japhy pointed out this particular syntax to me. Before this, I was using
>@files = grep {/jpe?g$/i} readdir DIR;
>
>Can someone let me know what effectively is the difference between
>@files = grep {/jpe?g$/i} readdir DIR;
>and
>@files = grep /jpe?g$/i, readdir DIR;
If you look at the grep() documentation (perldoc -f grep), you'll see that
grep() (like map()) can take either an expression (EXPR) or a block
(BLOCK) as its argument.
By the way, you probably mean to include a \. at the front of your regex,
since right now, it allows "foojpg" to go through, when really you mean to
be checking for "foo.jpg".
@files = grep /\.jpe?g$/i, readdir DIR;
Notice that when using grep(EXPR, LIST), the comma is needed after the
expression, whereas when using grep(BLOCK LIST), there is NO comma.
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
** Manning Publications, Co, is publishing my Perl Regex book **