in reply to Common elements of a hash of hashes

Sorry but some syntaxic piece of code are really obscur. i am not as comfortable as you with perl. do you mind giving me a short explanation on the elements hereunder?
sub perl_mouse { my %HoH = %{+shift}; # I know @_ to get the parameter but not this + one } $saw{lc,} # what is lc,? grep { $count!=$count{$_} } map { ++$count{$_};$_ } map { keys %{$HoH{ +$_}} } keys %HoH # the result of this line is stored in which variable?
thanks

Replies are listed 'Best First'.
Re^2: Common elements of a hash of hashes
by Hue-Bond (Priest) on Oct 07, 2005 at 19:06 UTC
    my %HoH = %{+shift};

    Did I miss something? I don't see the word "shift" in the entire thread. Anyway, that takes the first parameter, dereferences it as a hashref and assigns the resulting hash to %HoH. The plus sign is needed for preventing Perl to take $shift as a reference and instead use the shift function. shift without arguments operates on @_ (UPDATE: or @ARGV depending on the scope).

    lc is "lowercase". I'm not sure about the comma.

    grep { $count!=$count{$_} } map { ++$count{$_};$_ } map { keys %{$HoH{$_}} } keys %HoH
    the result of this line is stored in which variable?

    That returns a list but, since it's surrounded with [ and ], the for loop gets a reference to that list. It's not stored anywhere. It's visible inside the loop as $_.

    I see it the other way around, that is, s/obscure/brilliant/.

    --
    David Serrano

      lc is "lowercase". I'm not sure about the comma.
      It's there because of this:
      $ cat foo.pl my %a; $_='fOo'; $a{lc}++; $a{lc()}++; $a{+lc}++; $a{lc,}++; $ perl -MO=Deparse foo.pl my %a; $_ = 'fOo'; ++$a{'lc'}; ++$a{lc $_}; ++$a{lc $_}; ++$a{lc $_}; foo.pl syntax OK
      So it's there for disambiguating too, just as +shift. I chose the latter form because in this context (involving the ++ operator) it seemed to me to be the least obtrusive and visually distracting.
Re^2: Common elements of a hash of hashes
by blazar (Canon) on Oct 09, 2005 at 09:15 UTC
    Sorry but some syntaxic piece of code are really obscur. i am not as comfortable as you with perl. do you mind giving me a short explanation on the elements hereunder?
    sub perl_mouse { my %HoH = %{+shift}; # I know @_ to get the parameter but not this + one } $saw{lc,} # what is lc,?
    As a general rule if you see a bareword like those, chances are that they may be built in functions. So, always as a general rule, you'll find that perl ('s excellent documentation) may already give you an answer; just check e.g. (in this case): But since there's a subtle issue involved here, please read also the following replies, including mine to Hue-Bond's.
      Thanks for your accurate explanation. I knew the functions shift and lc. In fact, the tricky points were the comma and the plus.

      I have the habit to read the documentation but I don't see very often this kind of syntax in it. to imagine how works the array reference of a grep followed by 2 map in a loop is not easy for everybody I guess.

      but thank to the monks, everybody can learn.

      I see it the other way around, that is, s/obscure/brilliant/.
      I would say s/obscure/brilliant_but_obuscure/ ;