Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

How do I create a new array in memory?

by Buckaroo Buddha (Scribe)
on Jun 27, 2000 at 01:20 UTC ( [id://19919]=perlquestion: print w/replies, xml ) Need Help??

Buckaroo Buddha has asked for the wisdom of the Perl Monks concerning the following question: (arrays)

Hi there,
I'm trying to figure out how to make sure each array claims its own memoryspace.

How do I do that?

while <> { @record = split(',',$_); $key = shift(@record); $list{$key} = \@record; }

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: How do I create a new array in memory?
by btrott (Parson) on Jun 27, 2000 at 02:03 UTC
    You need to declare the variable lexically with my:
    while (<>) { my @record = split /,/; my $key = shift @record; $list{$key} = \@record; }
    You can test this by printing out the array references; they should all have different addresses:
    print join "\n", values(%list), '';
Re: How do I create a new array in memory?
by davorg (Chancellor) on Jun 27, 2000 at 15:09 UTC

    The other way to do it is to take a copy of the array each time by using the anonymous array constructor.

    while (<>) { my @record = split /,/; my $key = shift @record; $list{$key} = [@record]; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-07-17 19:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.