Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: arrays and dot operator

by vrk (Chaplain)
on Apr 05, 2017 at 14:06 UTC ( #1187123=note: print w/replies, xml ) Need Help??

in reply to arrays and dot operator

It's not a newline problem. In your second section, the line print @new_array . "\n" has @new_array in scalar context, because the string concatenation operator (.) puts its arguments in scalar context. The line is actually executed as print scalar(@new_array) . "\n". In scalar context, you get the array length, which is 5 in this case.

If you want to print a newline after the array, just use a comma:

print @new_array, "\n";

Replies are listed 'Best First'.
Re^2: arrays and dot operator
by BillKSmith (Monsignor) on Apr 05, 2017 at 14:59 UTC
    Or use:
    #print "@array,\n"; print "@array\n";

    This will print the array elements separated by the contents of $" (space by default), followed by the newline.

    Update: Removed comma as indicated by vrk


      You have an extra comma there.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1187123]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2023-02-05 20:42 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (32 votes). Check out past polls.