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

Re: COBOL compiler



On Fri, Aug 29, 2003 at 05:46:01PM -0500, Ron Johnson wrote:
> On Fri, 2003-08-29 at 16:28, Bijan Soleymani wrote:
> > Well then you do it differently:
> > open(INPUT,"records.txt");
> > LOOP: while($record = <INPUT>)
> > {
> > if(!input_filter($record))
> >   {
> >     next LOOP;
> >   }
> >   else
> >   {
> >     #code to process record
> >   }
> > }
> > close(INPUT);
> > 
> > Where input_filter() is the winnowing function you define.
> 
> That's good, but where's the sort function?  Also, what if each
> record-to-be-sorted doesn't come directly from records.txt?  Maybe,
> for each record read from records.txt, you must also query some
> other file(s), or a database, or must do some other algorithmic
> calculation.

RTFM: 'perldoc -f sort'. None of this is terribly hard in Perl at all; I
don't see the point of making people write pseudocode to prove the
point.

> The COBOL SORT verb has 3 sections:
> INPUT - Records (from whatever input) are RELEASEd to the SORT buffers.
>         Any winnowing or transformations can happen here.
> SORT - You can figure that part out.
> OUTPUT - Records are RETURNed from the actual sort and can be pro-
>          cessed (transformed, summarized, etc).

Sounds like the 'map sort map' idiom in Perl that's often used for
complex cases. (It's also a common optimization to factor out expensive
transformations in the sort comparator.)

Cheers,

-- 
Colin Watson                                  [cjwatson@flatline.org.uk]



Reply to: