home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!mcsun!sunic!corax.udac.uu.se!irfu.se!jhd
- From: jhd@irfu.se (Jan D.)
- Subject: Re: Assoc array indirection
- Message-ID: <1992Aug17.154518.7147@irfu.se>
- Date: Mon, 17 Aug 1992 15:45:18 GMT
- References: <1992Aug17.100513.9649@nuscc.nus.sg>
- Organization: Swedish Institute of Space Physics, Uppsala, Sweden
- Lines: 40
-
- In article <1992Aug17.100513.9649@nuscc.nus.sg> ccechk@nuscc.nus.sg (Heng Kek) writes:
- >Greetings
- >
- >#!/usr/bin/perl
- > %ipaddr = ('nusunix1','137.132.73.11',
- > 'nusunix2','137.132.10.11',
- > 'nusunix3','137.132.91.12'
- > );
- > @host = ('nusunix1',
- > 'nusunix2',
- > 'nusunix3'
- > );
- >print eval "\@ipaddr{@host[0..1]}"; # no go
- >print eval "\@ipaddr{join(',', @host[0..1])}"; # no go
- >print eval "\@ipaddr{$host[0], $host[1]}"; # okay
- >
- >Why doesn't the 1st 2 print()s do what I expect? How do I achieve
- >my goal, given my intentions in:
- >
- >print eval "\@ipaddr{join(',', @host[0..1])}"; # no go
- >?
- >
- >Or is it just wishful thinking?
- >Hope someone can help. Thanks
-
- I'm not sure I understand your goal, but if it is comma separated
- ip numbers you wan't, this works:
-
- print join(',', @ipaddr{@host[0..1]});
-
- You can get the first print to work by simply removing the eval:
-
- print @ipaddr{@host[0..1]};
-
- >
- >Heng Kek
-
- Jan D.
-
-
-