Re: Regular Expression help!



On Jan 31, 11:16 am, "Paul Lalli" <mri...@xxxxxxxxx> wrote:
On Jan 31, 11:10 am, "Suk" <suk...@xxxxxxxxxx> wrote:

Sorry I meant -

open CSVFILE, "data.csv" or die "failed to open changes $!";

while (<CSVFILE>) {

print "$`$3/$2/$1$'" if (/(\d{2})\/(\d{2})\/(\d{4})/);

}

Which just alters the first date- I need to alter all of them

So change your pattern-match-within-an-if to s///g, and print the
results.
s/(\d{2})\/(\d{2})\/(\d{4})/$3/$2/$1/g;
print;

Ugh. Gotta escape those last two slashes...

s/(\d{2})\/(\d{2})\/(\d{4})/$3\/$2\/$1/g;

Or, preferably, just stop using / as your delimiter in the s/// :

s!(\d{2})/(\d{2})/(\d{4})!$3/$2/$1!g;

Paul Lalli


.