Kasi ramanathen wrote:
> 
> dear friends i'm in work place and i'm facing a problem of replacing an
> ascii character with some other ascii character i cut the ascii character
> from my word document and pasted it in my pear programme but the result
> is not as i expected. plese give me answer with simple codeing and also
> say me how to use word file as input file. my coding is as below

You _should_ be use'ing warnings and strict when developing your code.

> @a=<>;
> $ln=join('',@a);

It is more efficient to undef the input record separator and slurp the
file into a scalar.

> $t= $ARGV;
> print "$t\n";
> $ln=~s/
> file://gis;
> 
> $ln=~s/'/,/gis;
> $ln=~s/[?????]//gis;s;
> $ln=~s/[cr]//gis;
> $ln=~s/[abc]//gis;
> $ln=~s/_/_/gis;
> $ln=~s/ý/+/gis;
> $ln=~s/^/^/gis;
> $ln=~s/%/%/gis;
> $ln=~s/</</gis;
> $ln=~s/'/'/gis;
> $ln=~s/'/'/gis;
> $ln=~s/"/"/gis;
> $ln=~s/"/"/gis;
> $ln=~s/o/ú/gis;
> $ln=~s/-/--/gis;
> $ln=~s/-/----/gis;
> $ln=~s/~/~/gis;
> $ln=~s/>/>/gis;

All of your substitutions use the /s option which determines wheather
the dot (.) matches a newline or not.  Since none of the regular
expressions uses a dot, the /s option is not needed.  All of your
substitutions use the /i option which affects how alphabetic characters
are matched but most of your regular expressions do not contain
alphabetic characters.

> print $ln;
> open (H, ">$ARGV");

You should _always_ verify that the file was opened correctly.

> print H $ln;

It looks like you want to modify the file "in-place" and perl provides a
method to do this.

#!/usr/bin/perl -w
use strict;

$/  = undef;
$^I = '.bak';

while ( <> ) {
    print "$ARGV\n";

    s/\nfile://gi;

    tr/'?????\177/,\177/;
    tr/crabc//d;
    tr/_ý^%<'"o/_+^%<'"ú/;

    s/-/--/g;
    s/-/----/g;

    tr/~>/~>/;
    }

__END__



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to