CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Need a Custom or Prewritten Perl Program?: I need a program that...: Re: [omatza] Reversing the contents of a file: Edit Log



shest75
Novice

Nov 1, 2009, 9:52 AM


Views: 4105
Re: [omatza] Reversing the contents of a file

Bonjour,
Updated program :

open FILE, $ARGV[0] or die $!;
open my $out, '>', $ARGV[1] or die "Can't write new file: $!";

while (<FILE>) {
print reverse;
print $out scalar reverse;print $out "\n";
}

close $out;

then perl myfile.pl in.txt out.txt

the out.txt file will be created each time. If you want to append data at the end of the file use :

open FILE, $ARGV[0] or die $!;
open my $out, '>>', $ARGV[1] or die "Can't write new file: $!";

while (<FILE>) {
print reverse;
print $out scalar reverse;print $out "\n";
}

close $out;

Bye


(This post was edited by shest75 on Nov 1, 2009, 9:55 AM)


Edit Log:
Post edited by shest75 (Novice) on Nov 1, 2009, 9:54 AM
Post edited by shest75 (Novice) on Nov 1, 2009, 9:55 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives