Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: direct data to a socket

by Loops (Curate)
on Oct 22, 2014 at 08:19 UTC ( [id://1104653]=note: print w/replies, xml ) Need Help??


in reply to direct data to a socket

The $_[0] is the socket that is passed from the accept into the sub. The filename is looked up and if it is executable, a pipe is created with it, otherwise it is opened directly. In either case the contents of the resulting IO::All object are fed into the $_[0] socket. Very similar to the simplistic use of '<' in:

$contents < io 'file.txt';

So this oneline web server can send the contents of simple files, or the generated output from executables.

Update: The reason you couldn't find anything in perldoc is because this is an operator that has been overridden to act in this way by IO::All which is where the simple example above comes from. Thus, you can only use the '<' operator this way with IO:All objects.

Replies are listed 'Best First'.
Re^2: direct data to a socket
by demoralizer (Beadle) on Oct 22, 2014 at 08:54 UTC
    Thanks for your answer Loops...

    what I'm really looking for is the meaning of this <, the whole rest is quite simple and completely clear.

    I know this redirection from shell command line but not within perl... is it the same meaning here?
    Can you point me to perldoc where this is described, please?

      This is magic employed by IO::All.

      If you want to know the details, IO::All overrides some operators of Perl to make the normal Perl syntax do something different when dealing with IO::All objects.

      The expression is simply $a < $b, the comparison expression. Except that the IO::All objects do something different when "compared" with something, to make this syntax appear like shell redirection.

        Wow, that's icky. I understand why overloading exists, and needs to exist. Things like being able to subtract two DateTime objects and get a DateTime::duration object are the stuff of which consistent, intuitive behavior are made. But overloading what is normally a comparison operator to do something completely semantically unrelated to comparison doesn't make me smile. If it were in the ACME:: namespace, that would be one thing...

        Now it's clear or at least I know where to search for :)

        Thanks a lot to all of you, for bringing some enlightenment to me!
      Updated the original post, to be more clear about that part, but not quickly enough, sorry. As I said in that update, this is a specific operator overload implemented by IO::All. It is very specific to objects created with IO::All and so you wont see examples of usage like this anywhere else in perldoc.

Log In?
Username:
Password:

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

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

    No recent polls found