home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / perl / 5349 < prev    next >
Encoding:
Internet Message Format  |  1992-08-17  |  1.3 KB

  1. Path: sparky!uunet!dtix!darwin.sura.net!jvnc.net!nuscc!ccechk
  2. From: ccechk@nuscc.nus.sg (Heng Kek)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: Assoc array indirection
  5. Message-ID: <1992Aug18.020219.28827@nuscc.nus.sg>
  6. Date: 18 Aug 92 02:02:19 GMT
  7. References: <1992Aug17.170850.13766@netlabs.com>
  8. Organization: National University of Singapore
  9. Lines: 32
  10.  
  11. lwall@netlabs.com (Larry Wall) writes:
  12. : In article <1992Aug17.100513.9649@nuscc.nus.sg> ccechk@nuscc.nus.sg (Heng Kek) writes:
  13. ...[stuff deleted]...
  14. : : print eval "\@ipaddr{@host[0..1]}";              # no go
  15. : : print eval "\@ipaddr{join(',', @host[0..1])}";  # no go
  16. : : print eval "\@ipaddr{$host[0], $host[1]}";      # okay
  17. ...[stuff deleted]...
  18. : Why do you need the eval?
  19.  
  20. I guess I (the original poster) didn't post a very good example for
  21. what I was trying to find out, in my hurried quest for a quick answer.
  22. Here's a better illustration as to why I needed the 'eval':
  23.  
  24. #!/usr/bin/perl
  25. @host   = ('nusunix1', 'nusunix2', 'nusunix3');
  26.  
  27. $nusunix1{'john'} = '555/666/k ';
  28. $nusunix1{'mary'} = '666/777/l ';
  29. $nusunix1{'pete'} = '888/999/m ';
  30.  
  31. @names = ('john', 'mary', 'pete');
  32.  
  33. print eval "\@$host[0]{\@names[0..2]}";  # okay.
  34. print "\n";
  35. #print eval "\@$host[0]{@names[0..2]}";  # This doesn't work.
  36.  
  37. The above works, thanks to all your responses.
  38.  
  39.  
  40. Sincerely
  41. Heng Kek
  42. National Univ of S'pore
  43.