Re: Sort Multidimensional Array by Column 5
Re: Sort Multidimensional Array by Column 5
- Subject: Re: Sort Multidimensional Array by Column 5
- From: Doug McNutt <email@hidden>
- Date: Wed, 6 Oct 2010 16:59:39 -0600
I can't resist it. But I didn't obfuscate by making it smaller.
.= is a concatenation operator that adds text to the end of a string.
#!/usr/bin/perl
open IN, "/Volumes/HEAO/CSVdata" or die "Can't open source file\n";
$/ = "\r"; # Line end is a return on my old Mac, Leave out if it's a newline.
while ($aline = <IN>)
{
chomp $aline;
last if (length($aline) < 10);
@array = split /","/, $aline;
$key = $array[4];
# print "$key\n";
$ahash{$key} = $aline;
}
@sort = sort keys(%ahash);
# foreach $x (@sort) { print "\$x = $x\n"; }
$output = "set formData to {";
$acomma = "";
foreach $x (@sort)
{
$bcomma = "";
$output .= "$acomma";
$output .= "{";
@brray = split /,/, $ahash{$x}; # Fails with comma in the data.
while (@brray)
{
$item = shift @brray;
$output .= $bcomma;
$output .= $item;
$bcomma = ", ";
}
$output .= "}";
$acomma = ", ";
}
$output .= "}\n";
print $output;
__END__
--
--> Halloween == Oct 31 == Dec 25 == Christmas <--
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden