Chris Nandor <[EMAIL PROTECTED]> writes:

> In article <[EMAIL PROTECTED]>,
>  [EMAIL PROTECTED] (Dan Kogai) wrote:
> 
> > On Monday, Nov 25, 2002, at 01:05 Asia/Tokyo, Chris Nandor wrote:
> > > The bottom line was that it'd be nice to have a PerlIO filter for perl
> > > 5.8.x, so that MacPerl can execute Unix and Windows text files, and 
> > > Mac OS X
> > > perl can execute Mac OS text files, etc.  Patches are surely welcome!  
> > > :-)
> > 
> > One good question may be how to handle newlines in heretext, the only 
> > part that really matters because that's the only exception to the fact 
> > that newlines are nothing but whitespace from perl compiler's point of 
> > view -- oops, shebang is another.  When you feed MacPerl *.pl to MacOS 
> > X, should linefeeds in heretext emit \015 or \012?
> 
> I am talking here about taking (for example) a perl program with Mac OS 
> newlines, and making it run under Unix perl.  In order for that to happen, 
> you need to translate all the CRs to LFs.  That would include the CRs in the 
> heretext, as well as in every literal string.
> 
> 
> 
> > I am not sure which is lazier to simply apply
> > 
> > # Any -> Unix
> > perl -i.bak -ple 's/\015\012|\015|012/\012/g' *.pl
> > # Any -> Mac
> > perl -i.bak -ple 's/\015\012|\015|012/\015/g' *.pl
> > 
> > or teach camel the same trick....
> 
> One of the main points of this is that some people will want the same files 
> to be used in more than one context, such as sharing code between Windows 
> and Unix perl over NFS, or sharing code between perl on Mac OS X and MacPerl 
> under Mac OS or Classic.  Right now, the only solution is to make copies, as 
> you suggest.
> 

Or use source filters:

package Filter::Any2Unix;
use Filter::Util::Call;
sub import {
    if ($^O ne 'MacOS') {
        filter_add(sub {
                       my($status) = filter_read();
                       if ($status > 0) {
                           s/\015\012|\015|\012/\012/g;
                       }
                   }
                  );
    }
}

and then call the script with 

   perl -MFilter::Any2Unix script.pl

or embed "use Filter::Any2Unix" into the script.

Regards,
        Slaven

-- 
Slaven Rezic - [EMAIL PROTECTED]

Tk-AppMaster: a perl/Tk module launcher designed for handhelds
        http://tk-appmaster.sf.net

Reply via email to