Shlomi Fish wrote:

On Mon, 04 Jun 2012 14:19:27 -0700
"John W. Krahn"<jwkr...@shaw.ca>  wrote:

Chris Stinemetz wrote:
I have a subroutine that I want to "return 1" only if the value of
%{$href->{$_[0]}} is equal to 'ND' for the whole 24 occurences.

One way to do it:

sub site_offAir {
      return values %{ $href->{ $_[ 0 ] } } == grep( $_ eq 'ND', values
%{ $href->{ $_[ 0 ] } } ) ? 1 : '';
      }


I see several problems with your code:

You are entitled to your opinion.

1. It's quite hard to understand the logic of it.

No it isn't.  (IMHO)

2. It won't stop when it encounter the first "ND" value.

That is true.  And your point?

3. You have the values % { $href->{ $_[0] } } gob twice (a duplicate
expression).

Yes.  And...

4. You've used $_[0] which is a positional parameter,

So?

see:
http://perl-begin.org/tutorials/bad-elements/#subroutine-arguments

Your argument on your web page does not appear to apply to this situation.

5. The grep does not uses braces for its predicate/block which is harder to
read.

In your opinion.  I prefer to not use braces unless I have to.

6. You will return a true value (a list of length 1) when the function is
called in list context.

Yes, just as the OP's code.



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to