STDIN to String (codegolf)

Add a reply

Posted by Zapp 693 days ago:
Cause code from any challenge isn't published here, i thought about code golfing on fragements, to improve your and my golfing!
Of course, integrating STDIN directly into your algorithms will make your code shorter for a few bytes, but since not everyone is a pro, try your best on those tiny tasks ;)


Part 1: STDIN to String

1. containing newlines
13 bytes:

@_=<>;s//@_/;
or
$_=join'',<>;


2. without newlines
15 bytes:

$s.=$_ while<>;


Any other or shorter codes?

cheers
Zapp
Posted by Sartak 682 days ago:
2. without newlines
15 bytes:

$s.=$_ while<>;

Why not just use this?

$s=<>;
Posted by Zapp 676 days ago:

$s=<>;

Sry, my fault.

Forgot to mention, that it is (or could be) a multi-line source (file).
So the code above would only read one line, containing newline char.
Posted by robin 635 days ago:
$\=$u;$_=<>

assuming $u is undefined.
Posted by robin 635 days ago:
$\=$u;$_=<>

assuming $u is undefined.
Posted by robin 635 days ago:
Oops, typo above! I meant:

$/=$u;$_=<>

(Sorry about the double-post, too.)
Posted by essohbee 550 days ago:
@f = <>;

does the trick

Add a reply