- Original Message -
From: ""michael wang"" <[EMAIL PROTECTED]>
Newsgroups: perl.beginners
To:
Sent: Wednesday, August 06, 2008 9:00 AM
Subject: date info
Hi,
if I have something like 20080503, how can I get the date a year ago,
such as 20070503 in perl?
Thanks,
michael
michael wang wrote:
>
> if I have something like 20080503, how can I get the date a year ago,
> such as 20070503 in perl?
If you simply want to subtract one from the first four-digit field found in your
string, then you can write
$str =~ s/(\d{4})/$1-1/e;
HTH,
Rob
--
To unsubscrib
On 8/6/08, Mr. Shawn H. Corey <[EMAIL PROTECTED]> wrote:
> On Wed, 2008-08-06 at 08:00 -0500, michael wang wrote:
> > Hi,
> >
> > if I have something like 20080503, how can I get the date a year ago,
> > such as 20070503 in perl?
> >
> > Thanks,
> >
> > michael
>
> my $str = '20080503
On Wed, Aug 6, 2008 at 4:29 AM, Kenneth Brun Nielsen
<[EMAIL PROTECTED]> wrote:
> Within a perl program, I want to go to a particular mode when a
> keyword is found. The keyword is a regexp.
>
> E.g.
> #!/usr/bin/perl -w
> open FILEHANDLE, "soatest.soa";
> while (){
>if (/^\*| XI/) {
>p
On Wed, 2008-08-06 at 08:00 -0500, michael wang wrote:
> Hi,
>
> if I have something like 20080503, how can I get the date a year ago,
> such as 20070503 in perl?
>
> Thanks,
>
> michael
my $str = '20080503';
$str =~ s/(.*)(\d\d\d\d)(\d\d\d\d)$/$1.($2-1).$3/e
print "$str\n";
--
michael wang 写道:
> Hi,
>
> if I have something like 20080503, how can I get the date a year ago,
> such as 20070503 in perl?
>
you may extract the exact date from the original string (ie, use a
regex), then convert it to any date form you wanted (use POSIX::strftime
or something like th
Hi,
if I have something like 20080503, how can I get the date a year ago,
such as 20070503 in perl?
Thanks,
michael
- Original Message -
From: ""Remy Guo"" <[EMAIL PROTECTED]>
Newsgroups: perl.beginners
To: "Perl Beginners"
Sent: Tuesday, August 05, 2008 10:14 PM
Subject: question about text operation using regex.
hi all,
i have a txt log file and i want to delete the 9th character of each
line.
Kenneth Brun Nielsen wrote:
>
> I need to make a conditional on a regular expression match. How can I
> do that?
>
> E.g. in the code below, it prints all lines, and NOT only the ones
> that match. How can I make the boolean test correct?
>
> #!/usr/bin/perl -w
> open FILEHANDLE, "soatest.soa";
>
[EMAIL PROTECTED] wrote:
The following Perl one-liner will do what you need
perl -n -e 's/(.{8,8}).(.*)/$1$2/;print ;'
Or more simply as:
perl -pe's/^(.{8})./$1/'
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in sho
You are almost right, since it prints all lines all lines match.
Could you explain what it is that you are trying to match, that way people
might be able to help getting the regex right.
The way you are looking at the file line by line is valid and if your regex
matches only a few lines it will o
I need to make a conditional on a regular expression match. How can I
do that?
E.g. in the code below, it prints all lines, and NOT only the ones
that match. How can I make the boolean test correct?
#!/usr/bin/perl -w
open FILEHANDLE, "soatest.soa";
while (){
if (/^\*| XI/) {
print "m
Within a perl program, I want to go to a particular mode when a
keyword is found. The keyword is a regexp.
E.g.
#!/usr/bin/perl -w
open FILEHANDLE, "soatest.soa";
while (){
if (/^\*| XI/) {
print "match in line: $.\n";
}
}
This conditional seems to be true for all lines (although
The following Perl one-liner will do what you need
perl -n -e 's/(.{8,8}).(.*)/$1$2/;print ;'
The first set of parentheses strips out the first 8 characters, the second set
strips out everything after the 9th character which is lost.
My test line was:-
(echo "1234567890";echo "abcdefghijkl")|pe
[EMAIL PROTECTED] wrote:
>
> How do I round off a decimal to the next nearest whole digit ,
> example
> 0.123 = 1,
> 1.23 = 2,
> 4.7312 = 5, etc etc.
>
> Right now I can only do the above by extracting the first digit using splice
> , then add one.
You need the ceil() function from the POSIX
[EMAIL PROTECTED] 写道:
> Hi,
> How do I round off a decimal to the next nearest whole digit ,
> example
> 0.123 = 1,
> 1.23 = 2,
> 4.7312 = 5, etc etc.
$number = int($number) + 1;
also does the same thing.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PR
On Wed, 2008-08-06 at 13:31 +0800, [EMAIL PROTECTED] wrote:
> Hi,
> How do I round off a decimal to the next nearest whole digit ,
> example
> 0.123 = 1,
> 1.23 = 2,
> 4.7312 = 5, etc etc.
>
> Right now I can only do the above by extracting the first digit using splice
> , then add one.
>
>
> -Original Message-
> From: Anirban Adhikary [mailto:[EMAIL PROTECTED]
> Sent: 06 August 2008 06:51
> To: beginners@perl.org
> Subject: Re: how to round off a decimal to the next whole number
>
> On Wed, Aug 6, 2008 at 11:01 AM, <[EMAIL PROTECTED]> wrote:
>
> > Hi,
> > How do I round of
18 matches
Mail list logo