Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: element of an array of arrays

by frozenwithjoy (Priest)
on Jun 17, 2013 at 02:14 UTC ( #1039252=note: print w/replies, xml ) Need Help??

in reply to element of an array of arrays

You don't actually have an array of arrays:

use Data::Printer; p @Records; p @RecCheck;
[ [0] "AAA,20130610,730,1015, ", [1] "BBB,20130610,1015,1200, ", [2] "CCC,20130610,1230,1400, ", [3] "DDD,20130610,1415,1530, " ] [ [0] "AAA,20130610,730,1015, ", [1] "BBB,20130610,1015,1200, ", [2] "CCC,20130610,1230,1400, ", [3] "DDD,20130610,1415,1530, " ]

I left your @Records almost as is (only removed new line) and changed @RecCheck so that it would be an array of arrays like I think you wanted:

#!/usr/bin/env perl use strict; use warnings; use feature 'say'; use Data::Printer; my @Records; push( @Records, join ',', ( "AAA", 20130610, 730, 1015 ) ); push( @Records, join ',', ( "BBB", 20130610, 1015, 1200 ) ); push( @Records, join ',', ( "CCC", 20130610, 1230, 1400 ) ); push( @Records, join ',', ( "DDD", 20130610, 1415, 1530 ) ); my @RecordRowFields; my @RecCheck; for my $RecordRow (@Records) { @RecordRowFields = split /,/, $RecordRow; push( @RecCheck, [@RecordRowFields] ); } say "Single element: $RecCheck[1][2]"; p @RecCheck; __END__ [ [0] [ [0] "AAA", [1] 20130610, [2] 730, [3] 1015 ], [1] [ [0] "BBB", [1] 20130610, [2] 1015, [3] 1200 ], [2] [ [0] "CCC", [1] 20130610, [2] 1230, [3] 1400 ], [3] [ [0] "DDD", [1] 20130610, [2] 1415, [3] 1530 ] ] Single element: 1015

Replies are listed 'Best First'.
Re^2: element of an array of arrays
by JockoHelios (Scribe) on Jun 17, 2013 at 02:21 UTC
    So when I push arrays onto an empty array, that doesn't create an array of arrays ?

    Interesting, that's not where I thought the problem was. Now I'm at a loss. How would I create an array of arrays with that data ?

    Dyslexics Untie !!!
      I just updated my answer w/ code that creates an AoA. You were basically pushing a list into an array and it gets incorporated into the array just like all the elements. What you needed to do was push an array reference.

      So when I push arrays onto an empty array, that doesn't create an array of arrays ?

      an array of arrays is an array of arrayrefs

      When you push @arra, @array you're pushing a list onto @arra

      push @arra, \@array; ## pushing arrayreference, array of arrays achieved

        perldoc -f push
        push ARRAY,LIST
        push EXPR,LIST
        Treats ARRAY as a stack by appending the values of LIST to the end of ARRAY. The length of ARRAY increases by the length of LIST.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1039252]
[erix]: then you might as well send that patch to the DBIC guys :)
[Corion]: erix: Yeah, I just found that it has no documentation at all on how to circumvent/ eliminate "1+n SELECTs" by building a local hash... I guess I have to make ->has_many do the hash lookup instead of doing the SQL query. But as the problem ...
[Corion]: ... has only manifested itself so far through the puzzled questions of other bystanders, I won't go deeper at this time. But the DBIx::Class documentation could well do with a document on how to make "it" (that is, ORMs in general) faster ;)
[Corion]: I find that DBIx::Class, like most ORMs makes things easy until they become performance critical and then makes it horribly hard to change things because the design is highly inflexible if you don't already know about the problems of 1+n :-/

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2017-09-25 11:06 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (279 votes). Check out past polls.