On 2009-10-18 at 6:20 PM, b...@cruzio.com (Bruce Van Allen) wrote:

>On 2009-10-18 at 5:53 PM, b...@cruzio.com (Bruce Van Allen) wrote:
>
>>On 2009-10-18 at 5:35 PM, jlund...@pobox.com (Jonathan Lundell) wrote:
>>
>>>Bruce, how are you handling the % fortune separator?
>>
>>Not sure what you are referring to.
>
>OK, my bad for responding to something in between running my 
>own work jobs. I looked at the fortune file, so now I see the '%'.
>
>Before the start of the read loop, add the line
>
>$/ = "%\n";

Besides doing that, you'll need to deal with the punctuation 
marks at the start of some lines.

Aside from the punctuation marks, it now looks like this:

#!/usr/bin/perl -w

my %sort_buckets;
my %exclusions;

my $file_to_sort = '/path/to/file_to_sort';
my $sorted_file = '/path/to/sorted_file';

while (<DATA>) {
     chomp;
     $exclusions{$_}++;
}

open $in, "<", $file_to_sort
     or die "Can't open file: $!";

$/ = "%\n";

while (<$in>) {
     my $line = $_;
     my @words = split " " => $line;
     my $sort_key = '';
     for (0..$#words) {
         if ($exclusions{lc($words[$_])}) {
             next;
         } else {
             $sort_key = join "" => map { lc($_) } @words[$_..$#words];
             last;
         }
     }
     $sort_buckets{$sort_key} = $line;
}

close $in;

open $out, ">", $sorted_file
     or die "Can't open file: $!";

foreach (sort keys %sort_buckets) {
     print $out $sort_buckets{$_};
}

close $out;

__END__
a
the
this
that
you
when
is
may
be
if
i
have


    - Bruce

_bruce__van_allen__santa_cruz_ca_


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the 
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email "supp...@barebones.com" rather than posting to the group.
-~----------~----~----~----~------~----~------~--~---

Reply via email to