Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: Add new data to array

by BillKSmith (Monsignor)
on Mar 17, 2020 at 21:09 UTC ( [id://11114401]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Add new data to array
in thread Add new data to array

I do not understand what you mean. Your code is not valid Perl.
>type tryit.pl use strict; use warnings; my $add_in = (); my @$add_in = $add_ins[0]; >perl tryit.pl "my" variable $add_in masks earlier declaration in same scope at tryit +.pl line 4 . Can't declare array dereference in "my" at tryit.pl line 4, near "$add +_in =" Global symbol "@add_ins" requires explicit package name (did you forge +t to decla re "my @add_ins"?) at tryit.pl line 4. Execution of tryit.pl aborted due to compilation errors.

I defined the array @add_ins to force grep to run in list context. Execution of grep returnes a list (which contained only one element) and assigned it to @add_ins. The statement my $add_in = $add_ins[0]; assigns the value of that element to the scalar $add_in. Note that the value is a reference to the hash which contains the data which is to be added to every hash. AnomolousMonk accomplished the same thing by using the extra parenthesis to force list context and used list assignment to extract the single reference.

Bill

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-20 04:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found