Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Space prepended to Array Print

by grondilu (Friar)
on Jun 08, 2013 at 07:46 UTC ( [id://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 (Cardinal) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1037808]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-16 10:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found