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

Re: [MacPerl] Parsing Script



I wrote:
>
>     {
>         local($^W) = 0;
> #       *sort1 = $sort1{($$opts{R} . $$opts{N})};
> #       *sort2 = $sort2{($$opts{R} . $$opts{N})};
>         *sort1 = sub { ... } #some sort routine with $a and $b
>         *sort2 = sub { ... } #some sort routine with $fh{$a} and $fh{$b}
>     }
>
> At some point I think I will make *File::Sort::sort1 and sort2
> assignable from outside the package, but it is tricky to do because of
> %fh, $a, and $b.  But it should be no problem just temporarily hacking
> the module itself.

Playing around:

#!perl -w
@x = (
"abba\tbaby\tcoat\tduck\n",
"baby\tcoat\tduck\tabba\n",
"coat\tduck\tabba\tbaby\n",
"duck\tabba\tbaby\tcoat\n",
);

$del = '\t';
$cnt = 1;

*sort1 = sub {
  splice(@{[split(/$del/,$a)]},$cnt,1)
    cmp
  splice(@{[split(/$del/,$b)]},$cnt,1)
};
print sort sort1 @x;
print "\n";

I was thinking about maybe instituting something like this in File::Sort
where a user of the module can pass a delimiter and an array index, and the
sort can be done on that field of the line (I'd already have the sort
routines built similarly).  Comments?

I am also still thinking about how to pass an arbitrary sort routine, but
this would be a nice option in addition to that, I think.

--
Chris Nandor               pudge@pobox.com           http://pudge.net/
%PGPKey=('B76E72AD',[1024,'0824 090B CE73 CA10  1FF7 7F13 8180 B6B6'])
#==                    MacPerl: Power and Ease                     ==#
#==    Publishing Date: Early 1998. http://www.ptf.com/macperl/    ==#



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch