Previous Thread
Next Thread
Print Thread
Rate Thread
#103863 08/26/2002 4:56 AM
Joined: Apr 2001
Posts: 39
Junior Member
Junior Member
Offline
Joined: Apr 2001
Posts: 39
Hi all,
if I have a data file include
200|88|0|0||||||||password|codenumber1|||0|0|0|0
200|88|0|0||||||||password|codenumber2|||0|0|0|0
200|88|0|0||||||||password|codenumber3|||0|0|0|0
200|88|0|0||||||||password|codenumber4|||0|0|0|0
I want to delete line
200|88|0|0||||||||password|codenumber2|||0|0|0|0
so the data file will be
200|88|0|0||||||||password|codenumber1|||0|0|0|0
200|88|0|0||||||||password|codenumber3|||0|0|0|0
200|88|0|0||||||||password|codenumber4|||0|0|0|0
how can I do this
any help plz smile
help help help help

Sponsored Links
#103864 08/26/2002 3:10 PM
Joined: Mar 2000
Posts: 21,079
Likes: 3
I type Like navaho
I type Like navaho
Joined: Mar 2000
Posts: 21,079
Likes: 3
bumping for you smile


- Allen wavey
- What Drives You?
#103865 08/26/2002 5:57 PM
Joined: Aug 2000
Posts: 335
Member
Member
Offline
Joined: Aug 2000
Posts: 335
1) This is untested code.
2) Backup the data file before using this code.

Code
open(my $fh, '+<', 'path/to/the/file') or die "$!";
my @lines = <$fh>;
truncate($fh, 0) or die "$!";
for (@lines) {
my @fields = split '|' => $_;
print $fh $_ unless $fields[12] eq 'codenumber2';
}
close($fh) or warn "$!";

#103866 08/28/2002 6:47 AM
Joined: Apr 2001
Posts: 39
Junior Member
Junior Member
Offline
Joined: Apr 2001
Posts: 39
tipsy thanks AllenAyres
thanks Dave_L for youre help
the code delete data.file laugh
i modify this code and its work fine thanks all
Code
 
open(FILE, "$cgipath/data.file") &#0124;&#0124; &error("Error reading data.file");
@filedata = <FILE>;
close (FILE);

foreach $line(@filedata) {
@fields = split(/|/,$line);
if ($fields[12] == '123456789') {
$line = "";
open (FILE,">$cgipath/data.file") &#0124;&#0124; &error("Error writing to data.file");
if ($flock) { flock FILE, 2 }
print FILE @filedata;
close (FILE);

}
}

#103867 08/29/2002 5:11 PM
Joined: Aug 2000
Posts: 335
Member
Member
Offline
Joined: Aug 2000
Posts: 335
Hmmmm, that code looks a bit strange, but as long as it does what you want ... smile

Sponsored Links

Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
AllenAyres
AllenAyres
Texas
Posts: 21,079
Joined: March 2000
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20221218)