Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] for loop with keys from two hashes

Expand Messages
  • Shlomi Fish
    Hi Noah, On Mon, 29 Oct 2012 20:48:14 -0700 ... You can do something like (untested: my %total_keys = (%{ $sites{$hostname } }, %{ $sites{$remote_hostname} });
    Message 1 of 3 , Oct 30, 2012
    • 0 Attachment
      Hi Noah,

      On Mon, 29 Oct 2012 20:48:14 -0700
      Noah <noah-list@...> wrote:

      > Hi,
      >
      > Is there any easy way to get keys from two hashes listed a for loop?
      > like for $sites{$hostname} and for $sites{$remote_hostname} ?
      >
      > How would I do that? here is pseudo code of what I am trying to accomplish.
      >
      > for my $blah ( sort keys %{ $sites{$hostname} } && sort keys %{
      > $sites{$remote_hostname} }) {
      >

      You can do something like (untested:

      my %total_keys = (%{ $sites{$hostname } }, %{ $sites{$remote_hostname} });

      foreach my $key (sort keys %total_keys)
      {
      if (exists($sites{$hostname}{$key})
      {
      ...;
      }
      }

      For more information, see:

      http://stackoverflow.com/questions/350018/how-can-i-combine-hashes-in-perl

      Regards,

      Shlomi Fish



      > Cheers,
      > Noah



      --
      -----------------------------------------------------------------
      Shlomi Fish http://www.shlomifish.org/
      Freecell Solver - http://fc-solve.shlomifish.org/

      Mothers used to tell their children stories about XSLT to scare them.

      Please reply to list if it's a mailing list post - http://shlom.in/reply .
    • Noah
      thank you
      Message 2 of 3 , Oct 30, 2012
      • 0 Attachment
        thank you

        On 10/30/12 1:26 AM, Shlomi Fish wrote:
        > Hi Noah,
        >
        > On Mon, 29 Oct 2012 20:48:14 -0700
        > Noah <noah-list@... <mailto:noah-list%40enabled.com>> wrote:
        >
        > > Hi,
        > >
        > > Is there any easy way to get keys from two hashes listed a for loop?
        > > like for $sites{$hostname} and for $sites{$remote_hostname} ?
        > >
        > > How would I do that? here is pseudo code of what I am trying to
        > accomplish.
        > >
        > > for my $blah ( sort keys %{ $sites{$hostname} } && sort keys %{
        > > $sites{$remote_hostname} }) {
        > >
        >
        > You can do something like (untested:
        >
        > my %total_keys = (%{ $sites{$hostname } }, %{ $sites{$remote_hostname} });
        >
        > foreach my $key (sort keys %total_keys)
        > {
        > if (exists($sites{$hostname}{$key})
        > {
        > ...;
        > }
        > }
        >
        > For more information, see:
        >
        > http://stackoverflow.com/questions/350018/how-can-i-combine-hashes-in-perl
        >
        > Regards,
        >
        > Shlomi Fish
        >
        > > Cheers,
        > > Noah
        >
        > --
        > ----------------------------------------------------------
        > Shlomi Fish http://www.shlomifish.org/
        > Freecell Solver - http://fc-solve.shlomifish.org/
        >
        > Mothers used to tell their children stories about XSLT to scare them.
        >
        > Please reply to list if it's a mailing list post - http://shlom.in/reply .
        >
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.