Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Re: Array in Array

by nylon (Acolyte)
on Oct 06, 2003 at 13:16 UTC ( #296925=note: print w/replies, xml ) Need Help??

in reply to Re: Array in Array
in thread Array in Array

Thanks for the help.
I get
ARRAY(0x253a350) ARRAY(0x2536024) ARRAY(0x2532bb8) ARRAY(0x248e328) ARRAY(0x248c1d0) ARRAY(0x2488e40)
if I run :
sub tweezers_sub { my @accounts_2 = map {[@{{split}}{@fields}]} @accounts; foreach $rec(@accounts_2) { print FH_temp ("$rec\n"); } # Prints all array records to the output file }
That's what I call the "spooky stuff". :-)
(PS: have installed the YAML module. Nice :-)

Replies are listed 'Best First'.
Re: Re: Re: Array in Array
by CombatSquirrel (Hermit) on Oct 06, 2003 at 14:40 UTC
    Your $rec variable is actually a reference to an array. You should dereference it, for example by writing my @rray = @$rec;, or, TIMTOWTDI:
    #!/usr/bin/perl use strict; use warnings; my @accounts = ("A x1 B y1 C z1 D v1 E w1 F", "A x2 B y2 C zzz2 D v2 E w2 F", "A x3 B y3 C z3 D v3 E w3 F", "A x4 B y4 C z4 D v4 E wwww4 F", "A x5 B y5 C z5 D v5 E w5 F", "A x6 B y6 C z6 D v6 E F"); my @fields = ("A", "B", "C", "D", "E"); sub tweezers_sub { my @accounts_2 = map { [@{{/([A-Z])\s+([a-z]+\d|\s)/g}}{@fields} ] +} @accounts; for my $rec (@accounts_2) { print "'" . join("' - '", @$rec) . "'\n"; } } tweezers_sub;
    This uses a RegEx instead of a split, but you can still see how $rec is dereferenced by writing @$rec.
    Hope this helped.
    Update: Mixed up referencing and dereferencing. Fixed.
    Entropy is the tendency of everything going to hell.
Re: Array in Array
by Abigail-II (Bishop) on Oct 06, 2003 at 13:21 UTC
    That's what you are supposed to get - you are printing out a reference to an array. What did you expect to get?


      I was hoping on the content. Life is not simple for an apprentice. :-( ;-)
        References are like boxes. If you take a picture of them, you get just that: the box. To get to the content, you first have to open them. It's the same with references. If you print them, you just get that: some kind of 'spooky' representation of the reference. To get to the content, open it. For references pointing to arrays, you do that by placing a @ in front of the reference. So, for instance:
        print "@$array_ref\n";


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2023-02-03 01:31 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (24 votes). Check out past polls.