Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Trying to access array within hash

by BillKSmith (Vicar)
on Jun 04, 2013 at 12:37 UTC ( #1036965=note: print w/replies, xml ) Need Help??


in reply to Trying to access array within hash

You can further simplify ig's solution with values instead of keys in the foreach and with interpolation in the print.
foreach my $policy (values %policies) { my $polMembers = $policy->[ (lc($targetRole) eq "source") ? 2 +: 4 ]; local $" = "\n"; print "@$polMembers\n"; }
Bill

Replies are listed 'Best First'.
Re^2: Trying to access array within hash
by clegane (Novice) on Jun 04, 2013 at 13:47 UTC

    Thanks a bunch everyone. I got it working with Bill's solution. The reason I was copying the array is because the syntax was getting ugly, and I wasn't sure how to get things working. In Bill's solution, what does this line do exactly?

    local $" = "\n";
      see $" in perlvar

      $LIST_SEPARATOR $" This is like $, except that it applies to array and sli +ce values interpolated into a double-quoted string (or sim +ilar interpreted string). Default is a space. (Mnemonic: o +bvious, I think.)

      Are you the Hound or the Mountain? ;-)

      Cheers Rolf

      ( addicted to the Perl Programming Language)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1036965]
help
Chatterbox?
[Discipulus]: and it's GPIO how are seen by the OS? Perl can speak thougth them?
[marto]: yes
[Discipulus]: thanks i definetively must learn such stuff.. i must come out with a killing product and after i'll just do Perl elctronic and music.. ;=)

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2017-10-17 09:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (225 votes). Check out past polls.

    Notices?