ppp has asked for the wisdom of the Perl Monks concerning the following question:
I am perl bginner (but i guess logic is same for all programming languages like C++ and C in my case its perl).
What i want to achieve ?
I have a text file i read that file which contains different IPaddress Time in each line and when i find a particular Time then i delete that line.
What is the problem ?
The problem is when i open a file and check for time (to see that is this the particular time i am looking for to delete this line) then it need to read that file (I mean '<' operation) but when i have to delete that particular line after finding that correct time i need to do write operation (I mean this '>' operation). Now when i try to achieve this i use this code (which will surely not work as the file is opened in read mode we cannot delete (i mean write to it)):
open my $fhi, '<', 'C:\shekhar_Axestrack_Intern\WindowCreation\ListOf +IpAdress.txt', or die "Could not open file $!"; while (my $line = <$fhi>) { ## Doing some operation using $fhi in read mode if($Time >'33') { $fhi->autoflush; #flush the line if time is greater than 33 +hours, whereas all other lines which do not folow the condition are s +till present in file. } } close $fhi;
How to delete that particular line in text file (after some manupulation of time ?)
EDIT:
open my $fhi, '<', 'C:\shekhar_Axestrack_Intern\WindowCreation\ListOfI +pAdress.txt', or die "Could not open file $!"; open my $fho, '>', 'C:\shekhar_Axestrack_Intern\WindowCreation\Lis +tOfIpAdress.txt', or die "Could not open file $!"; while (my $line = <$fhi>) { //Here i write the code to get the time from text file in ech li +ne and below i check in if condition if that exceed 34 hours then flu +sh that line if($Time >'34') { $fhi->autoflush; } print $fho; } close $fhi;
But it deletes all my file ListOfIpAdress.txt whereas i just want to delete only those lines where time > 34
|
|---|