Wiggins has asked for the wisdom of the Perl Monks concerning the following question:

I found this code when looking for and example of doing an HTTP POST with only core modules. A snipette is below:
. . . print $sock "POST https://$host/ HTTP/1.1\r\n"; print $sock "Connection: close", "\r\n"; print $sock "Host: ", $host, "\r\n"; print $sock "Content-length: ", length $req, "\r\n"; print $sock "Content-type: application/json\r\n"; #RFC 4627 print $sock $req, "\r\n\r\n"; print while <$sock>; # << ??????? close $sock;
The line in question is marked with a comment...

It is always better to have seen your target for yourself, rather than depend upon someone else's description.

Replies are listed 'Best First'.
Re: A curiosity
by AppleFritter (Vicar) on Aug 12, 2014 at 18:22 UTC

    That line is really just shorthand for the following:

    while(defined($_ = <$sock>)) { print $_; }

    In other words, the code reads from $sock (I assume that $sock is an IO::Socket, so that the angle brackets are overloaded to do what you'd expect them to) and prints each line read to standard output. (What this is useful for here I'm not sure.)

    See Statement Modifiers for more on statement modifiers.

Re: A curiosity
by tobyink (Canon) on Aug 13, 2014 at 06:35 UTC

    AppleFritter has answered your question exactly correctly.

    I'll point out though, that if you want to do an HTTP request with only core modules, HTTP::Tiny has been in core since Perl 5.14. (And on older versions of Perl, it's a very quick and easy installation.)