in reply to Too Much Perl?

if you did one of these lately :

Replies are listed 'Best First'.
Re^2: Too Much Perl?
by Tanktalus (Canon) on Apr 27, 2006 at 16:42 UTC

    Oh, come on now. That would never work. If $red was true, you'd get all your tshirts, regardless of colour, while, if false, you'd be overdressed at the beach.

    What I think you meant was: grep { $_->{colour} eq 'red' } @tshirts or, if you're an OO type of guy, grep { $_->colour() eq 'red' } @tshirts.

    However, even that can get a bit messy. I mean, some of us have two, three, or even more, red shirts. Putting them all on at once would look silly, even for a computer geek. (Though, if you're in a workplace filled with perl geeks, you could do that one day - show up wearing all your red shirts, and if anyone asks why you're wearing so many shirts, just tell 'em that you did a grep { $_->has_colour('red') } @tshirts on your closet that morning...). Instead, what you really want is either use List::Utils qw/first/; first { $_->colour() eq 'red' } @tshirts or possibly my @reds = grep { $_->colour() eq 'red' }; $reds[rand @reds] depending on whether you want to be efficient or you prefer some variety.

    Me? Too much perl? Nah ...

      "Never"? This is Perl!

      { package Tie::ColorTest; sub TIESCALAR { my( $pkg, $color ) = @_; bless \$color, $pkg } sub FETCH { my $self = shift; $_->{'color'} eq $$self } } tie my $red, 'Tie::ColorTest' => 'red';
      We're building the house of the future together.

        Oh, a red tie. Does it have flashing lights and play a tune?


        DWIM is Perl's answer to Gödel
      If you're going to be pedantic, you would have noticed that neither of those statements actually do anything.

      sort and grep are called in void context; it's just frantic early morning thrashing around, before the brain kicks in.

      Presumably, the code later on will end up with the user dressed. Or not, depending on the sort of day it's been.

        I usually thrash about in the morning amongst the $black shirts, actually. Also, the $nerd shirts (my Perl Camel shirt, my Perl obfu shirt, my "talk nerdy to me" shirt, my MC Escher shirts, and so on).

        I'm not sure I actually have any $red shirts. Thank goodness: I don't want to be the one guy that never returns from the away team.

        print substr("Just another Perl hacker", 0, -2);
        - apotheon
        CopyWrite Chad Perrin