Ged wrote at Thu, 24 Jul 2003 08:00:04 +0000:

> I am very new to perl (2 days) but am finding it very rewarding. I have however 
> stumbled across a problem hopefully somebody can help me with.
> 
> I am trying to open a file, change the text from lowercase to uppercase and rewrite 
> it to a backup file. However, I only seem to be duplicating the original file. Here 
> is my code:
> 
> $stuff="c:/ged/perl files/stuff.txt";
> $backup="c:/ged/perl files/stuff.bk";
> 
> open STUFF, $stuff or die "Cannot open $stuff for read :$!";
> open BACKUP, ">$backup" or die "Cannot open $backup for write :$!";
> 
> while (<STUFF>) {
>       s/a-z/A-Z/g;
       ^^

You meant tr instead.
(The substitution really changes all occurrences of the string "a-z" to
"A-Z".

>       print BACKUP "$_";

Please read
perldoc -q 'What\'s wrong with always quoting "$vars"'

> }

However, there is a shorter other way, as Perl has a builtin uppercase
function:

while (<STUFF>) {
    print BACKUP, uc;
}

Please read 
perldoc -f uc
for details.


Greetings,
Janek

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

Reply via email to