[30734] in Perl-Users-Digest
Perl-Users Digest, Issue: 1979 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 12 21:09:47 2008
Date: Wed, 12 Nov 2008 18:09:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 12 Nov 2008 Volume: 11 Number: 1979
Today's topics:
BigInt in per <tux@nospam.ciuc.deu>
Re: BigInt in per <RedGrittyBrick@spamweary.invalid>
Re: determine when to change to or from daylight saving <rvtol+news@isolution.nl>
Editor with embedded perl interpreter? <lap76@19yahoo.com>
Re: Editor with embedded perl interpreter? <jurgenex@hotmail.com>
Re: Editor with embedded perl interpreter? <lap76@19yahoo.com>
Re: Editor with embedded perl interpreter? <john@castleamber.com>
Re: Perl -> My SQL - Tutorial or Guide? <noemail@nothere.com>
Perl equivalent of simple awk script <usenet@sta.samsung.com>
Re: Perl equivalent of simple awk script <someone@example.com>
Re: Perl equivalent of simple awk script <tadmc@seesig.invalid>
Re: Perl equivalent of simple awk script <someone@example.com>
Re: Perl equivalent of simple awk script sln@netherlands.com
Re: Removing Comma Within Digits <glennj@ncf.ca>
Re: Removing Comma Within Digits sln@netherlands.com
Re: Removing Comma Within Digits sln@netherlands.com
Re: Removing Comma Within Digits sln@netherlands.com
Re: Removing Comma Within Digits (fidokomik\)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 12 Nov 2008 11:32:24 -0600
From: Tux Tango <tux@nospam.ciuc.deu>
Subject: BigInt in per
Message-Id: <gff3v8$oh6$1@news.acm.uiuc.edu>
Hi,
I have a MSSQL database with bigint datatype. I am doing a simple SELECT
query and printing out the information:
my $qry = "SELECT C1, C2 FROM TABLE" ;
my $sth = $dbh->prepare($qry);
$sth->execute;
while(my @row = $sth->fetchrow_array) {
print "$row[0]\t$row[1]\n";
}
OUTPUT:
954925604786 1.00000000076029e+15
954925505262 1.00000000076023e+15
954925581159 1.00000000076028e+15
954925581160 1.00000000076028e+15
954925421109 1.00000000076019e+15
954925574965 1.00000000076027e+15
110978984447583 1.00000000076031e+15
In the Database:
954925604786 1000000000760290
any idea, how to convert the output?
thanks.
--s
------------------------------
Date: Wed, 12 Nov 2008 22:43:35 +0000
From: RedGrittyBrick <RedGrittyBrick@spamweary.invalid>
Subject: Re: BigInt in per
Message-Id: <gffm6p$goh$1@news.eternal-september.org>
Tux Tango wrote:
> Hi,
>
> I have a MSSQL database with bigint datatype. I am doing a simple SELECT
> query and printing out the information:
>
>
> my $qry = "SELECT C1, C2 FROM TABLE" ;
> my $sth = $dbh->prepare($qry);
> $sth->execute;
> while(my @row = $sth->fetchrow_array) {
> print "$row[0]\t$row[1]\n";
> }
>
> OUTPUT:
>
> 954925604786 1.00000000076029e+15
> 954925505262 1.00000000076023e+15
> 954925581159 1.00000000076028e+15
> 954925581160 1.00000000076028e+15
> 954925421109 1.00000000076019e+15
> 954925574965 1.00000000076027e+15
> 110978984447583 1.00000000076031e+15
>
>
> In the Database:
> 954925604786 1000000000760290
>
>
> any idea, how to convert the output?
>
Maybe you are looking for printf?
--
RGB
------------------------------
Date: Thu, 13 Nov 2008 00:04:47 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: determine when to change to or from daylight savings time
Message-Id: <gffr63.1f8.1@news.isolution.nl>
Ted Byers schreef:
> The documentation for DateTime::TimeZone doesn't say
> which version of the Olson data it uses, so I can't be sure it uses
> the current Olson data unless someone can confirm that.
DateTime::TimeZone::Catalog->OlsonVersion()
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Wed, 12 Nov 2008 21:48:31 +0100
From: Paolo <lap76@19yahoo.com>
Subject: Editor with embedded perl interpreter?
Message-Id: <op.ukixe5wv4j0i0k@fsa1300>
I don't remember the name of this application for Windows but i've
make use of that once.
Do you know an editor which allows the execution of Perl-script
on selected text?
The Perl-script are in a submenu of the Tools menu.
---
THANX4URTIME!
------------------------------
Date: Wed, 12 Nov 2008 13:32:58 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Editor with embedded perl interpreter?
Message-Id: <6qimh4h3m325fqdia6lepele18g2f59sqq@4ax.com>
Paolo <lap76@19yahoo.com> wrote:
>I don't remember the name of this application for Windows but i've
>make use of that once.
>
>Do you know an editor which allows the execution of Perl-script
>on selected text?
A namesake of yours just posted exactly the same question in the
deprecated NG CLP. Maybe you can ask him to share the replies with you.
I won't type the same answer twice.
jue
------------------------------
Date: Wed, 12 Nov 2008 23:13:35 +0100
From: Paolo <lap76@19yahoo.com>
Subject: Re: Editor with embedded perl interpreter?
Message-Id: <op.uki1cxes4j0i0k@fsa1300>
> A namesake of yours just posted exactly the same question in the
> deprecated NG CLP. Maybe you can ask him to share the replies with you.
> I won't type the same answer twice.
Ok, i've posted this question in comp.lang.perl but this NG is *broken*
(?)...
hence i've posted also in CLPM. Your answer in CLP? ...but CLP is not
accessibile
on my news-server!
--
THANX
------------------------------
Date: 13 Nov 2008 01:27:32 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Editor with embedded perl interpreter?
Message-Id: <Xns9B54C5F3BAFD0castleamber@130.133.1.4>
Paolo <lap76@19yahoo.com> wrote:
> I don't remember the name of this application for Windows but i've
> make use of that once.
>
> Do you know an editor which allows the execution of Perl-script
> on selected text?
>
> The Perl-script are in a submenu of the Tools menu.
TextPad, see:
http://johnbokma.com/textpad/textpad-subversion.html
You can run a command on a selection.
And Emacs, of course.
--
John http://johnbokma.com/ - Hacking & Hiking in Mexico
Perl help in exchange for a gift:
http://johnbokma.com/perl/help-in-exchange-for-a-gift.html
------------------------------
Date: Wed, 12 Nov 2008 16:28:15 -0500
From: me <noemail@nothere.com>
Subject: Re: Perl -> My SQL - Tutorial or Guide?
Message-Id: <oiimh4d0oo9bqvnsu9ht1ga664s1bcaaks@4ax.com>
Thanks boys, plenty to get me started.
------------------------------
Date: Wed, 12 Nov 2008 13:01:46 -0800 (PST)
From: Generic Usenet Account <usenet@sta.samsung.com>
Subject: Perl equivalent of simple awk script
Message-Id: <4a48a014-f518-45f7-b3a9-e740a21c81b6@e1g2000pra.googlegroups.com>
Hi,
I am an old hat who is still living in the grep, sed, awk era. I am
trying to come up to speed with Perl since I am told that my toolkit
is completely outdated. I would appreciate if someone could help me
with a Perl equivalent of the following extremely simple awk command:
awk '/pattern/ {print $1 "-" $2 "-" $3 "\t" $NF}' inputfile
Thanks,
Larry
------------------------------
Date: Wed, 12 Nov 2008 13:31:16 -0800
From: "John W. Krahn" <someone@example.com>
Subject: Re: Perl equivalent of simple awk script
Message-Id: <zWHSk.6863$xj4.3494@newsfe01.iad>
Generic Usenet Account wrote:
>
> I am an old hat who is still living in the grep, sed, awk era. I am
> trying to come up to speed with Perl since I am told that my toolkit
> is completely outdated. I would appreciate if someone could help me
> with a Perl equivalent of the following extremely simple awk command:
>
> awk '/pattern/ {print $1 "-" $2 "-" $3 "\t" $NF}' inputfile
perl -lane'/pattern/ && print "$F[0]-$F[1]-$F[2]\t$."' inputfile
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 short order. -- Larry Wall
------------------------------
Date: Wed, 12 Nov 2008 15:26:33 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Perl equivalent of simple awk script
Message-Id: <slrnghmig9.alv.tadmc@tadmc30.sbcglobal.net>
["Followup-To:" header set to comp.lang.perl.misc.]
Generic Usenet Account <usenet@sta.samsung.com> wrote:
> I am an old hat who is still living in the grep, sed, awk era. I am
> trying to come up to speed with Perl since I am told that my toolkit
> is completely outdated. I would appreciate if someone could help me
> with a Perl equivalent of the following extremely simple awk command:
>
> awk '/pattern/ {print $1 "-" $2 "-" $3 "\t" $NF}' inputfile
The perl distribution ships with an awk-to-perl translater:
man a2p
When I try it on your program, it outputs:
---------------------------
#!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if $running_under_some_shell;
# this emulates #! processing on NIH machines.
# (remove #! line above if indigestible)
eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_0-9]+=)(.*)/ && shift;
# process any FOO=bar switches
$[ = 1; # set array base to 1
$, = ' '; # set output field separator
$\ = "\n"; # set output record separator
while (<>) {
@Fld = split(' ', $_, -1);
if (/pattern/) {
print $Fld[1] . '-' . $Fld[2] . '-' . $Fld[3] . "\t" . $Fld[$#Fld];
}
}
---------------------------
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Wed, 12 Nov 2008 15:41:39 -0800
From: "John W. Krahn" <someone@example.com>
Subject: Re: Perl equivalent of simple awk script
Message-Id: <OQJSk.4415$Gm3.1688@newsfe01.iad>
John W. Krahn wrote:
> Generic Usenet Account wrote:
>>
>> I am an old hat who is still living in the grep, sed, awk era. I am
>> trying to come up to speed with Perl since I am told that my toolkit
>> is completely outdated. I would appreciate if someone could help me
>> with a Perl equivalent of the following extremely simple awk command:
>>
>> awk '/pattern/ {print $1 "-" $2 "-" $3 "\t" $NF}' inputfile
>
> perl -lane'/pattern/ && print "$F[0]-$F[1]-$F[2]\t$."' inputfile
Correction, that should be:
perl -lane'/0/ && print "$F[0]-$F[1]-$F[2]\t$F[-1]"' inputfile
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 short order. -- Larry Wall
------------------------------
Date: Thu, 13 Nov 2008 01:02:57 GMT
From: sln@netherlands.com
Subject: Re: Perl equivalent of simple awk script
Message-Id: <0mumh41j7ro20pb9dn8qs27ide4j2h3pkb@4ax.com>
On Wed, 12 Nov 2008 13:01:46 -0800 (PST), Generic Usenet Account <usenet@sta.samsung.com> wrote:
>Hi,
>
>I am an old hat who is still living in the grep, sed, awk era. I am
>trying to come up to speed with Perl since I am told that my toolkit
>is completely outdated. I would appreciate if someone could help me
>with a Perl equivalent of the following extremely simple awk command:
>
> awk '/pattern/ {print $1 "-" $2 "-" $3 "\t" $NF}' inputfile
>
>Thanks,
>Larry
Awk says the pattern can be a conditional on the field data,
so it probably splits it up first. Although there is a $0 record
variable, so it depends on what when and where you wan't to
match.
Here is some very simple examples. Complex splitting can be done
using regular expressions for delemeter determination as well.
You can also forego split and parse the record fields with
a custom regular expression. I always thought DB's were
a better processor for records though.
Welcome to Perl.
sln
------------------------
use strict;
use warnings;
my @fld = ();
my ($pattern, $record) = ('w', '');
while ($record = <DATA>)
{
if ($record =~ /$pattern/)
{
# split fields up on white spaces (like awk)
@fld = split (' ', $record);
# do error checking, expected number of fields,
# more matching of field data, etc..
# ..
# print out some stuff
print "#1 - $fld[0]-$fld[1]-$fld[2]\t$fld[$#fld]\n";
}
# or
if ((@fld = split (' ', $record)) > 3 && $fld[3] eq $pattern)
{
print "#2 - $fld[0]-$fld[1]-$fld[2]\t$fld[$#fld]\n";
}
# or
if ((@fld = split (' ', $record)) > 3 && $fld[3] =~ /$pattern/)
{
print "#3 - $fld[0]-$fld[1]-$fld[2]\t$fld[$#fld]\n";
}
# or
if ((@fld = split (' ', $record)) > 3 && $fld[2] == 2007 && $fld[3] =~ /$pattern/)
{
print "#4 - $fld[0]-$fld[1]-$fld[2]\t$fld[$#fld]\n";
}
# or
if ((@fld = split (' ', $record)) > 4)
{
print "#5 - there are ".@fld." fields in this record\n";
}
}
__DATA__
Jan 20 2007 w
Jan 21 2007 w
Jan 22 2007 l
Jan 23 2008 w
Jan 24 2008 l
Jan 25 2008 l
Jan 26 2008 w extra
Jan 27 2008 l extra
Jan 28 2008 w extra
------------------------------
Date: 12 Nov 2008 17:02:38 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: Removing Comma Within Digits
Message-Id: <slrnghm31f.oql.glennj@smeagol.ncf.ca>
At 2008-11-12 10:29AM, "yccheok" wrote:
> I should rephrase the topic,
>
> 1) Removing comma within a digit number, where that particular digit
> must in the middle of two string.
>
>
> "A",1,234,567,890,"A",123,456
>
> to
>
> "A",1,234,567,890,"A",123,456
ITIYM: to
"A",1234567890,"A",123,456
> the comma within the last 123 and 456 are just delimiter within a csv
> file. There is a bug in legacy data, where they located comma in
> digits, and place the digits in csv file.
So, you want to keep the first field and the last three fields, and then
join all the ones in the middle:
while (<DATA>) {
print "old: $_";
chomp;
my @new;
my @tmp = split /,/;
unshift(@new, pop @tmp) for (1..3);
unshift @new, shift @tmp;
splice @new, 1, 0, (join "",@tmp);
print "new: ", join(',', @new), "\n";
}
__DATA__
"A",1,234,567,890,"A",123,456
"A",1,234,567,"A",123,456
"A",1,234,"A",123,456
"A",3,"A",123,456
--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous
------------------------------
Date: Wed, 12 Nov 2008 17:12:10 GMT
From: sln@netherlands.com
Subject: Re: Removing Comma Within Digits
Message-Id: <as2mh452ud3qb4ol3ujucvli8jin8utbf7@4ax.com>
On Wed, 12 Nov 2008 05:30:23 -0800 (PST), yccheok <yancheng.cheok@gmail.com> wrote:
>Hi,
>
>I try to change the following source text
>
>"A",1,234,567,890,"A",123,456
>"A",1,234,567,"A",123,456
>"A",1,234,"A",123,456
>"A",3,"A",123,456
>
>i wish to change to
>
>"A",1234567890,"A",123,456
>"A",1234567,"A",123,456
>"A",1234,"A",123,456
>"A",3,"A",123,456
>
>By using the following regular expression :-
>
>",(\d{1,3})(,(\d{3}))+,"
>
>and the replacement
>
>",$1$3,"
>
>Here is the result I obtain :-
>
>"A",1890,"A"
>"A",1567,"A"
>"A",1234,"A"
>"A",3,"A"
>
>It seem that, I wish to have one or more $3. How can I specific that
>in my code?
>
>Thanks!
You almost got it with that regexp. Have to replace back the items
that don't change in the substitution. As well you have to itterate
the substitution with a while to reset the posision to the beginning.
Each pass starts from the beginning and basically is stripping out a ','
past the first continuous digits. This all works because of the
delimeters ", and ,". However there are other ways of doing it as well.
sln
-----------------------------
use strict;
use warnings;
# output:
# "A",1234567890,"A",123,456
# "A",1234567,"A",123,456
# "A",1234,"A",123,456
# "A",3,"A",123,456
while (<DATA>)
{
while (s/(",)(\d+),([\d,]*?)(,")/$1$2$3$4/) {}
print $_;
}
__DATA__
"A",1,234,567,890,"A",123,456
"A",1,234,567,"A",123,456
"A",1,234,"A",123,456
"A",3,"A",123,456
------------------------------
Date: Wed, 12 Nov 2008 17:31:47 GMT
From: sln@netherlands.com
Subject: Re: Removing Comma Within Digits
Message-Id: <pd4mh4hfmrc371004iupda44gl92sefgom@4ax.com>
On Wed, 12 Nov 2008 07:29:16 -0800 (PST), yccheok <yancheng.cheok@gmail.com> wrote:
>I should rephrase the topic,
>
>1) Removing comma within a digit number, where that particular digit
>must in the middle of two string.
>
>
>"A",1,234,567,890,"A",123,456
>
>to
>
>"A",1,234,567,890,"A",123,456
>
>the comma within the last 123 and 456 are just delimiter within a csv
>file. There is a bug in legacy data, where they located comma in
>digits, and place the digits in csv file.
>
>sub nocomma { (my $s=shift) =~ y/,//d; $s }
>
>(my $mod_text = $source_text) =~ s/(?<=",)([^"]+)(?=,")/nocomma($1)/
>mge;
>
>seems a nice solution. but any way i may eliminate two pass pattern
>matching?
>
Don't top post.
IMO because you have the anchor strings there is no way you can remove
the comma's without a minimum of 2 match operations. Its not an open
repeatible pattern, there is a sub-pattern.
This method is actually pretty good. You may wan't to benchmark if you
are worried about performance. I don't see that as an issue with the
simple thing you are doing here.
sln
------------------------------
Date: Wed, 12 Nov 2008 18:23:25 GMT
From: sln@netherlands.com
Subject: Re: Removing Comma Within Digits
Message-Id: <tk7mh4pahhd92edi9nr7ol7nucv6t5vr65@4ax.com>
On Wed, 12 Nov 2008 17:12:10 GMT, sln@netherlands.com wrote:
>On Wed, 12 Nov 2008 05:30:23 -0800 (PST), yccheok <yancheng.cheok@gmail.com> wrote:
>
>>Hi,
>>
>>I try to change the following source text
>>
>>"A",1,234,567,890,"A",123,456
>>"A",1,234,567,"A",123,456
>>"A",1,234,"A",123,456
>>"A",3,"A",123,456
>>
>>i wish to change to
>>
>>"A",1234567890,"A",123,456
>>"A",1234567,"A",123,456
>>"A",1234,"A",123,456
>>"A",3,"A",123,456
>>
>>By using the following regular expression :-
>>
>>",(\d{1,3})(,(\d{3}))+,"
>>
>>and the replacement
>>
>>",$1$3,"
>>
>>Here is the result I obtain :-
>>
>>"A",1890,"A"
>>"A",1567,"A"
>>"A",1234,"A"
>>"A",3,"A"
>>
>>It seem that, I wish to have one or more $3. How can I specific that
>>in my code?
>>
>>Thanks!
>
[snip]
Actually, the only way to do it in one pass is something
like this:
s/(",|),?(\d+|)(,".*|)/$1$2$3/g;
>-----------------------------
>use strict;
>use warnings;
>
># output:
># "A",1234567890,"A",123,456
># "A",1234567,"A",123,456
># "A",1234,"A",123,456
># "A",3,"A",123,456
>
>
>while (<DATA>)
>{
s/(",|),?(\d+|)(,".*|)/$1$2$3/g;
> print $_;
>}
>
>__DATA__
>"A",1,234,567,890,"A",123,456
>"A",1,234,567,"A",123,456
>"A",1,234,"A",123,456
>"A",3,"A",123,456
>
>
------------------------------
Date: Thu, 13 Nov 2008 02:41:39 +0100
From: "Petr Vileta \(fidokomik\)" <stoupa@practisoft.cz>
Subject: Re: Removing Comma Within Digits
Message-Id: <gfg0oe$2f48$1@ns.felk.cvut.cz>
yccheok wrote:
> Hi,
>
> I try to change the following source text
>
> "A",1,234,567,890,"A",123,456
> "A",1,234,567,"A",123,456
> "A",1,234,"A",123,456
> "A",3,"A",123,456
>
> i wish to change to
>
> "A",1234567890,"A",123,456
> "A",1234567,"A",123,456
> "A",1234,"A",123,456
> "A",3,"A",123,456
>
Try this
while (<DATA>)
{
s/^(\D+)(\d+),*(\d*),*(\d*),*(\d*),*(\d*),(\d*),*(\d*)(,\D+.+)$/$1$2$3$4$5$6$7$8$9/;
print;
}
__DATA__
"A",1,234,567,890,"A",123,456
"A",1,234,567,"A",123,456
"A",1,234,"A",123,456
"A",3,"A",123,456
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail.
Send me your mail from another non-spammer site please.)
Please reply to <petr AT practisoft DOT cz>
------------------------------
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 V11 Issue 1979
***************************************