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

[MacPerl] using one array to sort another



Richard,

I'm not sure if I understand this map/sort part of Perl. My results are
coming out as follows:

1.1|||
1.1.p.1|||
1.1.1|||
1.1.2|||
1.1.3|||

from the following alexander.cgi program. Am I not reading in the file
correctly? I thought I was reading in the alexander.txt (listed at end) and
building a hash array with the numbers being the keys to the family
information being the value.

Thanks.

alan :)

###############################alexander.cgi##################################
#!/usr/local/bin/perl -w

use diagnostics ;

if(open(INFILE,"alexander.txt") || die "Cannot open alexander.txt: $!\n") {
	while (<INFILE>) {
		print("The full array is ");
		print $_;
		print "\n";
		@names = $_;
		@names = split /\|\|\|/, $_;
		%names = @names;
		while(($key, $value) = each(%names)) {
			print("<B>Key is : </B> $key and <B>Value is: </B>
$value\n");
		}
	}
}

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

print @compArray;

@final_results = map $_ . '|||' . $names->{$_} . "\n" , @compArray ;

print @final_results ;

1;

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



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