[27883] in Perl-Users-Digest
Perl-Users Digest, Issue: 9247 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 29 21:05:47 2006
Date: Mon, 29 May 2006 18:05:04 -0700 (PDT)
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, 29 May 2006 Volume: 10 Number: 9247
Today's topics:
Re: datetime problem <rvtol+news@isolution.nl>
Re: regular expression problem ? and * characters <rvtol+news@isolution.nl>
Re: replace string with variable <njus@larshaugseth.com>
Re: replace string with variable <noreply@gunnar.cc>
Re: replace string with variable <cmic@caramail.com>
Re: replace string with variable <peace.is.our.profession@gmx.de>
Re: replace string with variable <peace.is.our.profession@gmx.de>
Re: replace string with variable <peace.is.our.profession@gmx.de>
Re: replace string with variable <peace.is.our.profession@gmx.de>
Re: replace string with variable <listasaca@gmail.com>
Re: replace string with variable <noreply@gunnar.cc>
Re: replace string with variable <xicheng@gmail.com>
Re: replace string with variable <listasaca@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 29 May 2006 13:07:13 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: datetime problem
Message-Id: <e5es8j.v0.1@news.isolution.nl>
Nicky schreef:
> Encode::from_to($date, 'ISO-8859-7', 'utf8');
>
> a) $date in this format wont get inserted into a mysql datetime field
You shouldn't store (string) representations of dates, you should store
them with the date-type of the particular database (or rather the
datetime-type since often the timezone is important too).
The conversion to string is what you do just before you need to show it,
so before you put the date on screen or in print.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Mon, 29 May 2006 12:41:27 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: regular expression problem ? and * characters
Message-Id: <e5eqdb.13o.1@news.isolution.nl>
compboy schreef:
fup set to clpm
> Im writing a perl script now and this is part of the sricpt
>
> chomp = ($pattern = ARGV[0]);
That is not real code. ITYM
chomp ($pattern = ARGV[0]) ;
> for each(@thisarray)
That is not real code. ITYM
foreach (@thisarray)
or
for (@thisarray)
> {
> if($_ =~ m/$pattern/i)
> {
> print ("found it here, $_");
> }
> }
You can change all that to
/\Q$pattern/ and print "found '$_'\n" ;
> my question is how do you imporve it so it can accept the input
> that contains* and ?
> character(s) like *ab? a*b* *a*
Read perlre, look for \Q.
(so if you meant wildcards, don't use "\Q").
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Mon, 29 May 2006 10:50:51 GMT
From: Lars Haugseth <njus@larshaugseth.com>
Subject: Re: replace string with variable
Message-Id: <87lkslf6i3.fsf@durin.larshaugseth.com>
* "aca" <listasaca@gmail.com> wrote:
|
| Hi, from Spain, I'm new user in perl, I have a problem with regular
| expression,
|
| I dont know how I can replace the zeros on the right of the decimal
| separator, for example I have a file with some lines of data how this
| example:
|
| 20.1300,20.2500,19.7700,20.2500,985365,0
|
| And I want that the final text appear how this
|
| 20.13,20.25,19.77,20.25,985365,0
This ought to do the trick:
s/(\.\d+?)0+(?!\d)/$1/g;
--
Lars Haugseth
"If anyone disagrees with anything I say, I am quite prepared not only to
retract it, but also to deny under oath that I ever said it." -Tom Lehrer
------------------------------
Date: Mon, 29 May 2006 12:53:36 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: replace string with variable
Message-Id: <4e025jF1c28maU1@individual.net>
aca wrote:
> I have a file with some lines of data how this example:
>
> 20.1300,20.2500,19.7700,20.2500,985365,0
>
> And I want that the final text appear how this
>
> 20.13,20.25,19.77,20.25,985365,0
s/(\.\d*[1-9])0+\b|\.0*\b/$1 or ''/eg;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 29 May 2006 04:07:13 -0700
From: "cmic" <cmic@caramail.com>
Subject: Re: replace string with variable
Message-Id: <1148900833.369343.102900@i39g2000cwa.googlegroups.com>
Mirco Wahab a =E9crit :
> Thus spoke aca (on 2006-05-29 12:06):
>
> > I dont know how I can replace the zeros on the right of the decimal
> > separator, for example I have a file with some lines of data how this
> > example:
> > 20.1300,20.2500,19.7700,20.2500,985365,0
> >
> > And I want that the final text appear how this
> >
> > 20.13,20.25,19.77,20.25,985365,0
>
> my first shot: use split //, $text
> and join the Elements then:
>
> ...
> # have a file with some lines of data how this example:
> my $text =3D qq{20.1300,20.2500,19.7700,20.2500,985365,0};
>
> my @fields =3D split /(?<=3D[^0])0*,/, $text;
Or even like this (negate + negate =3D> equate !)
my @fields =3D split /(?<!0)0*?,/, $text;
> my $new_text =3D join ',', @fields;
>
.=2E..
>
> (There are zillions of other variants how to do that ..)
There are now zillions minus one ...
--
cmic Perl beginner
>=20
> Regards
>=20
> Mirco
------------------------------
Date: Mon, 29 May 2006 13:01:16 +0200
From: Mirco Wahab <peace.is.our.profession@gmx.de>
Subject: Re: replace string with variable
Message-Id: <e5ekgj$711$1@mlucom4.urz.uni-halle.de>
Thus spoke Gunnar Hjalmarsson (on 2006-05-29 12:53):
>
> s/(\.\d*[1-9])0+\b|\.0*\b/$1 or ''/eg;
>
$text = "20.01";
$text =~s/(\.\d*[1-9])0+\b|\.0*\b/$1 or ''/eg;
print "$text\n";
==> 2001
Regards
Mirco
------------------------------
Date: Mon, 29 May 2006 13:02:30 +0200
From: Mirco Wahab <peace.is.our.profession@gmx.de>
Subject: Re: replace string with variable
Message-Id: <e5ekit$711$2@mlucom4.urz.uni-halle.de>
Thus spoke Lars Haugseth (on 2006-05-29 12:50):
> This ought to do the trick:
>
> s/(\.\d+?)0+(?!\d)/$1/g;
$text = "200.,200.0000";
$text =~ s/(\.\d+?)0+(?!\d)/$1/g;
print "$text\n";
=> 200.,200.0
Regards
Mirco
------------------------------
Date: Mon, 29 May 2006 13:04:46 +0200
From: Mirco Wahab <peace.is.our.profession@gmx.de>
Subject: Re: replace string with variable
Message-Id: <e5ekn4$711$3@mlucom4.urz.uni-halle.de>
Thus spoke axel@white-eagle.invalid.uk (on 2006-05-29 12:56):
>
> $str =~ s/0+,/,/g;
>
$text = "200.,200.0000";
$text =~ s/0+,/,/g;
print "$text\n";
==> 200.,200.0000
Regards
Mirco
------------------------------
Date: Mon, 29 May 2006 13:10:16 +0200
From: Mirco Wahab <peace.is.our.profession@gmx.de>
Subject: Re: replace string with variable
Message-Id: <e5el1f$759$1@mlucom4.urz.uni-halle.de>
Thus spoke cmic (on 2006-05-29 13:07):
> Or even like this (negate + negate => equate !)
> my @fields = split /(?<!0)0*?,/, $text;
No, wont work:
$text = "200.,200.0000";
my @fields = split /(?<!0)0*?,/, $text;
my $text = join ',', @fields;
print $text;
==> 200.,200.0000
Regards
Mirco
------------------------------
Date: 29 May 2006 04:19:40 -0700
From: "aca" <listasaca@gmail.com>
Subject: Re: replace string with variable
Message-Id: <1148901580.755070.106380@38g2000cwa.googlegroups.com>
The first thanks to all for yours rapid answers.
Lars I try you solution , because it the first that I understand, but
the final results
are :
20,20,19,20 and not 20.13,20.25,19.77,20.25
I try test the others answers. Thanks again
ACA
------------------------------
Date: Mon, 29 May 2006 13:26:49 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: replace string with variable
Message-Id: <4e043sF1cmbrmU1@individual.net>
Mirco Wahab wrote:
> Thus spoke Gunnar Hjalmarsson (on 2006-05-29 12:53):
>>
>> s/(\.\d*[1-9])0+\b|\.0*\b/$1 or ''/eg;
>
> $text = "20.01";
> $text =~s/(\.\d*[1-9])0+\b|\.0*\b/$1 or ''/eg;
> print "$text\n";
>
> ==> 2001
Okay, new attempt:
s/(\.\d*[1-9])0+\b|\.0*(?!\d)/$1 or ''/eg;
:)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 29 May 2006 04:36:44 -0700
From: "Xicheng Jia" <xicheng@gmail.com>
Subject: Re: replace string with variable
Message-Id: <1148902604.788560.64990@i40g2000cwc.googlegroups.com>
aca wrote:
> Hi, from Spain, I'm new user in perl, I have a problem with regular
> expression,
>
> I dont know how I can replace the zeros on the right of the decimal
> separator, for example I have a file with some lines of data how this
> example:
>
> 20.1300,20.2500,19.7700,20.2500,985365,0
>
> And I want that the final text appear how this
>
> 20.13,20.25,19.77,20.25,985365,0
>
> I try use the regular expression but the final patron I dont know how
> it can
> be variable.
$string =~ s/(\.\d*?)0+(?=,|$)/$1/g;
Xicheng
------------------------------
Date: 29 May 2006 04:43:14 -0700
From: "aca" <listasaca@gmail.com>
Subject: Re: replace string with variable
Message-Id: <1148902993.956535.293600@j73g2000cwa.googlegroups.com>
Thanks Gunnar for your time but the result are the same, appear the
data but without decimals
20,20,19,20 and not 20.13,20.25,19.77,20.25
I will try more slowly the solution of split mentioned more above by
mirco,
but for me is the solution more hard.
Thanks to all, I hope that some day in the future I will can help to
others, but
for at present, I only can study.
ACA
------------------------------
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:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#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 V10 Issue 9247
***************************************