On May 13, Lee Johnson said:

>#
># End date is a year after start date
>#
>$edate = $sdate;
>$edate =~ s/\///g;
>$edate++;
>$edate =~ s/.*(\d{4})$/01\/04\/$1/;

Are you sure you want to just use April 1st (or January 4th) always?  You
don't want to use the day and month in $sdate?

>where $sdate is a UK date of the type "dd/mm/yyyy"
>
>I've tried ($edate = $sdate) =~ s/(.*)(\d)$/$1($2++)/e; to no avail. I think
>I'm misunderstanding the /e modifier here?

A little bit, yes.  The /e modifier makes the right-hand side Perl code,
and you should recognize that

  $1($2++)

isn't valid Perl code.  You'd need

  $1 . ($2++)

but that won't work for two reasons.  First, $x++ returns its OLD value,
and THEN increments it, so you wouldn't get a changed value.  The second
reason is that you can't modify the $DIGIT variables.

Finally, your code is making a mistake in the regex.  What if the year is
2009?  You're only matching the LAST digit of the year, and adding one to
it.  Your string would end up being "...20010", which is wrong.  Match the
whole four-digit year, and add one to it.  When it rolls around to 9999,
then come back to me and complain about my bad code. ;)

And your regex is doing more work than it has to.  Why would you write

  s/(.*)(\d{4})$/$1 . (1 + $2)/e;

when you could just write

  s/(\d{4})$/1 + $2/e;

You're matching the WHOLE beginning of the string just to replace it with
ITSELF.  That's silly and inefficient.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
CPAN ID: PINYAN    [Need a programmer?  If you like my work, let me know.]
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to