On Wed, 27 Mar 2002, William R Ward wrote:

> Joshua Polterock writes:
> >Apologies, I consider myself an intermediate Perl programmer at best, but
> >would something like this fit into this category. I realize it has a U*ix
> >bent.
> >
> >A Perl script called crlf with the following.
> [...]
>
> A sound implementation, but I think that all those evals will slow it
> down too much.  How about something like this instead:
>
> #!/usr/bin/perl -w
>
> use strict;
> use File::Basename;
>
> my $dos        = "\015\012";
> my $mac        = "\015";
> my $unix       = "\n";
> my $myPlatform = "$unix";
> my $iam        = basename($0);
> my $regexp     = "";
>
> $myPlatform = $mac if $^O =~ /mac/i;
> $myPlatform = $dos if $^O =~ /win|dos/i;
>
> my %subs = (
>   crlf     => sub { s/[\015\012]+/$myPlatform/ },
>   dos2unix => sub { s/$dos/$unix/ },
>   unix2dos => sub { s/$unix/$dos/ },
>   mac2dos  => sub { s/$mac/$dos/  },
>   mac2unix => sub { s/$mac/$unix/ },
>   dos2mac  => sub { s/$dos/$mac/  },
>   unix2mac => sub { s/$unix/$mac/ },
> );
>
> die "I do not recognize my own name."
>   unless exists ($subs{$iam});
>
> my $sub = $subs{$iam};
> while(<STDIN>) {
>   &$sub;
>   print;
> }
>
>
> --
> William R Ward            [EMAIL PROTECTED]          http://www.wards.net/~bill/
> -----------------------------------------------------------------------------
>      If you're not part of the solution, you're part of the precipitate.
>

Much better. This scales nicely.

Josh


Reply via email to