Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: (tye)Re: Recursive opendir without

by bobione (Pilgrim)
on Apr 11, 2001 at 21:52 UTC ( #71770=note: print w/replies, xml ) Need Help??

in reply to (tye)Re: Recursive opendir without
in thread Recursive opendir without

No, it's not a problem of "/" (even if my first exemple could be wrong).
I mean : if I take ton's code and replace $dh by $dir :
use strict; # ---> IMPORTANT my $dir = "toto"; my $file; sub openNewDir { my $dir = shift; ### my $dh; opendir ($dir, $dir); # ---> MODIFICATION while ($file = readdir ($dir)) { # ---> MODIFICATION here too next if (($file eq '.') || ($file eq '..')); if (-d "$dir/$file") { openNewDir("$dir/$file"); } else { # Do something with the file print "($file)\n"; } } close ($dir); # ---> MODIFICATION here too } openNewDir ($dir);
(I comment important lines).
use strict warm me : Can't use string ("toto") as a symbol ref while "strict refs" in use at line 13. (that mean during the readdir()).
And when I was trying to explain you, I think I understood why ;) (but not sure)
It could be that readdir() don't know if $dir is a "Directory Handler" or the "Directory" itself...


Replies are listed 'Best First'.
Re (tilly) 3: Recursive opendir without
by tilly (Archbishop) on Apr 12, 2001 at 06:04 UTC
    $dir is a string (aka "toto") and you are trying to use it as a directory handle. How do you expect that to work?

    Let me give you a hint.

    Create a file called "tst" and run the following snippet without strict on.

    my $file = "tst"; open ($file, $file) or die "Cannot read $file: $!"; print <tst>;
    How did a filehandle get opened on the filehandle tst?

    Now read what strict 'refs' is supposed to disallow.

    Not my link. tye pointed his tutorial out to me and I made the change...

      Great thanks for your link strict. !

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2019-11-15 10:07 GMT
Find Nodes?
    Voting Booth?
    Strict and warnings: which comes first?

    Results (82 votes). Check out past polls.