Perl chdir problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • johntology
    New Member
    • Nov 2007
    • 5

    Perl chdir problem

    Hello,

    I'm having a tough time using chdir in different versions of perl in a dos window (XP). In early versions of Perl 5.x it works just fine. I have a bat file that dynamically sets my perl path to either 5.0.x or to 5.8.8:

    Code:
    path %path%;c:\perl\[whichever]
    Then in I call the perl script which just has this:

    [code=perl]
    $dirLocation ='c:\[whatever]';

    chdir $dirLocation or die "Can't cd to $dirLocation: $!\n";

    [/code]

    In the earlier version of perl it works fine and moves dos to that directory. In 5.8.8 it doesn't. But nor does it die. It just doesn't switch directories. I've confirmed that it's at least looking for a valid dir by changing $dirLocation to something nonexistent and it does indeed then balk. So what am I missing here???

    Thanks for any help.

    John
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Originally posted by johntology
    Hello,

    I'm having a tough time using chdir in different versions of perl in a dos window (XP). In early versions of Perl 5.x it works just fine. I have a bat file that dynamically sets my perl path to either 5.0.x or to 5.8.8:

    Code:
    path %path%;c:\perl\[whichever]
    Then in I call the perl script which just has this:

    [code=perl]
    $dirLocation ='c:\[whatever]';

    chdir $dirLocation or die "Can't cd to $dirLocation: $!\n";

    [/code]

    In the earlier version of perl it works fine and moves dos to that directory. In 5.8.8 it doesn't. But nor does it die. It just doesn't switch directories. I've confirmed that it's at least looking for a valid dir by changing $dirLocation to something nonexistent and it does indeed then balk. So what am I missing here???

    Thanks for any help.

    John
    If I may ask, how do you know that it is not working, especially if you get no errors?

    Regards,

    Jeff

    Comment

    • eggi
      New Member
      • Nov 2007
      • 9

      #3
      Hi,


      Try:
      chdir("$dirloca tion");

      , Mike

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        Originally posted by eggi
        Hi,


        Try:
        chdir("$dirloca tion");

        , Mike
        adding quotes around a single scalar will not help and should really never be done anyway. It's a bad habit to get into when writing perl programs.

        Comment

        • johntology
          New Member
          • Nov 2007
          • 5

          #5
          Originally posted by numberwhun
          If I may ask, how do you know that it is not working, especially if you get no errors?

          Regards,

          Jeff

          Jeff, DOS should change to the directory specified in the perl command. In my case it doesn't. It just stays where it was before running the script. Thanks.

          Comment

          • numberwhun
            Recognized Expert Moderator Specialist
            • May 2007
            • 3467

            #6
            Originally posted by johntology
            Jeff, DOS should change to the directory specified in the perl command. In my case it doesn't. It just stays where it was before running the script. Thanks.
            I would definitely go with eggi's suggestion of using the chdir() function to change the working directory and see if that works then.

            Regards,

            Jeff

            Comment

            • sakurakun
              New Member
              • Oct 2011
              • 1

              #7
              Try using a forward slashes instead of a backward slashes
              in your path.

              Regards,
              Sakurakun

              Comment

              Working...