Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: while loop with diamond operator

by tobyink (Abbot)
on Aug 07, 2012 at 12:34 UTC ( #985961=note: print w/replies, xml ) Need Help??

in reply to while loop with diamond operator

while(<>){ $data = $data . $_ ; }

... can be better written as:

$data = do { local $/; <> };

Not only is that shorter, but it should actually run faster. In your version, Perl has to split STDIN on each new line character, and then join them back together. Localizing $/ just slurps the whole thing in at once.

How exactly are you getting Tomcat to launch your Perl script? Are you 100% sure that whatever mechanism it's using is actually passing data to STDIN?

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://985961]
[Corion]: If you have a BOM, that's a really easy way to recognize UTF-8. Otherwise, you can try to decode a file from UTF-8, and if that works OK and doesn't crash, most likely the file was valid UTF-8
[Corion]: But as "ansi" (Latin-1?) is a single-byte encoding, any file is a valid ANSI file

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2017-03-28 13:21 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (332 votes). Check out past polls.