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: Perl Programming Help: Beginner:
Delete from file

 



newbie2002
Deleted

Apr 30, 2001, 2:14 AM

Post #1 of 2 (497 views)
Delete from file Can't Post

This forum seems nice.
My file looks like
1.I'm born in Europe 1980
2.O like horses and animals
3.I'm not good at perl
4.but I will learn it someday

I would like to read the file and remove
every '1.' , '2.' ond so on and then write it back to the file again so it would look like

I'm born i Europe 1980
O like horses and animals
I'm not good at perl
but I will learn it someday

/Thanks again



Jean
User


Apr 30, 2001, 3:56 AM

Post #2 of 2 (494 views)
Re: Delete from file [In reply to] Can't Post

This is one of the many ways do solve your problem:


Code
my $sourcefilename = 'file.test'; 
my $targetfilename = 'file1.test'; # Do not use same names for source and target files!
my $line;

open(SRCFILE, $sourcefilename) or die "Unable to open file $sourcefilename ($!)\n";
open(TRGFILE, ">$targetfilename") or die "Unable to create file $targetfilename ($!)\n";
while ($line = <SRCFILE>) {
$line =~ s/^\d+\.(.*)/$1/; # This is the core line - removes digits until dot is met.
print TRGFILE $line;
}
close(TRGFILE);
close(SRCFILE);

Enjoy,

Jean Spector
QA Engineer @ Extent Technologies, Ltd.
mage@lycosmail.com

 
 


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

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