Tons of confusion over there, eh? :-)
First of all: you are opening your database and slurping in at once in memory. It's ok if it's not too big, but in case it is and you have enough disk space I suggest you to read line by line and write to another file. If you want, you could end your script by overwriting the old file with the newly created one; check File::Copy and it's function move for details.
Second: You use double quotes around $db in your opens: that would be needed if you specify, for example, "> $db" to mean overwrite the file. In your situation double quotes are useless.
Next: your foreach cycle doesn't print on DATA, which would be then left empty!
And finally: you used a character class \s where it had no meaning in the first substitution, and you swapped the matching string with the substitute in the second.
A slightly revised (but untested!) version of your code could be:
use strict ; # now and forever! my $db = 'aaa.txt'; open DATA, "< $db" or die "did not open for reading: $!\n"; my @dat = <DATA> ; # don't need parentheses, context forced by @dat close DATA; open DATA, "> $db" or die "did not open for writing: $!\n"; foreach my $line (@dat) { # Indent, it's useful! $line =~ s/main/index/g; $line =~ s/\t/ /g; #This is not working $line =~ s/^/\a/g; #This is not working print DATA $line; } close DATA ;
Ciao!
--bronto
# Another Perl edition of a song:
# The End, by The Beatles
END {
$you->take($love) eq $you->made($love) ;
}
In reply to Re: Substituting data
by bronto
in thread Substituting data
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |