in reply to ascii conversion

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.

Replies are listed 'Best First'.
Re: (Ovid) Re: ascii conversion
by Anonymous Monk on Nov 23, 2000 at 04:05 UTC
    thanks for your help i had had this previously as an assignment but i managed to create a working program in vb but am interested to see how i would do this in perl to help my progression in perl. could you also recommend a good book 4 beginners in perl siting many useful examples as i have to do a web based project later this year using perl in creating cgi scripts. is the perl cookbook any good????

      For good books, check out the site's Reviews section and see what other monks have had to say.

      For a real newbie to Perl, I wholeheartedly recommend Learning Perl.

      Perl Cookbook also rocks, as does Programming Perl ... try O'Reilly's web site and look at their Perl catalog.

      I've heard that there are also good books on Perl by other publishers ... =) (really a joke, see my review of one such book )

      Philosophy can be made out of anything. Or less -- Jerry A. Fodor