Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Splicing the next element in an array

by Laurent_R (Canon)
on Apr 08, 2014 at 16:46 UTC ( [id://1081527]=note: print w/replies, xml ) Need Help??


in reply to Splicing the next element in an array

Possibly with the map function:
my @infoArray = (1, 2, 3, 4, 5, "\n", 6, 7, 8, 9, 10, "\n"); my @final_array = map { $_ eq "\n" ? $_ : "$_\t"} @infoArray; # now print @final_array, for example: print join '', @final_array;
which prints:
1 2 3 4 5 6 7 8 9 10
Or you could print directly the output of map:
print join '', map { $_ eq "\n" ? $_ : "$_\t"} (1, 2, 3, 4, 5, "\n", + 6, 7, 8, 9, 10, "\n");
giving the same output.

Update (Apr 08, 2014 at 17:15 UTC): added the output and the one-line final piece of code (did not have Perl on my tab when I wrote the original post while in public transportation).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-19 03:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found