[32606] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3879 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 11 21:09:20 2013

Date: Mon, 11 Feb 2013 18:09:05 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 11 Feb 2013     Volume: 11 Number: 3879

Today's topics:
    Re: Date in CSV/TSV question <ben-goldberg@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 11 Feb 2013 17:48:20 -0800 (PST)
From: Ben Goldberg <ben-goldberg@hotmail.com>
Subject: Re: Date in CSV/TSV question
Message-Id: <a89a653a-d144-45c6-ada6-545bc21f27ce@googlegroups.com>

On Wednesday, January 2, 2013 10:37:02 AM UTC-5, Rainer Weikusat wrote:
> Dr Eberhard Lisse <nospam@lisse.NA> writes:
> 
> > I have a Tab Separated File of roughly 1000 likes with the first
> > fields like
> >
> > "07 Jan 2011"   "TFR"
> > "05 Jan 2011"   "DR"
> >
> > I need change the first field to look like
> >
> > 2011-01-07   "TFR"
> > 2011-01-05   "DR"
> >
> > for all lines, of course :-)-O
> >
> > Can someone point me to where I can read this up? Or send me a code
> > fragment?
> 
> -----------
> 
> %months = map { $_, sprintf('%02d', ++$n); } qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
> 
> 
> 
> while (<>) {
> 
>     s/^"(\d+)\s+(\S+)\s+(\d+)"/"$3-$months{$2}-$1"/;
> 
>     print;
> 
> }
> 
> -----------

Don't forget that you can use perl's "command line" switches even when you put your program in a file.
#!/usr/bin/perl -pi.bak
BEGIN {
   %months = map {;$_, sprintf('%02d', ++$n)}
      qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
}
s/^"(\d+)\s+(\S+)\s+(\d+)"/"$3-$months{$2}-$1"/;
__END__


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 3879
***************************************


home help back first fref pref prev next nref lref last post