foreach $f (<*>) ( $i{$f} = -S $f };
foreach $k (sort{ $i{$b} <=> $i${a} } keys %i}
{ printf "%8d %s\n", $i{$k}, $k }
Any guru can explain? Thanks!
Another way of writing
glob(*);
> Another is the usage
>$i{$f} or $i{$b}, etc., not sure what that means?
See
perldoc perldata
and look for hashes. It is retrieving the value of %i for the key that
has the value of $f resp. $b.
jue
ITYM: glob '*';
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
Hmmm, yes.
jue
Yes. There is nothing special about it, it is just the "file glob" version
of the diamond operator, and just happens to have an argument of '*', which
does indeed mean all non-hidden files (in the current directory).
> Another is the usage
> $i{$f} or $i{$b}, etc., not sure what that means?
%i is a hash. $i{$f} is a hash lookup.
> foreach $f (<*>) ( $i{$f} = -S $f };
This is storing each file in the hash %i, with the hash key being the
file name and hash value being the file size.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
So, not everything and anything. Specifically, it omits all files with
names beginning with '.', even on OSs where that is not a convention for
'hidden file'. It ignores e.g. DOS 'hidden file' attributes.
Ben
--
Many users now operate their own computers day in and day out on various
applications without ever writing a program. Indeed, many of these users
cannot write new programs for their machines...
-- F.P. Brooks, 'No Silver Bullet', 1987 [b...@morrow.me.uk]
I did not know that. I knew it used the Unix interpretation of "*.*"
rather DOS's, but I didn't know it also used Unix's method of hiddenness.
Maybe 'Why doesn't glob("*.*") get all the files?' should be changed
to make that clearer. I don't exactly how, maybe from:
You'll need "glob("*")" to get all (non-hidden) files
to
You'll need "glob("*")" to get all (non-dot) files
That doesn't sound all that clear either.
Maybe adding ", including the Unix notion of filenames starting with a
dot being hidden." after:
Because even on non-Unix ports, Perl's glob function follows standard Unix
globbing semantics
Anyway, I found it misleading as-is because I assumed the semantics being
discussed were only those concerning *.*, not also those concerning .*
It's documented but well hidden in perldoc -f glob:
glob Returns the value of EXPR with filename expansions such as
the standard Unix shell /bin/csh would do. [...]
I guess you just have to know what /bin/csh would do.
>Anyway, I found it misleading as-is because I assumed the semantics being
>discussed were only those concerning *.*, not also those concerning .*
Another good point.
jue
Actually the value is true or false depending on whether $f is a socket
or not.