Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: how to properly handle the closing of pipe? read from the pipe unzip-c and get out before

by Illuminatus (Curate)
on Mar 29, 2011 at 15:03 UTC ( [id://896189]=note: print w/replies, xml ) Need Help??


in reply to how to properly handle the closing of pipe? read from the pipe unzip-c and get out before

I'm sorry, but your english is hard to understand. Let me re-phrase, and you tell me if I have misinterpreted anything.

You have a perl program that needs to extract some information from the beginning of a file in a .zip. As this script is on a production system, you cannot install additional modules that might make this easier. The script as written passes perlcritic, but dies on the croak line for the pipe close. Removing the croak statement (obviously) makes the error disappear, but then it won't pass perlcritic. You believe that the code as written results in a memory leak of some sort, apparent when a large (>10GB) is being unzipped. Does this sound correct?

Given your source (thank you for formatting it properly), I have a couple of general comments:

  1. In your croak statement, you should be using $!, not $ERRNO. This should give you more info on why the close is failing
  2. Unfortunately, $! will only give you the error associated with the close. unzip uses its exit status to identify any reason it had for failure, but I don't think you can get this from the close
  3. You do realize that by using -c instead of -p, it will print the file name before it prints the file data? Your parsing routine does not seem to take this into account.

fnord

  • Comment on Re: how to properly handle the closing of pipe? read from the pipe unzip-c and get out before

Replies are listed 'Best First'.
Re^2: how to properly handle the closing of pipe? read from the pipe unzip-c and get out before
by Eliya (Vicar) on Mar 29, 2011 at 15:47 UTC
    In your croak statement, you should be using $!, not $ERRNO.

    Why?  As he's using English, $ERRNO should be the same as $!.

      You are right, of course. I never use anything but $!, so I had forgotten this. The OP error output seemed to indicate that $ERRNO was blank. I was unsure as to why, or whether he simply omitted it. At any rate, it looks like his problem was fixed by changing the params to unzip

      fnord

        unzip fixed - yes,but error after the close of the pipe is still
        $ perl pipe_quest.pl
        unable to close: unzip -p test.zip utp.live.stp.published.messages.txt at pipe_quest.pl line 29
        mishin
Re^2: how to properly handle the closing of pipe? read from the pipe unzip-c and get out before
by mishin (Sexton) on Mar 29, 2011 at 15:23 UTC
    1. Thank you for translate, you understand correctly
    2. unzip -p it's really work !
    Mishin
Re^2: how to properly handle the closing of pipe? read from the pipe unzip-c and get out before
by mishin (Sexton) on Mar 29, 2011 at 15:42 UTC
    3. you advise to add. percritic
    [Variables::ProhibitPunctuationVars] allow = $@ $!
    mishin
      you advise to add. percritic

      I'd advise dumping perlcritic.

      Advising against using $! is like advising ignoring the temperature warning light on your dashboard and insisting you only regard spoken messages in English. (A language 2/3rds of the programmers in the world don't understand!).


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-19 13:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found