in reply to <=> - not only for sort anymore

Great idea (idiom, actually)!
But, errr, here's a "no-setup" solution of your combined grep and index problem:
print( ("|","*"," ")[ $seen && 2 || ($seen = $_ eq $pos) ], " $_\n" ) +for @list;


p

Replies are listed 'Best First'.
Re: Re: = - not only for sort anymore
by jrifkin (Initiate) on Apr 18, 2001 at 21:47 UTC
    Nice use of <=>, but I think this might do the same thing even easier

        for $i (0..5) { print substr("|||||*",5-$i,5), "\n" }
      Oops, sorry. We were talking about names, not numbers. So how about this

         $seen=0;
         for $i (@list) { last if $i eq $pos; $seen++ }
         print substr("|||||*     ", 5-$seen, 5), "  $pos\n";