Tim Johnson wrote:
What does it do when you try it?
I'm seeing an empty output file.
One thing I see right now is that you are attempting to print the reverse of each line, but you are reading the lines sequentially, which will not give the result you want. Also, you should get used to always "use strict"ing.
Further googling reveals that
Reverse both the order of the lines and the text order inside each line perl -e 'print scalar reverse <>'
So if I change my program to
#!/usr/bin/perl -e use strict; $a= "myin.txt"; $b="myout.txt"; open(IN, $a) || die "cannot open $a for reading: $!"; open(OUT, ">$b") || die "cannot open $b for reading: $!"; while (<IN>) { print scalar reverse OUT $_;
The file handle should immediately follow the print statement.
print OUT scalar reverse $_;
In order to reverse the line, you can split the string into an array of characters, reverse them, and then join them back into a string. (the functions: join, reverse, and split all use $_ as a default argument, so it's not specified)
print OUT join '', reverse split //;
} close (IN) || die "cannot close $a: $!"; close (OUT) || die "cannot close $b: $!";
but no myout.txt created.
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>