home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / perl / 5343 < prev    next >
Encoding:
Text File  |  1992-08-17  |  1.3 KB  |  51 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!mcsun!sunic!corax.udac.uu.se!irfu.se!jhd
  3. From: jhd@irfu.se (Jan D.)
  4. Subject: Re: Assoc array indirection
  5. Message-ID: <1992Aug17.154518.7147@irfu.se>
  6. Date: Mon, 17 Aug 1992 15:45:18 GMT
  7. References: <1992Aug17.100513.9649@nuscc.nus.sg>
  8. Organization: Swedish Institute of Space Physics, Uppsala, Sweden
  9. Lines: 40
  10.  
  11. In article <1992Aug17.100513.9649@nuscc.nus.sg> ccechk@nuscc.nus.sg (Heng Kek) writes:
  12. >Greetings
  13. >
  14. >#!/usr/bin/perl
  15. >  %ipaddr = ('nusunix1','137.132.73.11',
  16. >             'nusunix2','137.132.10.11',
  17. >             'nusunix3','137.132.91.12'
  18. >            );
  19. >  @host   = ('nusunix1',
  20. >             'nusunix2',
  21. >             'nusunix3'
  22. >            );
  23. >print eval "\@ipaddr{@host[0..1]}";              # no go
  24. >print eval "\@ipaddr{join(',', @host[0..1])}";  # no go
  25. >print eval "\@ipaddr{$host[0], $host[1]}";      # okay
  26. >
  27. >Why doesn't the 1st 2 print()s do what I expect?  How do I achieve
  28. >my goal, given my intentions in:
  29. >
  30. >print eval "\@ipaddr{join(',', @host[0..1])}";  # no go
  31. >?
  32. >
  33. >Or is it just wishful thinking?
  34. >Hope someone can help.  Thanks
  35.  
  36. I'm not sure I understand your goal, but if it is comma separated
  37. ip numbers you wan't, this works:
  38.  
  39. print join(',', @ipaddr{@host[0..1]});
  40.  
  41. You can get the first print to work by simply removing the eval:
  42.  
  43. print @ipaddr{@host[0..1]};
  44.  
  45. >
  46. >Heng Kek
  47.  
  48.     Jan D.
  49.  
  50.  
  51.