Perl and regexs for the newbie!

Associate
Joined
27 Jun 2006
Posts
1,473
I have a csv file that is something like:
"data1"|"data2"|"data3"|"data4"| etc etc

I am opening the file, reading it in and then trying to get rid of al the " marks but to no avail. The output looks the same as the input :(

Any suggestions most welcome, the code I have at the mo is:

Code:
open(INPUT, $file) || die("Could not open input file!");
open(OUTPUT, '>'.$output) || die("Could not open output file!");

while(<INPUT>)
{
	$_=~s/\"//;
	print OUTPUT $_;
}

So how do I get rid of them damed " marks??????

Cheers all,

M.
 
Hi,

Try putting a g at the end of your regexp so it searches and replaces in the whole string:

$_=~s/\"//g

Also, the regexp will be carried out on $_ by default so you could omit this if you like.

Jim
 
JIMA said:
Hi,

Try putting a g at the end of your regexp so it searches and replaces in the whole string:
$_=~s/\"//g
Jim

Cheers Jim,

Completely forgot about the g thing - worked a treat!
Will also kncok off the $_ to save me 2 characters worth :D

M.
 
Back
Top Bottom