Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: simple hash question

by wolfi (Scribe)
on May 27, 2004 at 04:17 UTC ( [id://356802]=note: print w/replies, xml ) Need Help??


in reply to simple hash question

you're trying to match a hash again the number 1, yes? (rather than use the 1 as part of the ref).

try this...

if (%hash->{$base}->{'Initialized'} !~ /1/) {

or

if (%hash->{$base}->{'Initialized'} !~ /"1"/) {

about strict:
if i'm not mistaken, most values need to be in quotes, while strict is in place

Replies are listed 'Best First'.
Re: Re: simple hash question
by PodMaster (Abbot) on May 27, 2004 at 04:28 UTC
    use strict; my $hash = { Foo => 1 }; if( $hash->{Foo}->{EEEEEEEK} cmp "abcdefghijklmnopqrstuvwxyz" ){ } __END__ Can't use string ("1") as a HASH ref while "strict refs" in use at ... +.
    about strict: if i'm not mistaken, most values need to be in quotes, while strict is in place
    You are mistaken. If you want to know what strict is for read `perldoc strict'. If you want to know about quoting hash keys, start with `perldoc perldata'.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      i meant unquoted strings and not values, while strict was in place.

      As i reread the question, this probably wasn't necessary in this case, as it appears to be more of a mathematical - rather than string - comparison.

      my apologies...

Re: Re: simple hash question
by davido (Cardinal) on May 27, 2004 at 04:29 UTC
    If his datastructure contains a 1 (a numeric value), there's no reason to resort to using the regexp comparisons. And there's no need to wrap the 1 in quotes.

    You're barking up the wrong tree with those suggestions.

    It is perfectly legit to say:

    if ( $item != 1) {....

    And a properly accessed hash element is not an exception to this rule.


    Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://356802]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-03-19 11:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found