Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Is readdir ever deterministic?

by arturo (Vicar)
on Sep 17, 2001 at 18:54 UTC ( #112870=note: print w/replies, xml ) Need Help??


in reply to Is readdir ever deterministic?

I'm not qualified to comment on the variations among systems or the lack of determinism, but as far as coding defensively, you could just put a filter on the files with grep :

foreach my $file ( grep { !/^\.{1,2}$/ } readdir DIR ) { munge($file); }
perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'

Replies are listed 'Best First'.
Re: Re: Is readdir ever deterministic?
by merlyn (Sage) on Sep 18, 2001 at 01:25 UTC
    Well, being truly defensive, you should have written:
    foreach my $file ( grep { !/\A\.{1,2}\z/ } readdir DIR ) { munge($file); }
    Or else the day someone creates a file named dot-newline or dotdot-newline, you'll be very angry.

    -- Randal L. Schwartz, Perl hacker

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://112870]
help
Chatterbox?
[Corion]: Nice to see that the kids have some understanding of important things that happen and the appropriate behaviour :)
[marto]: at times mine surprise me with this behavior :)
[Corion]: I mean, in a way it would be nicer+easier if they always where that obedient, but it's comforting to see that they are when it matters, at least for now ;)

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2016-12-08 09:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (138 votes). Check out past polls.