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: Regular Expressions:
Replacing Double quotes

 



riscphree
New User

Jun 5, 2007, 8:57 PM

Post #1 of 3 (2298 views)
Replacing Double quotes Can't Post

I've got a file with lines like this (my test file has just 4 lines of data):

"90001","+33.973951","-118.248405","LOS ANGELES","CA","LOS ANGELES","STANDARD"

And I want to just make the quoted entries comma seperated instead of with quotes. So I wrote this:


Code
#!/usr/bin/perl -w 

open(FILEIN, "quotes.txt");
open(FILEOUT, ">quotesout.txt");

while(<FILEIN>){
print FILEOUT $variable =~ tr/"//d;
}
close(FILEOUT);
close(FILEIN);


But my quotesout.txt file gives me 4 zeroes (one for each line?). Any suggestions or hints?


KevinR
Veteran


Jun 6, 2007, 5:15 PM

Post #2 of 3 (2293 views)
Re: [riscphree] Replacing Double quotes [In reply to] Can't Post

$variable has no value. But you don't need it anyway:


Code
#!/usr/bin/perl -w  

open(FILEIN, "quotes.txt");
open(FILEOUT, ">quotesout.txt");

while(<FILEIN>){
tr/"//d;
print FILEOUT;
}
close(FILEOUT);
close(FILEIN);

-------------------------------------------------


riscphree
New User

Jun 6, 2007, 5:20 PM

Post #3 of 3 (2292 views)
Re: [KevinR] Replacing Double quotes [In reply to] Can't Post

Ah cool! That shortened this version that worked for me as well.


Code
open(FILEIN, "zipcodes.txt"); 
open(FILEOUT, ">zipcodesOUT.txt");

while(<FILEIN>){
$variable = $_;
$variable =~ tr/"//d;
print FILEOUT $variable;
}
close(FILEOUT);
close(FILEIN);


 
 


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

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