Could somebody help me to shorten the working script I wrote marked script 1 below, as I realised that I could not do the following :- ------ open FILE, 'cookie.txt' or die "$!\n"; open SAME_FILE, '>cookie.txt' or die "$!\n"; while (<FILE>) { print SAME_FILE; }; ------ Since I cannot do the above so basically this is what I did :- My question : Is this the best and only way?
open FILE, 'cookie.txt' or die "$!\n"; open FILE2, '>cookie1.txt' or die "$!\n"; print FILE2 while <FILE>; open FILE2, 'cookie1.txt' or die "$!\n"; open FILE, '>cookie.txt' or die "$!\n"; print FILE while <FILE2>; ------ What I wanted to do is :- while (<#reading a file lets say 'cookie.txt'>) { if (the test is true) { change the default $_; print the default $_ into the same file 'cookie.txt'; $switch = 1; }else { print the default $_ into the same file 'cookie.txt'; }; ); if ($switch != 1) { print to the file 'cookie.txt' all the things here; }; # end of what I wanted to do. --- working script 1 ---- -- how do I shorten this script ---- #!d:\perl\bin\perl.exe -w use CGI::Carp qw(fatalsToBrowser); use strict; print "content-type: text/plain\n\n"; my %FORM = (membername => 'dindy'); open READ_COOKIEFILE, 'cookie.txt' or die "$!\n"; open WRITE_COOKIEFILE, '>cookie1.txt' or die "$!\n"; # initialization my $switch5 =0; my $id = 123456; while (<READ_COOKIEFILE>) { my ($tempass , $name ); ($tempass , $name) = split / /; chomp $name; if ($FORM{'membername'} eq $name ){ $_=~ s/$tempass/$id/; print WRITE_COOKIEFILE; $switch5 = 1; print "true\n"; # for debugging } else { print WRITE_COOKIEFILE; print "false\n"; # for debugging }; }; if ($switch5 != 1) { print WRITE_COOKIEFILE "$id $FORM{'membername'}\n"; }; close READ_COOKIEFILE; close WRITE_COOKIEFILE; open READ_COOKIEFILE, 'cookie1.txt' or die "$!\n"; open WRITE_COOKIEFILE, '>cookie.txt' or die "$!\n"; print WRITE_COOKIEFILE while <READ_COOKIEFILE>; close READ_COOKIEFILE; close WRITE_COOKIEFILE; _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]