Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Space prepended to Array Print

by grondilu (Friar)
on Jun 08, 2013 at 07:46 UTC ( #1037808=note: print w/replies, xml ) Need Help??


in reply to Space prepended to Array Print

Other comments above give you the explanation on what happened.

Me, when I want to put the lines of a text file in an array, I usually write:

my @data = map { chomp; $_ } <>;

And when I want to output it, I write:

print "$_\n" for @data

In Perl6 I'd write:

my @data = lines; .say for @data;

Replies are listed 'Best First'.
Re^2: Space prepended to Array Print
by choroba (Bishop) on Jun 08, 2013 at 07:57 UTC
    A bit faster is to use chomp for the array:
    chomp(my @data = <>);
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2018-06-21 16:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (118 votes). Check out past polls.

    Notices?