Re: Regular Expression help!



On 31 Jan, 15:07, Josef Moellers <josef.moell...@xxxxxxxxxxxxxxxxxxx>
wrote:
Suk wrote:
Look at the excerpt from a CSV file below

"C29560","Some text ","07/12/2006 11:00:00","07/12/2006
16:00:00","07/12/2006 16:00:00","07/12/2006 11:00:00","NODE21A3"

I am trying to write a snippet of perl that will swap the date and
year bits in all of the date fields, so that 07/12/2006 becomes
2006/12/07. So the line should read:

"C29560","Some text ","2006/12/07 11:00:00","2006/12/07
16:00:00","2006/12/07 16:00:00","2006/12/07 11:00:00","NODE21A3"

Any help would be appreciated !

What have you tried so far?
Where does your code not meet your expectations?
Using Text::CSV_XS, split and join this is a trivial exercise.

--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett

I have tried

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

while (<CHANGES>) {

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

Sort of works but doesnt get all of them


.



Relevant Pages

  • Re: So what colour is it?
    ... was because it just wasn't in the least bit funny. ... It must deserve some sort of prize, then, to reproduce Pratchett ...
    (uk.rec.sheds)
  • Re: BBC2 - chinese food made easy
    ... For anybody else who doesnt really do this sort of thing on a regular ... basis - then the show itself was as useful as a slide rule is to forrest ...
    (uk.media.tv.misc)
  • Re: Plosrie Wednesday 13th
    ... That deserves some sort of prize, for getting "a rat" right and then ... I've just switched newsreader, so this is something of a test posting (TB ...
    (uk.media.radio.archers)
  • Re: Why no pc/computer shows on tv
    ... tonight - so that that doesnt appear to be any sort of guideline. ... What would the format be? ...
    (uk.media.tv.misc)
  • Re: non case sensitive searching
    ... duplicates from a list it doesnt seem to work ... The line above is ineffective because you do not sort the original list. ... have same spelling but in diff. ...
    (comp.lang.ruby)