home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!srvr1.engin.umich.edu!uvaarpa!mmdf
- From: Alan Stebbens <aks%anywhere@hub.ucsb.edu>
- Subject: Re: lists in associative arrays
- Message-ID: <1993Jan21.173318.4445@uvaarpa.Virginia.EDU>
- Sender: mmdf@uvaarpa.Virginia.EDU (Mail System)
- Reply-To: aks%anywhere@hub.ucsb.edu
- Organization: The Internet
- Date: Thu, 21 Jan 1993 17:33:18 GMT
- Lines: 52
-
- | From: danq@spot.Colorado.EDU (Daniel Quinlan)
- | ...I think there must be some better way to do this
- | than ...
- | $list{$i} = "$list{$i} new_entry" ;
-
- | From: Tom Christiansen <tchrist@convex.COM>
- | The ".=" operator would be a bit more efficient, I suspect.
-
- The way I build lists is:
-
- $list .= $new.' ';
-
- Then, when you're done, I either use
-
- @items = split(' ',$list);
-
- to ignore the trailing blanks when separating items, or to simply remove
- the trailing blank:
-
- chop($list);
-
- If you are building an array of accumulating lists:
-
- while (<>) {
- ...
- $list[$index] .= $new.' ';
- ...
- }
-
- You choose to either ignore the trailing blanks, or chop them:
-
- grep(chop,@list);
-
-
- If you are building a associative array of accumulating lists:
-
- while (<>) {
- ...
- $list{$entry} .= $new.' ';
- ...
- }
-
- Simiarly, you can ignore the trailing blanks, chop them, or use split
- (as Tom pointed out above) to ignore them.
-
- foreach $ent (keys %list) {
- chop($list{$ent});
- }
-
- -- Alan Stebbens, UCSB, Santa Barbara <aks@hub.ucsb.edu>
- "If all you have is a hammer, then everything looks like a nail."
-
-