Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

readdir() only returns one result when used with Fatal.pm

by jesuashok (Curate)
on Apr 11, 2006 at 03:57 UTC ( #542441=perlquestion: print w/ replies, xml ) Need Help??
jesuashok has asked for the wisdom of the Perl Monks concerning the following question:

Hi all

Fatal.pm and readdir() do not play well together. Run the following script in a directory containing several files. It only prints out '.'. Then comment out the 'use Fatal' line and run the script again. It now prints out all the files in the directory.

#!/usr/bin/perl use strict; use warnings; use Fatal qw(readdir); my $start_dir = '.'; opendir(my $dir, $start_dir); my @subdir = readdir $dir; closedir $dir; print "@subdir\n";

"Keep pouring your ideas"

2006-10-07 Unapproved by planetscape once evidence of habitual plagiarism uncovered.

Comment on readdir() only returns one result when used with Fatal.pm
Download Code
Re: readdir() only returns one result when used with Fatal.pm
by diotalevi (Canon) on Apr 11, 2006 at 04:18 UTC

    Yes, that's right. I'd already planned to patch Fatal in bleadperl. That'll likely be a few days away, at least.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Re: readdir() only returns one result when used with Fatal.pm
by codeacrobat (Chaplain) on Apr 11, 2006 at 06:34 UTC
    Hmm and I thought it would only prevent onliners :-(
    $ perl -MFatal+qw/open close/ -e 'open( F, "fasel"); print <F>;close F +;' Can't open perl script "close/": No such file or directory

      You should reread the error message you got there.

      perl -MFatal+qw/open close/ -e 'open( F, "fasel"); print <F>;close F;' Can't open perl script "close/": No such file or directory

      should be written

      perl -MFatal=open,close -e 'open( F, "fasel"); print <F>;close F;'

      or on win32:

      perl -MFatal=open,close -e "open( F, q(fasel)); print <F>; close F;"

      which produces

      Can't open(F, fasel): No such file or directory at (eval 1) line 3 main::__ANON__('F', 'fasel') called at -e line 1
      ---
      $world=~s/war/peace/g

Re: readdir() only returns one result when used with Fatal.pm
by Tomte (Priest) on Apr 11, 2006 at 09:19 UTC

    Seems to be a bug in context evaluation in FATAL, this code works and throws an exception when readdir returns undef:

    #!/usr/bin/perl use strict; use warnings; use Fatal qw(readdir); $| = 1; my $start_dir = '.'; opendir(my $dir, $start_dir); while($_= readdir($dir)) { print "$_ "; } closedir $dir;

    Update 2006/04/28: This apparently isn't a bug in Fatal, but simply the fact that readdir can't be correctly "fatalized" 'cause it doesn't clearly indicates failure (and only failure) returning a false value. The documentation of Fatal will be updated to reflect better when to use it.

    regards,
    tomte


    An intellectual is someone whose mind watches itself.
    -- Albert Camus

Re: readdir() only returns one result when used with Fatal.pm
by ambrus (Abbot) on Apr 11, 2006 at 11:54 UTC
Re: readdir() only returns one result when used with Fatal.pm
by liverpole (Monsignor) on Oct 06, 2006 at 11:14 UTC
    From this site:
    On Thu, Mar 23, 2006 at 02:03:57PM +0100, Rafael Garcia-Suarez wrote: > Tom Hukins (via RT) wrote: > > Fatal.pm and readdir() do not play well together. Run the followi +ng > > script in a directory containing several files. It only prints ou +t '.'. > > Then comment out the 'use Fatal' line and run the script again. I +t now > > prints out all the files in the directory. > > > > #!/usr/bin/perl > > > > use strict; > > use warnings; > > > > use Fatal qw(readdir); > > > > my $start_dir = '.'; > > opendir(my $dir, $start_dir); > > my [at]subdir = readdir $dir; > > closedir $dir; > > print "@subdir\n"; >

    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

      It's interesting that this wasn't noticed before as not only have at least two regular p5p contributors replied in this thread but the original author of the bug report can occasionally be found here. I suppose it just goes to show how uncritical we all are when we don't suspect something might be afoot.

      /J\

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://542441]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2014-07-13 09:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (249 votes), past polls