• 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: Sorting? [sorted]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sorting? [sorted]


  • Subject: Re: Sorting? [sorted]
  • From: John Delacour <email@hidden>
  • Date: Sat, 14 Sep 2002 01:04:06 +0100

At 10:43 pm +0100 13/9/02, has wrote:

Clever? Certainly. Elegant? Maybe. Easy to grok? Not particularly. Easy to
generalise to handle different string arrangements? Not until you've
grokked it, and maybe not even then. (I don't know because I didn't fully
grok it.) JD's a smart guy and all, but I didn't think a solution that's
harder to understand than the alternatives was entirely to the OP's
benefit. [3]


Well here's the same routine with self-explanatory variables and in a form that ought to be 'grokable' by anyone with no experience at all of perl. In such a form it is necessarily more verbose than it needs to be, but it would be difficult to add any more verbosity to it and make it any clearer. It is certainly far easier to understand than any of the AppleScript solutions proposed, including my own, and has the added advantages of speed and unyawnfulness.

To dismiss the immeasurable superiority of perl over AppleScript for any work involved with text and files (not to speak of most other things) is rather like belonging to the Flat Earth Society and now that Apple have finally given us an operating system to shout about which has perl at it's heart, it seems odd not to take advantage of it. In fact, it seems odd not to take advantage of the wonderful MacPerl on older operating systems too.


set s to "page1_box0
page1_box1
page1_box10
page1_box11
page1_box12
page1_box13
page1_box14
page1_box15
page1_box16
page1_box17
page1_box18
page1_box19
page1_box2
page1_box20
page1_box21
page1_box22"
do shell script "perl -e '
($string, $return) = (qq~" & s & "~, $/);
@original_list = split/$return/, $string ;
foreach $line ( @original_list ) { $_ = $line;
/ (.+?) ([0-9]+$) /x ;
($namebit, $numberbit ) = ( $1, $2 ) ;
$number_with_zeros = sprintf qq~d~ , $numberbit ;
push @templist, qq~$namebit$number_with_zeros~ }
@sorted_list = sort @templist ;
foreach $name ( @sorted_list ) {
$name =~ s ~ (0+) ([0-9]+) ~$2~x ;
print qq~$name$return~ }'"


-- JD
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Sorting? [sorted] (From: has <email@hidden>)

  • Prev by Date: Re: Display dialog frontmost?
  • Next by Date: Re: Error resolving references
  • Previous by thread: Re: Sorting? [sorted]
  • Next by thread: Re: Sorting? [sorted]
  • Index(es):
    • Date
    • Thread