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

Re: Read into stdin pipe characters

by dasgar (Priest)
on Oct 05, 2010 at 23:09 UTC ( #863703=note: print w/replies, xml ) Need Help??


in reply to Read into stdin pipe characters

First, I'm going to assume that you're running on a *nix platform based off of your shebang line.

To call your script, you do have to encapsulate the desired pipe character inside of quotes. If you don't, the shell with believe that the pipe character is telling it to do something. Also, encapsulating it in quotes will not pass the quotes to your script.

For example, let's say you try calling your program like this: perl script.pl b c|d|e|f. Here's how your shell will process that.

  1. Need to call the perl executable with parameters
  2. script.pl is the first parameter to pass
  3. b is the next parameter to pass
  4. c is the next parameter to pass
  5. Pipe that output to d
  6. Pipe that output to e
  7. Pipe that output to f

In this case, I'd agree with ReturnOfThelonious that the error is from the shell and not your script. If you were instead to call your script like this : perl script.pl b "c|d|e|f", here's how your shell would process it.

  1. Need to call the perl executable with parameters
  2. script.pl is the first parameter to pass it
  3. b is the next parameter to pass
  4. c|d|e|f is the next parameter to pass

Notice the lack of quotes in the last step? The quotes will basically tell the shell: "Hey, treat everything in side this quote as a parameter and DO NOT view this content as instructions for you to do". The quotes are not actually passed by the shell into your script. This is why toolic suggested that you "quote your passed strings".

I apologize for the length of this post. But since you didn't seem to quite understand what toolic was suggesting, I thought I'd go the extra length to clearly explain the quoting from the shell's perspective.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2017-12-15 02:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (415 votes). Check out past polls.

    Notices?