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

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 test.pl 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...

BoBiOne

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.

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

      Great thanks for your link strict. !
      BoBiOne

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://71770]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2018-07-20 10:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (427 votes). Check out past polls.

    Notices?