in reply to backticks and 'Cannot allocate memory'

At the time it returns undef, I examined $!
You can only trust $! to contain something sensible immediately after a failed system call. (Which is something else than a call to system). Since cwd() calls pwd inside backticks, there's no system call, let alone a failed one (unless the fork() would fail, but then, time has passed). You may have more success in checking $?.
  • Comment on Re: backticks and 'Cannot allocate memory'

Replies are listed 'Best First'.
Re^2: backticks and 'Cannot allocate memory'
by NetWallah (Canon) on Sep 24, 2010 at 00:47 UTC
    Here is what I get in $?:
    DB<5> x $?,$! 0 '-1' 1 'Cannot allocate memory' DB<6> x qx|pwd| empty array DB<7> x $?, $! 0 '-1' 1 'Cannot allocate memory'
    Memory utilization (ps -auxf):
    admin 5033 6.3 61.4 1301804 1251316 pts/1 S+ 16:56 2:17 | \_ perl -d Program-name

         Syntactic sugar causes cancer of the semicolon.        --Alan Perlis

      $! being 1 is probably just a default value. I get $! to be 1 as well, but it means something differently:
      DB<1> x $?, $! + 0 0 1 'Illegal seek'
      However, my pwd does succeed. It still leaves $! to be 1, but it's string value changes:
      DB<2> x qx|pwd| + 0 '/tmp ' DB<3> x $?, $! + 0 0 1 ''
      It's curious to see your pwd fails. Is that from a debugging session where you aren't doing anything else? What happens if you use the fully qualified name to pwd? Anyway, the external pwd failing isn't something that happens on the perl level.
        Oh - under "normal" conditions, backticks and pwd work just fine -
        main::(-e:1): exit 0 DB<1> x qx |pwd| 0 '/home/admin ' DB<2> x $?,$! 0 0 1 '' DB<3> q
        But, in my program, I set a breakpoint to stop when cwd() returns undef. After that point, which is several hundred data files into the execution of the program, the weird behaviour is observed.

        So - I'm not sure I understand all the responses here, not being much of a linux OS and forking geek. Is there a reason the believe that backticks cause memory leaks ? Is there an alternative way for Cwd::cwd to return the current path without 'pwd' ? How can I persuade it to do so, when it is used as a sub-module inside Archive::Extract which I am calling ?

             Syntactic sugar causes cancer of the semicolon.        --Alan Perlis