Home > Archive > PERL Beginners > September 2006 > arithmetic expression while substituting
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
arithmetic expression while substituting
|
|
| Michael Alipio 2006-09-06, 6:57 pm |
| Hi,
Suppose I have the output of this command
date +%d.%H
which outputs:
06.11
I want to adjust the last two digits to less 1:
such that it becomes 06.10..
how do I do that?
perhaps something like this.
s/\d+$/(regexp being lookup minus 1/
thanks!
________________________________________
__________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
| |
| Adriano Ferreira 2006-09-06, 6:57 pm |
| On 9/6/06, Michael Alipio <daem0nb0y@yahoo.com> wrote:
> I want to adjust the last two digits to less 1:
> perhaps something like this.
> s/\d+$/(regexp being lookup minus 1/
s/(\d+)$/$1-1/e
is going to work, even though it is convoluted and not robust. For
example, '06.00' will become '06.-1'
| |
| Paul Lalli 2006-09-06, 6:57 pm |
| Adriano Ferreira wrote:
> On 9/6/06, Michael Alipio <daem0nb0y@yahoo.com> wrote:
>
>
> s/(\d+)$/$1-1/e
>
> is going to work, even though it is convoluted and not robust. For
> example, '06.00' will become '06.-1'
s{
(\d+)$
} {
die "Cannot subtract from 0\n" if $1 == 0;
sprintf("%0*d", length($1), $1 - 1);
}ex;
Paul Lalli
| |
| DJ Stunks 2006-09-06, 6:57 pm |
|
Michael Alipio wrote:
> Hi,
>
> Suppose I have the output of this command
> date +%d.%H
>
> which outputs:
> 06.11
>
> I want to adjust the last two digits to less 1:
> such that it becomes 06.10..
> how do I do that?
>
> perhaps something like this.
> s/\d+$/(regexp being lookup minus 1/
are you asking how to figure out yesterday's date?
perldoc -q yesterday
normally one does not simply use addition/subtraction for dates/times.
there are far too many edge cases.
-jp
|
|
|
|
|