Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re^2: Hash checking

by shigetsu (Hermit)
on Apr 25, 2007 at 19:38 UTC ( #612082=note: print w/replies, xml ) Need Help??

in reply to Re: Hash checking
in thread Hash checking

After that, I think it should work.

I disagree (I may be wrong). Consider exists:

Given an expression that specifies a hash element or array element, returns true if the specified element in the hash or array has ever been initialized, even if the corresponding value is undefined.

Replies are listed 'Best First'.
Re^3: Hash checking
by kyle (Abbot) on Apr 25, 2007 at 21:01 UTC

    I think maybe we're misunderstanding each other somehow. I think the reason the OP's search loop is not finding anything in the array is because each of the array keys has an extraneous newline at the end. Take that off (with chomp), and it should be fine.

    use Test::More 'tests' => 4; my $line; my %faclist; $line = "17\n"; $faclist{$line} = ""; $line = "23\n"; chomp $line; $faclist{$line} = ""; ok( ! exists $faclist{17}, 'number 17 does not exist' ); ok( ! exists $faclist{'17'}, 'string 17 does not exist' ); ok( exists $faclist{23}, 'number 23 exists' ); ok( exists $faclist{'23'}, 'string 23 exists' );

      I think maybe we're misunderstanding each other somehow.

      Yes, indeed we did. I'm inclined to say I misunderstood the intent that the Anonymous Monk was trying to put in effect.

      To elaborate a bit: I thought he wanted to clear the hash element and have exists yield failure when applied to the peculiar hash element; thus all the explanatory fuss.

      You did otherwise and were obviously right according to his follow-ups.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (1)
As of 2023-09-28 01:33 GMT
Find Nodes?
    Voting Booth?

    No recent polls found