[25635] in Perl-Users-Digest
Perl-Users Digest, Issue: 7877 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 11 00:05:42 2005
Date: Thu, 10 Mar 2005 21:05:12 -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 Thu, 10 Mar 2005 Volume: 10 Number: 7877
Today's topics:
Re: [perl-python] a program to delete duplicate files <pu.news.001@gmail.com>
Re: [perl-python] a program to delete duplicate files <eppstein@ics.uci.edu>
Re: code and messages <No_4@dsl.pipex.com>
Re: DBI and Microsoft Access <pilkowsk@informatik.uni-marburg.de>
Re: Formatting a single line without effecting the enti <tadmc@augustmail.com>
Re: Formatting a single line without effecting the enti <pilkowsk@informatik.uni-marburg.de>
Re: forms suddenly stopped working <tadmc@augustmail.com>
Re: gtk + png <mbosowo@gmail.com>
How to wrap DBI $sth object? <vito_corleone@godfather.com>
Re: include external perl program <tadmc@augustmail.com>
Re: One Liner to reverse sort file <notvalid@email.com>
Re: One Liner to reverse sort file <tadmc@augustmail.com>
Re: One Liner to reverse sort file <jl_post@hotmail.com>
Re: One Liner to reverse sort file <groleau+news@freeshell.org>
Re: perl contribution <postmaster@castleamber.com>
Re: perl contribution <postmaster@castleamber.com>
Re: shmem & complex data? <dkoleary@olearycomputers.com>
Time Conversion eswms@alltel.net
Re: Time Conversion <jgibson@mail.arc.nasa.gov>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 11 Mar 2005 01:24:59 +0100
From: Patrick Useldinger <pu.news.001@gmail.com>
Subject: Re: [perl-python] a program to delete duplicate files
Message-Id: <4230e55b$1@news.vo.lu>
Christos TZOTZIOY Georgiou wrote:
> That's fast and good.
Nice to hear.
> A minor nit-pick: `fdups.py -r .` does nothing (at least on Linux).
I'll look into that.
> Have you found any way to test if two files on NTFS are hard linked without
> opening them first to get a file handle?
No. And even then, I wouldn't know how to find out.
-pu
------------------------------
Date: Thu, 10 Mar 2005 20:32:56 -0800
From: David Eppstein <eppstein@ics.uci.edu>
Subject: Re: [perl-python] a program to delete duplicate files
Message-Id: <eppstein-31AD8D.20325610032005@news.service.uci.edu>
In article <1110372973.657649.212920@l41g2000cwc.googlegroups.com>,
"Xah Lee" <xah@xahlee.org> wrote:
> a absolute requirement in this problem is to minimize the number of
> comparison made between files. This is a part of the spec.
You need do no comparisons between files. Just use a sufficiently
strong hash algorithm (SHA-256 maybe?) and compare the hashes.
--
David Eppstein
Computer Science Dept., Univ. of California, Irvine
http://www.ics.uci.edu/~eppstein/
------------------------------
Date: Thu, 10 Mar 2005 23:53:39 +0000
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: code and messages
Message-Id: <2tSdnX7WjoKeQ63fRVnytQ@pipex.net>
Me wrote:
>
> What I would to find out is not neccesarily perl specific. But, perl is
> what I am focusing on. What tools/methods are available to allow for
> separation of "visible end user text" and code? I currently use template
> to seperate code from design, that is not what I am looking for?
Well, something non-Perl specific and relativley easy to implement in
Perl (and then use the same message from any other language).
Put every message and mail message into a file whose name is mnemonic,
then just read the contensts of that file name when required. Write a
module to do the getting.
> Taking it a step further, would be to say can I also get translation as
> well so that messages are not just in English? This is just a nice to have.
Allow for the files to be in a deault dir, or one named on after the
locale.
Ths is the sort of thing which gettext does, but it would be qute easy
to implement on its own.
--
Just because I've written it doesn't mean that
either you or I have to believe it.
------------------------------
Date: Fri, 11 Mar 2005 01:41:49 +0100
From: Fabian Pilkowski <pilkowsk@informatik.uni-marburg.de>
Subject: Re: DBI and Microsoft Access
Message-Id: <MPG.1c9b07b81107a0fe9898ca@news.individual.de>
* nathaniel_welch@hotmail.com wrote:
>
> > What happens when you remove $dbh = DBI->connect("dbi:ODBC:recruit");
> > from your code?
>
> When I remove or comment that line, the code works fine. It prints
> test1 and then test2 to the screen.
Hence there must be a problem with that line. So far you've posted the
error which will be displayed in your browser. This one was generated by
your webserver because your script hadn't returned a correct output.
Have a look into your webserver's errorlog to find out the errormessage
generated by your script.
Furthermore, you can add the line
use CGI::Carp qw( fatalsToBrowser );
to your script wherethrough all *your* errors will be redirected to your
browser. Especially while writing a script this could be helpful.
>
> And, by the way, the error doesn't change whether I use single or
> double quotes around the arguments for the connect.
When initializing a string you can use single or double quotes. Within
double quotes all vars will be interpolated (i.e. replaced by their
values), but not within single ones. Since you've no vars inside your
string you can't see any effect here.
regards,
fabian
------------------------------
Date: Thu, 10 Mar 2005 17:43:22 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Formatting a single line without effecting the entire table with the Text::Table module
Message-Id: <slrnd31msq.g6j.tadmc@magna.augustmail.com>
Mothra <lynn.watts@ugs.com> wrote:
> if ( !defined( $tmp_people->[0] ) ) { $tmp_people->[0] = 0 }
Excessive punctuation is bad for your (mental) health:
$tmp_people->[0] = 0 unless defined $tmp_people->[0];
> if ( !defined( $tmp_people->[1] ) ) { $tmp_people->[1] = 0 }
> if ( !defined( $tmp_people->[2] ) ) { $tmp_people->[2] = 0 }
Gak! There are only 2 characters that are different between all
three of those lines, that indicates that it can be written better.
foreach ( 0 .. 2 ) {
$tmp_people->[$_] = 0 unless defined $tmp_people->[$_];
}
but that won't scale when you add a 4th tmp_people, so maybe:
foreach ( 0 .. $#{ $tmp_people } ) {
$tmp_people->[$_] = 0 unless defined $tmp_people->[$_];
}
but since foreach uses an alias, we can make it even simpler
by not doing the indexing ourselves, let perl do the indexing:
$_ = defined() ? $_ : 0 for @$tmp_people; # untested
or
for ( @$tmp_people ) {
$_ = defined() ? $_ : 0;
}
or
for ( @$tmp_people ) { # this would be my choice of replacement code
$_ = 0 unless defined;
}
> $manager_total{$managers}[0] += $people->{$managers}->{$person}[0];
> $manager_total{$managers}[1] += $people->{$managers}->{$person}[1];
> $manager_total{$managers}[2] += $people->{$managers}->{$person}[2];
When you see repeated patterns in code like that, it usually
means you can easily come up with a better design that doesn't
repeat so much.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 11 Mar 2005 03:43:09 +0100
From: Fabian Pilkowski <pilkowsk@informatik.uni-marburg.de>
Subject: Re: Formatting a single line without effecting the entire table with the Text::Table module
Message-Id: <MPG.1c9b241ae80c92069898cb@news.individual.de>
* Mothra wrote:
>=20
> I have a data structure (see script) that I need to printout. I almost
> have what I need but I cannot figure out how to format just one line
> (center it ) sample output is:
>=20
> kreimer
> EMMI CHRISTIAN 0 0 17
> TRACEY LUSBY 0 4 0
> TONA MCGEAN 0 7 0
> Total: 0 11 17
>=20
> What I would like is the word "kreimer" centered and the other names
> remain left justified. What am I doing wrong?
After reading this module's documentation i'm thinking there's no way to=20
format a few lines differently than others. Consider to use another=20
format to indicate such "captions". Perhaps something like indentions:
kreimer
EMMI CHRISTIAN 0 0 17
TRACEY LUSBY 0 4 0
TONA MCGEAN 0 7 0
Total: 0 11 17
>=20
> ----------script--------------
>=20
> foreach my $tmp_people( values %{ $people->{'OTHER'} } ) {
> if ( !defined( $tmp_people->[0] ) ) { $tmp_people->[0] =3D 0 }
> if ( !defined( $tmp_people->[1] ) ) { $tmp_people->[1] =3D 0 }
> if ( !defined( $tmp_people->[2] ) ) { $tmp_people->[2] =3D 0 }
> }
Since youre values are always numbers, this loop can be reduced to:
for ( values %{$people->{OTHER}} ) {
$_ ||=3D 0 for @$_;
}
For testing for definedness, I've heard about an =BB//=3D=AB operator that=
=20
will be introduced in Perl6, but here this should be sufficient.
>=20
> my %manager_total =3D ();
> foreach my $managers( keys %{$people} ) {
> foreach my $person( keys %{ $people->{$managers} } ) {
> $manager_total{$managers}[0] +=3D $people->{$managers}->{$person}=
[0];
> $manager_total{$managers}[1] +=3D $people->{$managers}->{$person}=
[1];
> $manager_total{$managers}[2] +=3D $people->{$managers}->{$person}=
[2];
> }
> }
For me, your style isn't as good as it could be. Try out:
my %manager_total =3D ();
for my $m ( keys %{$people} ) {
for my $p ( values %{$people->{$m}} ) {
for my $i ( 0 .. $#{$p} ) {
$manager_total{ $m }[ $i ] +=3D $p->[$i];
}
}
}
[...]
>=20
> foreach my $managers( keys %{$people} ) {
> $tb->add($managers);
>=20
> foreach my $person( sort Mysort keys %{ $people->{$managers} } ) {
>=20
> $tb->add( "$person", @{ $people->{$managers}->{$person} } );
^^^
Adding here two blanks will indenting these lines (see above).
>=20
>=20
> }
> $tb->add( "Total: ", @{ $manager_total{$managers} } );
> $tb->add();
On my system, adding *nothing* will produce the warning "Use of=20
uninitialized value in range (or flop) at Text/Table.pm line 380".=20
Perhaps you want to add a blank to generate a blank line
$tb->add( " " );
> }
>=20
> print $tb;
>=20
> sub Mysort {
>=20
> my ( undef, $first ) =3D split ( / /, $a );
> my ( undef, $last ) =3D split ( / /, $b );
> $first cmp $last;
>=20
> }
I'd write this as
sub Mysort {
(split / /, $a)[1] cmp (split / /, $b)[1]
}
but I don't think every proposal above results in better readability.=20
This might depending on one's individual flair.
regards,
fabian
------------------------------
Date: Thu, 10 Mar 2005 17:47:09 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: forms suddenly stopped working
Message-Id: <slrnd31n3t.g6j.tadmc@magna.augustmail.com>
Bill <bspratt@yahoo.com> wrote:
> <form
> method="post" action="cgi-bin/formmail.pl" onsubmit="return
> validateForm(this)">
> It must be our actual html (xhtml)
> forms.
Neither HTML or XHTML is Perl, you are in the Perl newsgroup you know...
Ask questions about Perl in the Perl newsgroup.
Ask questions about HTML in the HTML newsgroup.
> Anyone see anything wrong with the above code?
There was NO code in your article, only data.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 10 Mar 2005 15:14:06 -0800
From: "mboso" <mbosowo@gmail.com>
Subject: Re: gtk + png
Message-Id: <1110496446.021539.106090@l41g2000cwc.googlegroups.com>
Wow, you went above and beyond my friend. Thanks for the reply. Its a
great starting point. I'm partial to gtk, so I'll be porting it, but
this is definitely a big help.
Thanks again.
Mboso
------------------------------
Date: Fri, 11 Mar 2005 12:46:30 +0900
From: Vito Corleone <vito_corleone@godfather.com>
Subject: How to wrap DBI $sth object?
Message-Id: <20050311124630.147f7c68.vito_corleone@godfather.com>
Hi,
I want to make a module that execute the query and return the $sth in
wrapped form.
If you don't use the wrapper it would be like this:
## no_wrapper.pl
my $sth = $dbh->prepare("SELECT member_id, item_name FROM item");
$sth->execute();
while (my $row = $sth->fetchrow_arrayref()) {
print $row->[0];
pirnt $row->[1];
}
I want to wrap that, so I can write it like below:
## with_wrapper.pl
use Item;
my $it = Item::->new();
my $obj = $it->get_items(); ## This return $sth in wrapped form
while (my $item = $obj->each()) {
print $item->member_id();
print $item->item_name();
## etc
}
How should I write Item.pm, so it can be used as the wrapper above?
Could you please give some simple example, as I don't know where to
start. And thank you in advance.
Regards,
Vito
------------------------------
Date: Thu, 10 Mar 2005 18:32:54 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: include external perl program
Message-Id: <slrnd31ppm.g9h.tadmc@magna.augustmail.com>
alythh@netscape.net <alythh@netscape.net> wrote:
> good hint
What was a good hint?
It is customary to provide some context when composing a followup.
> Tad,
If you are following up to something that Tad said, then there
should be an ID of Tad's article in the References header.
Please don't break stuff like that. Learn how to make proper
followups.
I have followups that mention my article's IDs scored way up so
that I don't miss what other say about what I said.
I would never have even seen this followup of yours (due to
some "domainist" score rules) if I hadn't noticed it in
somebody else's subsequent followup, because it makes
no reference to any of my articles.
> but I found it slightly irritating in a point: the article dismisses
> any possible use of "local".
No it doesn't.
Did you read the Notes at the end? (the very first one)
It dismisses 97% of the possible uses of "local".
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 10 Mar 2005 23:08:37 GMT
From: Ala Qumsieh <notvalid@email.com>
Subject: Re: One Liner to reverse sort file
Message-Id: <Vr4Yd.16160$Pz7.6346@newssvr13.news.prodigy.com>
jl_post@hotmail.com wrote:
>>hogg wrote:
>>
>>>I was wondering if there was a one liner that would reverse
>>>order a file w/o having to write the output to another file.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> If I remember correctly, there was an even shorter solution given as
> an answer to a problem in Randal L. Schwartz & Tom Phoenix's book
> "Learning Perl":
>
> perl -e "print reverse <>"
>
> Quite elegant, in my opinion. :)
Except that it doesn't fulfill the OP's requirement of in-place editing
of the file.
--Ala
------------------------------
Date: Thu, 10 Mar 2005 17:55:14 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: One Liner to reverse sort file
Message-Id: <slrnd31nj2.g6j.tadmc@magna.augustmail.com>
hogg <don.hoggatt@pbsg.com> wrote:
> That works perfect.
^^^^
Which that is that that?
> Thanks for everyone that replied.
Please quote some context in followups.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 10 Mar 2005 17:05:20 -0800
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: One Liner to reverse sort file
Message-Id: <1110503120.724043.292210@z14g2000cwz.googlegroups.com>
> >>hogg wrote:
> >>
> >>>I was wondering if there was a one liner that would reverse
> >>>order a file w/o having to write the output to another file.
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
jl_post@hotmail.com replied:
>
> > If I remember correctly, there was an even shorter
> > solution given as an answer to a problem in
> > Randal L. Schwartz & Tom Phoenix's book "Learning Perl":
> >
> > perl -e "print reverse <>"
Ala Qumsieh replied:
>
> Except that it doesn't fulfill the OP's requirement of
> in-place editing of the file.
Oh, so in-place editing was what the original poster meant by
"without having to write the output to another file." (Before I
learned Perl, I would use sed and awk quite extensively. On occasion,
I would have to write out an intermediate file because of some logical
limitation that wouldn't let me chain awk and sed commands
indefinitely. I thought the original poster was talking about this
logical limitation. I was wondering why nobody had mentioned my
solution.)
To redeem myself, let me offer another solution, one that does what
I think the original poster wanted:
perl -pi -e 'unshift @a,$_; $_=""; print @a if eof' in.file
(I know that a solution isn't needed anymore, but I thought I might
offer yet another solution just for solution's sake.)
-- Jean-Luc
------------------------------
Date: Thu, 10 Mar 2005 21:35:39 -0500
From: Wes Groleau <groleau+news@freeshell.org>
Subject: Re: One Liner to reverse sort file
Message-Id: <39cef8F5v9kkgU1@individual.net>
>>>>>I was wondering if there was a one liner that would reverse
>>>>>order a file w/o having to write the output to another file.
>> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> Oh, so in-place editing was what the original poster meant by
> "without having to write the output to another file." (Before I
> [snip]
> To redeem myself, let me offer another solution, one that does what
> I think the original poster wanted:
>
> perl -pi -e 'unshift @a,$_; $_=""; print @a if eof' in.file
FWIW, perl in-place editing actually does write to a temporary file,
then renames it and deletes the original. Saves you the trouble of
writing explicit code for that, but that's what it does behind the
scenes. Anything that can stop you from doing it explicitly can stop
perl from doing it. (Full disk, for one example)
--
Wes Groleau
Armchair Activism: http://www.breakthechain.org/armchair.html
------------------------------
Date: 11 Mar 2005 03:57:08 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: perl contribution
Message-Id: <Xns9615DF4F8841Dcastleamber@130.133.1.4>
Josef Moellers wrote:
> John Bokma wrote:
>> Jay Tilton wrote:
>>
>>
>>>"robin" <robin@infusedlight.net> wrote:
>>>
>>>: I do have a contrubution
>>>
>>>To what are you contributing?
>>>
>>>: #!/usr/bin/perl
>>>: my $c=0; my @key;
>>>: my $key;
>>>: foreach ( sort %ENV)
>>>
>>>What on Earth are you doing that for?
>>
>> Greenhouse effect?
>
> You mean he took something from the greenhouse and smoked it?
Nah, he was messing with the ENVironment :-D.
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: 11 Mar 2005 03:57:58 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: perl contribution
Message-Id: <Xns9615DF7346DEBcastleamber@130.133.1.4>
Eric Bohlman wrote:
> John Bokma <postmaster@castleamber.com> wrote in
> news:Xns9614DFF5DC3F2castleamber@130.133.1.4:
>
>> Jay Tilton wrote:
>>
>>> "robin" <robin@infusedlight.net> wrote:
>>>
>>> : I do have a contrubution
>>>
>>> To what are you contributing?
>>>
>>> : #!/usr/bin/perl
>>> : my $c=0; my @key;
>>> : my $key;
>>> : foreach ( sort %ENV)
>>>
>>> What on Earth are you doing that for?
>>
>> Greenhouse effect?
>
> I thought that that was primarily due to carbon dioxide rather than
> methane.
I vaguely remember that a lot of methane also has a bad effect on %ENV.
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Fri, 11 Mar 2005 03:40:01 GMT
From: Doug O'Leary <dkoleary@olearycomputers.com>
Subject: Re: shmem & complex data?
Message-Id: <slrnd324i1.r1c.dkoleary@linux.attbi.com>
On 2005-03-07, Eric Schwartz <emschwar@pobox.com> wrote:
>
> Yes. You want to use any of the available session modules on CPAN to
> generate a unique session ID, and store all the complex data on the
> server, either in a file or database (there's always Cache::Mem, I
> suppose). When the user hits "submit", in your example, add the new
> host to the data structure on the server, and redirect to a url that
> displays the new information, which will draw on the data structure
> you stored on the server somehow, and so on.
Thanks for the tip. You got me on the right track. It took me
the better part of a day to get the html, session, javascript, and
cgi all working together, but I got it. Now that the fun part of
figuring out how to do it is done, it's time to get to the tedious
part of actually doing it.
Thanks again. That was a big help.
Doug
------------------------------
Date: 10 Mar 2005 17:16:40 -0800
From: eswms@alltel.net
Subject: Time Conversion
Message-Id: <1110503800.318936.10330@o13g2000cwo.googlegroups.com>
My Oracle (9i) (OS = Solaris 9) DB uses Unix time for most of its time
recording. Is there a way to, within Perl, translate Unix times to
Universal times when I display the input?
i.e. `echo "select date_time_created from dosr_study" | isql -St >
time`;
The time returned from the DB is Unix...Can I take that value and
display in UTC?
Thanks In Advance,
Scripter
------------------------------
Date: Thu, 10 Mar 2005 17:59:38 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Time Conversion
Message-Id: <100320051759389242%jgibson@mail.arc.nasa.gov>
In article <1110503800.318936.10330@o13g2000cwo.googlegroups.com>,
<eswms@alltel.net> wrote:
> My Oracle (9i) (OS = Solaris 9) DB uses Unix time for most of its time
> recording. Is there a way to, within Perl, translate Unix times to
> Universal times when I display the input?
>
> i.e. `echo "select date_time_created from dosr_study" | isql -St >
> time`;
>
> The time returned from the DB is Unix...Can I take that value and
> display in UTC?
Use gmtime($unixtime) to get components of UTC time from Unix time
value.
See
perldoc -f time
perldoc -f localtime
perldoc -f gmtime
and there are many, many date and time modules on CPAN, such as
Time::Format and DateTime.
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
------------------------------
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 7877
***************************************