Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: function chdir in Module Cwd broken?

by Aighearach (Initiate)
on Nov 08, 2004 at 20:39 UTC ( [id://406203]=note: print w/replies, xml ) Need Help??


in reply to function chdir in Module Cwd broken?

First of all, you shouldn't use the same module twice. You can get rid of the second one, it seems to export chdir and getcwd by default.

Are your permissions correct for the dir? Specifically, are /x, /x/y and /x/y/z all executable by your user? There are the test results I got:

$ perl -v This is perl, v5.8.0 built for i586-linux-thread-multi $ perl -MCwd -le 'chdir "/tmp"; print getcwd();' /tmp $ perl -MCwd -le 'chdir "/root"; print getcwd();'

--
Snazzy tagline here

Replies are listed 'Best First'.
Using the same module twice
by ikegami (Patriarch) on Nov 08, 2004 at 20:50 UTC
    While I agree the duplicate use is bad in the OP, I disagree with your blanket statement that a module shouldn't be used twice. For example, my script and a module used by my script might both use FileHandle. It can even be acceptable within the same file. Consider a style I often use:

    use Some::Module (); # Don't import anything here. # ---------- package Package1; use Some::Module qw( ... ); # import something ... # ---------- package Package2; use Some::Module qw( ... ); # import something ... # ---------- package main; { ... main program ... }

    One could argue this should be split into multiple files, but you'd still be including the Some::Module more than once.

      Yeah, but I think that it's still true as a general principle. Of course there are exceptions. I'd even go so far as to say, there are exceptions to the rule "never use goto LABEL" . But I would still say, when I was looking at something other than that cosmically rare situation, that the general rule is valid.

      The only reason your example is okay, IMO, is that you're pressed for time and are planning to split that module into more than one later, when your teapot isn't boiling over or whatever. That's the only reason for it; it's temporary and prevents a problem later. Otherwise it's redundant, confusing, and reinforces and incorrect notion of scope.


      --
      Snazzy tagline here
Re^2: function chdir in Module Cwd broken?
by Fletch (Bishop) on Nov 08, 2004 at 21:52 UTC

    Actually as a style nit I'd say get rid of the first one and leave the one which explicitly states what it's importing (as opposed to the first which depends on the graces of @EXPORT). But again that's just me and is neither here nor there with respect to chdir functioning or not.

      In that case it would have to be altered to add getcwd(). But another view is that being overly explicit creates a bunch of noise. And it can make things brittle. Also there are rare cases where that changes the expected behavior of a module. The important thing is, know what use Foo "bar" means, and use it in a self-consistent way.

      --
      Snazzy tagline here
Re^2: function chdir in Module Cwd broken?
by jethro (Monsignor) on Nov 09, 2004 at 01:56 UTC
    You are right, the second use seems to be superfluous, contrary to the perldoc of chdir.

    But even if the perldoc were true, I could have used Cwd::chdir or listed all the symbols in the use statement. It would be safer, but I'm not sure if modules shouldn't be designed to be called more than once.
    Similar to header files in C, where it made header handling so much easier.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-16 14:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found