Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Perl question

0 views
Skip to first unread message

sibi...@gmail.com

unread,
Aug 7, 2006, 6:49:22 PM8/7/06
to
I have a file name result01182006.xml which is named according to the
date. I know how to split it to get the values

$a = "result01182006.xml";
$a =~ /^(result)(\d{2})(\d{2})(\d{4})/;
print "$1 $2 $3 $4\n";

In the contents of this file i I need to replace every instance of
1/7/2006 to 01/18/2006.

Change the date of "Sat 07 Jan 2006" to corresponding day which
01/18/2006 falls on, so it should be changed to "Wed 18 Jan 2006

and change the string result01072006 to result01182006

Please can somebody help here.. Working on no sleep whatsover in 24
hrs.

Sibi

use...@davidfilmer.com

unread,
Aug 7, 2006, 7:12:55 PM8/7/06
to
sibi...@gmail.com wrote:
> a multiposted question

http://tinyurl.com/ryucn
http://tinyurl.com/ohy3g
http://tinyurl.com/q234q

Multiposting is universally considered rude in usenet. Folks are
unlikely to help you if you do not abide by basic rules of usenet
courtesy.

--
David Filmer (http://DavidFilmer.com)

John Bokma

unread,
Aug 7, 2006, 8:52:25 PM8/7/06
to
sibi...@gmail.com wrote:

> I have a file name result01182006.xml which is named according to the
> date. I know how to split it to get the values
>
> $a = "result01182006.xml";

don't use $a, use a meaningfull name (e.g. $filename)
Also make sure you have:

use strict;
use warnings;

near the top of your script-

> $a =~ /^(result)(\d{2})(\d{2})(\d{4})/;
> print "$1 $2 $3 $4\n";
>
> In the contents of this file i I need to replace every instance of
> 1/7/2006 to 01/18/2006.
>
> Change the date of "Sat 07 Jan 2006" to corresponding day which
> 01/18/2006 falls on, so it should be changed to "Wed 18 Jan 2006

The best thing to do this is to parse the date(s) to an internal format,
for example the one that time uses, and add the right amount of hours,
convert back to the desired format (see Time::Local for example). That
way you don't have to worry about things like Sat and Wed.

OTOH, it it are a restricted number of conversions, like replacing 7
with 18 iff date = 1/7/2006 etc. you might want to do just some s///,
e.g.

for ( $line ) {

s{1/7/2006}{01/18/2006}g;
s{Sat 07 Jan 2006}{Wed 18 Jan 2006}g;
}

> and change the string result01072006 to result01182006
>
> Please can somebody help here.. Working on no sleep whatsover in 24
> hrs.

Then get some sleep. I never understand people who think that
programming just a few more hours is really productive. My experience is
that the next time you spend twice the amount of hours you worked extra
the previous day with cleaning up the garbage.

What you want to do could be done with a text editor like TextPad
(search & replace) in a few steps. If this kept you up for 24 hrs, you
probably should find different work.


Programming requires concentration, and there is a limitation/day. It's
certainly not 18 hrs on coke (the drink) and pizza's combined with
sleeping on the office floor, how "romantic" that might sound.


--
John Bokma Freelance software developer
&
Experienced Perl programmer: http://castleamber.com/

it_says_BALLS_on_your_forehead

unread,
Aug 8, 2006, 12:04:53 AM8/8/06
to

sibi...@gmail.com wrote:
> I have a file name result01182006.xml which is named according to the
> date. I know how to split it to get the values
>
> $a = "result01182006.xml";
> $a =~ /^(result)(\d{2})(\d{2})(\d{4})/;
> print "$1 $2 $3 $4\n";
>
> In the contents of this file i I need to replace every instance of
> 1/7/2006 to 01/18/2006.
>
> Change the date of "Sat 07 Jan 2006" to corresponding day which
> 01/18/2006 falls on, so it should be changed to "Wed 18 Jan 2006
>
> and change the string result01072006 to result01182006

i love your subject line.

Mumia W.

unread,
Aug 8, 2006, 4:07:23 AM8/8/06
to
On 08/07/2006 05:49 PM, sibi...@gmail.com wrote:
> I have a file name result01182006.xml which is named according to the
> date. I know how to split it to get the values
>
> $a = "result01182006.xml";
> $a =~ /^(result)(\d{2})(\d{2})(\d{4})/;
> print "$1 $2 $3 $4\n";
>
> In the contents of this file i I need to replace every instance of
> 1/7/2006 to 01/18/2006.
>

Please don't multi-post; crosspost instead. Read and follow
the posting guidelines for comp.lang.perl.misc:
http://www.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

"Result01182006.xml" is the file's name--not its contents. Are
you sure you want to change the contents?

> Change the date of "Sat 07 Jan 2006" to corresponding day which
> 01/18/2006 falls on, so it should be changed to "Wed 18 Jan 2006
>
> and change the string result01072006 to result01182006
>

Please re-write this statement; it's not parse-able English.

> Please can somebody help here.. Working on no sleep whatsover in 24
> hrs.
>
> Sibi
>

It's important that you read the documentation for the
localtime command:
perldoc -f localtime

Chris Mattern

unread,
Aug 8, 2006, 11:20:27 AM8/8/06
to
John Bokma wrote:
> sibi...@gmail.com wrote:
>
>
>>I have a file name result01182006.xml which is named according to the
>>date. I know how to split it to get the values
>>
>>$a = "result01182006.xml";
>
>
> don't use $a, use a meaningfull name (e.g. $filename)

Also $a and $b are used by sort, so you shouldn't be using them
anyways.

> Also make sure you have:
>
> use strict;
> use warnings;
>
> near the top of your script-
>

Always good advice.


Chris Mattern

0 new messages