home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / perl / 7427 < prev    next >
Encoding:
Text File  |  1992-12-14  |  1.5 KB  |  57 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!munnari.oz.au!metro!usage!news
  3. From: cameron@cs.unsw.oz.au
  4. Subject: tell me this is a feature ...
  5. Message-ID: <cameron-921215144455-1-12966@fuligin>
  6. Sender: news@usage.csd.unsw.OZ.AU
  7. Nntp-Posting-Host: fuligin.spectrum.cs.unsw.oz.au
  8. Reply-To: cameron@cs.unsw.oz.au
  9. Organization: CS&E Computing Facility, Uni Of NSW, Oz
  10. Errors-To: cameron@cs.unsw.oz.au
  11. Date: Tue, 15 Dec 1992 03:45:15 GMT
  12. Return-Receipt-To: cameron@cs.unsw.oz.au
  13. Lines: 42
  14.  
  15. For the record, this is using perl-4.034.
  16.  
  17. Intending to check out a particular semantic of Perl I wrote the following
  18. (broken) script, which uncovered another semantic I had never encountered.
  19.  
  20.     $hdrs{'foo'}='fooval';
  21.  
  22.     { local(%hdrs);
  23.  
  24.       $hdrs{'foo'}='subfooval';
  25.  
  26.       print "foo=$hdrs{'fooval'}\n";
  27.  
  28.       undef $hdrs{'foo'};
  29.  
  30.       print "foo=$hdrs{'fooval'}\n";
  31.  
  32.       undef %hdrs;
  33.  
  34.       print "foo=$hdrs{'fooval'}\n";
  35.     }
  36.  
  37.     print "foo=$hdrs{'fooval'}\n";
  38.  
  39. What I was intending was to check that the original %hdrs got restored outside
  40. the block but the script doesn't check that because I mistyped the key in the
  41. print statements. I was, however, surprised by what the script did do, which
  42. was this:
  43.     foo=
  44.     foo=
  45.     foo={'fooval'}
  46.     foo=
  47.  
  48. Notice the third line. This suggests that when resolving
  49.     $thing{index}
  50. inside double quotes perl looks for %thing being defined before snarfing the
  51. curly portion. Weird, eh?
  52.     - Cameron Simpson
  53.       cameron@cs.unsw.oz.au, DoD 0743
  54. --
  55. "The engine purrs beneath me with a purpose,
  56.  ready for the pleasure of my hand upon the throttle." - Peter Smith
  57.