Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Arrays and Push

by fullermd (Curate)
on Apr 03, 2014 at 04:54 UTC ( #1080890=note: print w/ replies, xml ) Need Help??


in reply to Arrays and Push

Well, for one thing,

$main::a = [0.25]; push @{main::hd}, [@main::a];

You never define an array @main::a (only an array ref $main::a), so that's going to push nothing. All the explicit packages make it a little harder to read, too.

And if you fix it to $main::a, it'll be pushing a ref to an array with one element, which element is an array ref, which isn't what you want either. You're kinda shotgunning syntax at the problem. What you probably want is something much simpler like

@hd = ( [] ); $a = [0.25] $b = [0.25, 0.5]; push @hd, $a; push @hd, $b;


Comment on Re: Arrays and Push
Select or Download Code
Re^2: Arrays and Push
by boftx (Deacon) on Apr 03, 2014 at 05:28 UTC
    And if you fix it to $main::a, it'll be pushing a ref to an array with one element, which element is an array ref, which isn't what you want either.

    Actually,that is exactly what he wants and what both you and I have described. :) The element in the array ref is in fact a value and not another array.

    $ cat pm1080886.pl #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @hd = ( [] ); my $a = [0.25]; my $b = [0.25, 0.5]; push @hd, $a; push @hd, $b; print Dumper(\@hd); exit; __END__ $ ./pm1080886.pl $VAR1 = [ [], [ '0.25' ], [ '0.25', '0.5' ] ];
    It helps to remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.

      Actually,that is exactly what he wants and what both you and I have described.

      Not exactly. Just doing that sub would leave him doing a push @hd, [$a]; construct, which would be the Wrong I described. He also needs to slay the Bracket Fairy that's sprinkling dust through the code to get the push $hd, $a; that you/we have there.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (13)
As of 2014-12-29 16:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (193 votes), past polls