[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] using one array to sort another




6/29/99, alan wrote:
  > Richard,
  > I'm not sure if I understand this map/sort part of Perl.
  > My results are coming out as follows...
  > 1.1.3|||

Alan,

Try this...

-rkm

============================================================================
#!/usr/bin/perl -w
use diagnostics ;
use strict ;

my @CompArray =
	( '1' , '1.1' , '1.1.p.1' , '1.1.1' , '1.1.2' , '1.1.3' ) ;

my $Names = {} ;

open INFILE, "alexander.txt"
	or die "Cannot open alexander.txt: $!\n" ;

while ( <INFILE> )
{
	chomp;
	my ( $Key, $Value ) = split /\|\|\|/ ;
	$Names->{$Key} = $Value ;
} ;

my @Results = map $_ . '|||' . $Names->{$_} . "\n" , @CompArray ;

print @Results ;


## Prints:
##
## 1|||Bob||blank||Alexander||Address1||Address2
## 1.1|||Nathan||Robert||Alexander||Address1||Address2
## 1.1.p.1|||Anita||Sue||Alexander||Address1||Address2
## 1.1.1|||Grace||Robert||Alexander||Address1||Address2
## 1.1.2|||Joe||blank||Alexander||Address1||Address2
## 1.1.3|||Claudia||Bernice||Alexander||Address1||Address2
============================================================================

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org