Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

listing a directory by size

0 views
Skip to first unread message

April

unread,
Jun 19, 2008, 10:41:49 PM6/19/08
to
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ürgen Exner

unread,
Jun 20, 2008, 12:25:37 AM6/20/08
to
April <xiaoxi...@yahoo.com> wrote:
>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

John W. Krahn

unread,
Jun 20, 2008, 1:44:41 AM6/20/08
to
Jürgen Exner wrote:
> April <xiaoxi...@yahoo.com> wrote:
>> For the following program, found somethings seem not seen before, one
>> is the input <*>, everything and anything?
>
> Another way of writing
> glob(*);

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

Jürgen Exner

unread,
Jun 20, 2008, 4:40:59 AM6/20/08
to
"John W. Krahn" <som...@example.com> wrote:
>Jürgen Exner wrote:
>> April <xiaoxi...@yahoo.com> wrote:
>>> For the following program, found somethings seem not seen before, one
>>> is the input <*>, everything and anything?
>>
>> Another way of writing
>> glob(*);
>
>ITYM: glob '*';

Hmmm, yes.

jue

xho...@gmail.com

unread,
Jun 20, 2008, 11:13:38 AM6/20/08
to
April <xiaoxi...@yahoo.com> wrote:
> 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.

Ben Morrow

unread,
Jun 20, 2008, 11:32:32 AM6/20/08
to

Quoth xho...@gmail.com:

> April <xiaoxi...@yahoo.com> wrote:
> > 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).

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]

xho...@gmail.com

unread,
Jun 20, 2008, 12:02:48 PM6/20/08
to
Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth xho...@gmail.com:
> > April <xiaoxi...@yahoo.com> wrote:
> > > 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).
>
> 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 .*

Jürgen Exner

unread,
Jun 20, 2008, 12:20:35 PM6/20/08
to
xho...@gmail.com wrote:

>Ben Morrow <b...@morrow.me.uk> wrote:
>> 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.

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

John W. Krahn

unread,
Jun 20, 2008, 1:37:21 PM6/20/08
to
xho...@gmail.com wrote:
> April <xiaoxi...@yahoo.com> wrote:
>> 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.

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

0 new messages