Friday, June 29, 2007

ooooooooooohhhhh.....

WRONG        for my $key ( keys %hash_of_hashes->{$hash}){
WRONG        for my $key ( keys %hash_of_hashes{$hash}){
WRONG        for my $key ( keys {%hash_of_hashes{$hash}}){
WRONG        for my $key ( keys (%hash_of_hashes{$hash}){
WRONG        for my $key ( keys $hash_of_hashes{$hash}){

RIGHT!         for my $key ( keys %{$hash_of_hashes{$hash}}){

Aaaaahhhh..... I see what you did there...

I like that with perl, I have the flexibility to find correct syntax by simply trying out what makes sense. When I do have to actually look something up the answer was usually pretty close to my guesses.

4 comments:

blogagog said...

*cry*
*sigh*
*moan*

You have bought into the bigscript mentality of saying 'my' before a $variable.

It's like I'm watching the destruction of c all over. No, I'll not go quickly into that night. I'll rage, RAGE against the existing thing.

Fletch said...

I just like it because it lets me reuse simple variable names when in subroutines or loops. Kind of got in the habit of using it where I didn't have to.

Also, use strict keeps me from getting sloppy, and it bitches if I don't "my" my variables.

blogagog said...

Yeah, that's what the nazis said!

"Verkunft ein 'my' er variable ein gesacht!"

was their exact phrasing, if I'm not mistaken.

UPDATE: Ok, I admit it. I've no idea what those German words mean. But I will say that using 'my' in a perl script is tantamount to writing in c++!

Why not write an object, hippie!

(just kidding on the last comment)

Fletch said...

It's funny that I was more offended by the object comment than the hippie comment!

I completely get what you're saying, but this is (rough) production code, and if I require a function or even a *gasp* object, I'll have to bite my tongue and use it... Lest some perlmonger greater than I view my source (in an official capacity) and loudly proclaim "This guy doesn't know shit! Why are we using the code this company has provided!?" :x