listing a directory by size

A

April

For the following program, found somethings seem not seen before, one
is the input <*>, everything and anything? Another is the usage
$i{$f} or $i{$b}, etc., not sure what that means?

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!
 
J

Jürgen Exner

April said:
For the following program, found somethings seem not seen before, one
is the input <*>, everything and anything?

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
 
X

xhoster

April said:
For the following program, found somethings seem not seen before, one
is the input <*>, everything and anything?

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.
 
B

Ben Morrow

Quoth (e-mail address removed):
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).

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
 
X

xhoster

Ben Morrow said:
Quoth (e-mail address removed):

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.

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 .*

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.
 
J

Jürgen Exner

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.

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
 
J

John W. Krahn

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).


%i is a hash. $i{$f} is a hash lookup.


This is storing each file in the hash %i, with the hash key being the
file name and hash value being the file size.

Actually the value is true or false depending on whether $f is a socket
or not.



John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,209
Messages
2,571,088
Members
47,687
Latest member
IngridXxj

Latest Threads

Top