Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!asuvax!ncar!elroy.jpl.nasa.gov!swrinde!zaphod.mps.ohio-state.edu!think.com!mintaka!spdcc!dirtydog.ima.isc.com!ispd-newsserver!cronkite!cronkite.Atex.Kodak.COM!lawrence From: lawrence@APS.Atex.Kodak.COM (Scott Lawrence) Newsgroups: comp.lang.perl Subject: Re: A question on associative arrays Message-ID: Date: 31 May 91 16:30:43 GMT References: <1991May30.205555.14490@convex.com> <1991May31.011755.4305@eng.umd.edu> Sender: news@APS.Atex.Kodak.COM Organization: Advanced Publishing Systems, Atex Inc. A Kodak company Lines: 59 In-Reply-To: ziegast@eng.umd.edu's message of 31 May 91 01: 17:55 GMT In article <1991May31.011755.4305@eng.umd.edu> ziegast@eng.umd.edu (Eric W. Ziegast) writes: Eric> I gave it a few tests of wort-case scenarios... Eric> 1. Null assignment (an assignment nonetheless) Eric> $assoc{''}=''; Eric> print %assoc ? "true" : "false"; Eric> Results in true. Eric> 2. Defining the assoc as a local Eric> sub foo { Eric> local(%assoc); Eric> print %assoc ? "true" : "false"; Eric> } Eric> &foo Eric> Results in false. Eric> 3. A new dbm file Eric> dbmopen(%assoc,"newdbmfile",0600); Eric> print %assoc ? "true" : "false"; Eric> Results in false. Eric> I performed these tests with Perl 3.0 (41) on a SunOS 4.1 system. Eric> I believe ndbm was compiled into our perl. Just FYI. Eric> Eric Ziegast I got the same results with 4.03 on SunOS 4.1, and was prompted to check on the behaviour of `defined' in those same cases. The interesting one turned out to be case 2, in which local( %assoc2 ) does not cause defined( %assoc2 ) to return true. =========== $assoc1{''}=''; print "Case 1 ", ( defined( %assoc1 )? "defined" : "undefined" ), "\n"; Case 1 defined <<<<<< makes sense ====== sub case2 { local( %assoc2 ); print "Case 2 ", (defined(%assoc2)? "defined" : "undefined" ), "\n"; } &case2; Case 2 undefined ====== dbmopen( %assoc3, "/tmp/testdbmfile", 0777); print "Case 3 ", (defined(%assoc3)? "defined" : "undefined" ), "\n"; Case 3 defined ====== -- Scott Lawrence Voice: {US} 508-670-4023 Atex Advanced Publishing Systems G3Fax: {US} 508-670-4033 Atex, Inc; 165 Lexington St. MS 400/165L; Billerica MA 01821