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:
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).s/(.)/chr((ord $1)-45)/ge;
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |