Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Pushing Arrays into Hash without nesting

by tybalt89 (Monsignor)
on Feb 13, 2021 at 19:28 UTC ( [id://11128344]=note: print w/replies, xml ) Need Help??


in reply to Pushing Arrays into Hash without nesting

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %hash; my %source; my @array = (10 .. 12); $source{'data'} = \@array; print "\n".'%source'." - from main\n". Dumper %source; push (@ { $hash{"foo"}{"bar"} } , addSomeNumbers(1,3) ); print "\n".'%hash'." - from main\n". Dumper %hash; push (@ { $hash{"foo"}{"bar"} } , addSomeNumbers(4,6) ); print "\n".'%hash'." - from main\n". Dumper %hash; push (@ { $hash{"foo"}{"bar"} } , addSomeNumbersVia2ndSub(7,9) ); print "\n".'%hash'." - from main\n". Dumper %hash; push (@ { $hash{"foo"}{"bar"} } , @{ (addSomeNumbersFromSource("data") +)[0] } ); print "\n".'%hash'." - from main\n". Dumper %hash; sub addSomeNumbers{ my ($start, $end) = @_; my @array = ($start .. $end); print "\n".'@array'." - from addSomeNumbers\n". Dumper @array; return @array; } sub addSomeNumbersVia2ndSub{ my ($start, $end) = @_; my @array = addSomeNumbers($start, $end); print "\n".'@array'." - from addSomeNumbersVia2ndSub\n". Dumper @a +rray; return @array; } sub addSomeNumbersFromSource{ my ($data) = @_; my @array = $source{$data} ; return @array; }

Log In?
Username:
Password:

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

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

    No recent polls found