morgon has asked for the wisdom of the Perl Monks concerning the following question:
I need to find the number of entries in a directory, so I do this:
What bugs me is the "grep {1}"-thing that I do for the sole purpose of forcing a list-context on the readdir as doing simpy a $entries = scalar (readdir $dh) (i.e. putting paentheses around the call) does not do the trick...opendir my $dh, $dir or die $!; my $entries = grep {1} readdir $dh;
So I wonder now: What is the idiomatic way to force list-context?
Many thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: forcing list-context
by choroba (Cardinal) on Jan 23, 2012 at 14:40 UTC | |
by pvaldes (Chaplain) on Jan 23, 2012 at 15:09 UTC | |
by educated_foo (Vicar) on Jan 23, 2012 at 15:32 UTC | |
by AnomalousMonk (Archbishop) on Jan 23, 2012 at 19:47 UTC | |
by LanX (Saint) on Jan 23, 2012 at 16:10 UTC | |
|
Re: forcing list-context
by BrowserUk (Patriarch) on Jan 23, 2012 at 20:22 UTC | |
|
Re: forcing list-context
by JavaFan (Canon) on Jan 23, 2012 at 14:55 UTC | |
by morgon (Priest) on Jan 23, 2012 at 15:03 UTC | |
|
Re: forcing list-context
by ikegami (Patriarch) on Jan 23, 2012 at 22:25 UTC | |
|
Re: forcing list-context
by Arunbear (Prior) on Jan 23, 2012 at 17:31 UTC | |
|
Re: forcing list-context
by pvaldes (Chaplain) on Jan 23, 2012 at 15:22 UTC | |
by jwkrahn (Abbot) on Jan 24, 2012 at 00:21 UTC |