• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Sort Multidimensional Array by Column 5
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Sort Multidimensional Array by Column 5 (From: Richard Lake <email@hidden>)
 >Re: Sort Multidimensional Array by Column 5 (From: Jon Pugh <email@hidden>)
 >Re: Sort Multidimensional Array by Column 5 (From: Richard Lake <email@hidden>)
 >Re: Sort Multidimensional Array by Column 5 (From: KOENIG Yvan <email@hidden>)

  • Prev by Date: Re: Sort Multidimensional Array by Column 5
  • Next by Date: Re: Sort Multidimensional Array by Column 5
  • Previous by thread: Re: Sort Multidimensional Array by Column 5
  • Next by thread: Re: Sort Multidimensional Array by Column 5
  • Index(es):
    • Date
    • Thread