Re: Too Much Perl?
by wazoox (Prior) on Apr 27, 2006 at 11:16 UTC
|
| [reply] [d/l] [select] |
|
|
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 ...
| [reply] [d/l] [select] |
|
|
{
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.
| [reply] [d/l] |
|
|
|
|
|
|
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.
| [reply] |
|
|
Re: Too Much Perl?
by TedYoung (Deacon) on Apr 27, 2006 at 14:10 UTC
|
If you look at the following code and immediately understand it, then you have been spending way too much time with Perl. I suggest you take a few doses of Java. :-)
perl -p -e '$\+=$_}{'
Ted Young
($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)
| [reply] [d/l] [select] |
|
|
I guess I'm in the clear, then. I understood what the code did before reading your explanation, but not "immediately", so I should be safe to spend more time with Perl. Whew. What a relief.
It was the numerical context that hung me up for a few seconds. I kept wondering what good a += operator was to $\ since, like a good little code monkey, I would (almost) never want to add numbers to it from a file for no purpose other than printing them out, and would thus not have fed it numerical input, which didn't make sense to me. Silly me, I was thinking "useful code", not "mild obfu".
| print substr("Just another Perl hacker", 0, -2); |
|
- apotheon
CopyWrite Chad Perrin |
| [reply] |
Re: Too Much Perl?
by GrandFather (Saint) on Apr 27, 2006 at 18:18 UTC
|
I find myself wanting to write return if ... in C++ fairly often these days. Is that a symptom?
Not Perl, but PerlMonks OD leads me to look for the ++ and -- buttons on other web sites, or sometimes even emails! The fact that other (non-programmer) members of the household have come to use ++ from time to time may be another indication.
DWIM is Perl's answer to Gödel
| [reply] [d/l] |
|
|
Oh, yeah, I do that all the time — think about how to apply ++ and -- operators, or += (though never -= oddly enough), in all kinds of non-Perl contexts. Another one: I often want to use a while loop and regex (or, alternatively, the little Find box in Firefox) to find something I just read a few pages ago when I'm reading a book.
| print substr("Just another Perl hacker", 0, -2); |
|
- apotheon
CopyWrite Chad Perrin |
| [reply] |
Re: Too Much Perl?
by bluto (Curate) on Apr 27, 2006 at 16:47 UTC
|
This is like asking fellow asylum patients whether your sanity has failed. What further symptoms do you need to see?:-)
| [reply] |
|
|
Good point. Maybe I should ask my non-PerlMonk friends.
Then again, my non-PerlMonk friends would probably consider any amount of use of Perl (by choice) to be insane, so I'm not sure they're a very good source of judgment either. Er. Unless that just indicates something profound about the use of Perl and its relation to insanity, of course.
| print substr("Just another Perl hacker", 0, -2); |
|
- apotheon
CopyWrite Chad Perrin |
| [reply] |
Re: Too Much Perl?
by Happy-the-monk (Canon) on Apr 27, 2006 at 14:26 UTC
|
Seems all very sensible to me, apotheon, no reason to worry, do carry on!
Perl certainly is not like a drug you could ever get too much of =)
Cheerio, Sören
| [reply] |