in reply to Can someone Explain 2 lines of code

$count{$_}++ for @Clec_id; print "$_ => $count{$_}\n" for keys %count;

can someone please explain

Well, I got here too late and other people had already explained. So instead, I decided to play games with it, like getting it onto one line and getting rid of the well-named variables. (Honestly, naming a variable "count" when it's perfectly obvious that it's a counting variable... if you're not careful, people will be able to read your code...) So, um, this may not be helpful or answer your question, but it was fun:

print"$_ => $}{$_}\n"for grep{!$!{$_}++}map{$}{$_}++;$_}@Clec_id;

$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/

Replies are listed 'Best First'.
Re: Re: Can someone Explain 2 lines of code
by sauoq (Abbot) on Oct 29, 2003 at 01:57 UTC

    I think the funniest thing about that is that you kept the @Clec_id variable... :-)

    -sauoq
    "My two cents aren't worth a dime.";
    
      you kept the @Clec_id variable

      There were two reasons to keep that, but the most important reason was that it was presumably given its value in earlier code, so I'd have to copy from it anyway, not having access to the rest of the code to change it. (The other reason to keep it, of course, is that there was no compelling reason to do otherwise.)


      $;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/