1
$self->doSomething({
    record     => $record,
    listing    => [ $foo, $bar, $baz ],
    passedargs => { something => $val, another => $val2 }
});

accessing args within a hashref.

So if I wanted to access record I would

my $record = $args->{record};

If I wanted to access listing I would

my @listing = $args->{listing}; 

How would I access Passedargs? If I just wanted to access "something" or "another"?

Miller
  • 34,344
  • 4
  • 33
  • 55

2 Answers2

3

If you want assign the values in listing to an array, please note that you'll need to dereference it:

my @listing = @{ $args->{listing} };

To access the fields in passedargs, you simply need to use the following syntax:

my $something = $args->{passedargs}{something};

For more details, take a look at: perldsc - Perl Data Structures Cookbook

Miller
  • 34,344
  • 4
  • 33
  • 55
  • 5
    Re "If you want assign the values in listing to an array", you probably want the wrong thing :) Usually, `my $listing = $args->{listing};` is far more appropriate. – ikegami Sep 15 '14 at 19:05
1

$args->{passedargs} is a hashref itself, so you would do:

my $something = $args->{passedargs}->{something};
Andy Lester
  • 81,480
  • 12
  • 93
  • 144