On Tue, Mar 17, 2009 at 8:16 AM, Dermot <paik...@googlemail.com> wrote: > Hi All, > > I am unsure if the following statement is going to do what I want. > > I want to test if there is a value in $hash_ref{'someval'} NOT if the > key is defined. I'd also like to avoid un-sightly "undefined value" > errors.
Hi Dermot, It really depends on what the expected/legal values are. For numeric values, a simple 'if $x{x}' will normally suffice. The exception is in the case that zero is a legal value, in which case you need 'defined.' The perldoc exists for a nice rundown. If there are additional constraints, you really need at least two tests. Simply testing truth or definiedness will not tell you if the value is in range, and simply testing the value will throw an error if the element isn't defined, e.g. if ( $x{x} and $x{x} =~ /\w+/ ) {} if ( defined $x{x} and $x{x} > -4 ) {} # 0 is in range, so we need 'defined' HTH, --j -------------------------------------------------- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.downloadsquad.com http://www.engatiki.org values of β will give rise to dom! -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/