home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!dtix!darwin.sura.net!mips!sdd.hp.com!usc!news!netlabs!lwall
- From: lwall@netlabs.com (Larry Wall)
- Newsgroups: comp.lang.perl
- Subject: Re: Assoc array indirection
- Message-ID: <1992Aug17.170850.13766@netlabs.com>
- Date: 17 Aug 92 17:08:50 GMT
- References: <1992Aug17.100513.9649@nuscc.nus.sg>
- Sender: news@netlabs.com
- Organization: NetLabs, Inc.
- Lines: 40
- Nntp-Posting-Host: scalpel.netlabs.com
-
- In article <1992Aug17.100513.9649@nuscc.nus.sg> ccechk@nuscc.nus.sg (Heng Kek) writes:
- : #!/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
-
- This only works accidentally because all your host names happen to
- be identifiers, which when parsed are interpreted as unquoted strings.
-
- : Why doesn't the 1st 2 print()s do what I expect?
-
- Because you aren't interpolating a comma between the two host names.
-
- : How do I achieve my goal, given my intentions in:
- :
- : print eval "\@ipaddr{join(',', @host[0..1])}"; # no go
-
- Why do you quote the first @ and not the second? Try
-
- print eval "\@ipaddr{\@host[0..1]}";
-
- or better
-
- print eval '@ipaddr{@host[0..1]}';
-
- or even better
-
- print @ipaddr{@host[0..1]};
-
- Why do you need the eval?
-
- Larry
-