Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: push values to an element of an array and read the same

by Athanasius (Archbishop)
on Sep 28, 2017 at 07:32 UTC ( [id://1200247]=note: print w/replies, xml ) Need Help??


in reply to push values to an element of an array and read the same

push @colvalues1, $allcols[0],':',$allcols[1],"\n";

This pushes 4 separate values onto the array. If @colvalues1 was empty before the operation, the push populates it like this:

17:27 >perl -MData::Dump -wE "my @allcols = ('abc', 'def'); my @colval +ues1; push @colvalues1, $allcols[0],':',$allcols[1],qq[\n]; dd \@colv +alues1;" ["abc", ":", "def", "\n"] 17:27 >

Perhaps you intended to concatenate these 4 fields into a single string?

17:28 >perl -MData::Dump -wE "my @allcols = ('abc', 'def'); my @colval +ues1; push @colvalues1, $allcols[0].':'.$allcols[1].qq[\n]; dd \@colv +alues1;" ["abc:def\n"] 17:29 >

That is, replace the commas (which produce a list) with dots (which concatenate).

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-24 19:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found