With all due respect, this screams "homework" to me. If so, it's nice if you could let us know so that we can assist you without giving you the answers.

I'd like to say that if you are new to Perl, I congratulate you on using -w and strict. However, I am surprised that you didn't see the warning about trying to modify a read-only value: $1. The "dollar digit" ($1, $2, $3, etc) variables are only assigned to by what is called a "back reference" in a regular expression. See perlre for details.

Since I can't tell if this is homework or not, I'll just provide some hints. I would probably use something like the following:

s/(.)/chr((ord $1)-45)/ge;
However, if this is homework, your instructor is going to ask you how you figured out how to do that. It also has the problem that it will convert more than letters (which is fine if those are your specs).

Something closer in spirit to what you want: use a while loop to read from your filehandle and then split each line into an array and iterate over the array. getc is horribly inefficient. Once you've converted the individual characters, join the array back together and write it out to your output file.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.


In reply to (Ovid) Re: ascii conversion by Ovid
in thread ascii conversion by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.