home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / perl / 6903 < prev    next >
Encoding:
Internet Message Format  |  1992-11-09  |  2.3 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!agate!doc.ic.ac.uk!uknet!mcsun!sunic!seunet!enea!sommar
  2. From: sommar@enea.se (Erland Sommarskog)
  3. Newsgroups: comp.lang.perl
  4. Subject: TMF
  5. Message-ID: <1992Nov9.130634.12712@enea.se>
  6. Date: 9 Nov 92 13:06:34 GMT
  7. Organization: Enea Data AB
  8. Lines: 39
  9.  
  10. When I read the Perl book I said too myself: hey, what a fun
  11. langauge, it's got too many features. Well, I have never advocated
  12. minimalism for its own sake, so why not?
  13.  
  14. Nevertheless here are two things which have bitten me recently,
  15. which I might be prepared to put on the list of unnecessary features.
  16.  
  17. 1) Saying &Sub2 means that Sub2 does not get its own copy of @_, which
  18.    means that if called from Sub1, Sub2 gets Sub1's @_. In the case
  19.    Sub2 takes parameters which all can be omitted, this may give un-
  20.    exepected results.
  21.      OK, there are some effeciency reasons for this arrangement, and
  22.    it could probably be functionally useful as well.
  23.      Actually, what confused me was a comment to a code example on
  24.    page 100 in the camel book, which says "pass no list at all--
  25.    more efficient". OK, I thought, one shall not put superfluous ()
  26.    in parameterless call. And, since I do not come from the C or 
  27.    Fortran camp, that was the natural thing for me to do anyway.
  28.      So, the suggestion is only that the risk with passing no list at
  29.    all should be highlighted in future editions of the Camel book.
  30.  
  31. 2) @array returns the number of elements in a scalar context, but
  32.    @array[1,2,3] or @array{'a', 'b', 'c'} returns the last element.
  33.    I haven't found it now, but I dimly recall haveing read something 
  34.    of the kind which would explain the result.
  35.      Nevertheless, admit that it's quite confusing, and can lead to
  36.    errors which are difficult find during test. I had:
  37.  
  38.       if (@result{"changed", "new", "deleted"})
  39.  
  40.    As "deleted" was empty, but the others not, I immediately got
  41.    suspicious. But had I put "changed" at the end instead, I might
  42.    not have discovered the error until much later when I thought 
  43.    the program to be working.
  44.      I would prefer if scalar on a list, no matter which one, always
  45.    return the number of elements to get consistency, but I suspect
  46.    that it would not be compatible with other people's code, so...
  47. -- 
  48. Erland Sommarskog - ENEA Data, Stockholm - sommar@enea.se
  49.