[28976] in Perl-Users-Digest
Perl-Users Digest, Issue: 220 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 13 14:10:16 2007
Date: Tue, 13 Mar 2007 11:09:06 -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 Tue, 13 Mar 2007 Volume: 11 Number: 220
Today's topics:
Re: adding a data field to a subclass of HTML::Parser anno4000@radom.zrz.tu-berlin.de
Re: adding a data field to a subclass of HTML::Parser <bik.mido@tiscalinet.it>
Re: adding a data field to a subclass of HTML::Parser anno4000@radom.zrz.tu-berlin.de
Re: Convert hex to bin <wahab-mail@gmx.de>
Re: Convert hex to bin <bik.mido@tiscalinet.it>
Re: Convert hex to bin <wahab-mail@gmx.de>
Re: Convert hex to bin <uri@stemsystems.com>
Re: Convert hex to bin <wahab-mail@gmx.de>
Re: Equivalent in Perl <pankaj_wolfhunter@yahoo.co.in>
gluing client and server <blank@yahoo.com>
Re: gluing client and server <spamtrap@dot-app.org>
Re: How get cell count and match total column value <bik.mido@tiscalinet.it>
Re: how to do file1-file2? <tadmc@augustmail.com>
Re: passing passords to pgsql/pg_create/pg_dump program <filippo2991@virgilio.it>
Re: passing passords to pgsql/pg_create/pg_dump program <josef.moellers@fujitsu-siemens.com>
Random record access <dale.schmitz@offutt.af.mil>
Re: Random record access xhoster@gmail.com
Re: Random record access <dale.schmitz@offutt.af.mil>
Re: Random record access <dale.schmitz@offutt.af.mil>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 13 Mar 2007 11:53:03 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: adding a data field to a subclass of HTML::Parser
Message-Id: <55nhkvF25ej4vU1@mid.dfncis.de>
Michele Dondi <bik.mido@tiscalinet.it> wrote in comp.lang.perl.misc:
> On 12 Mar 2007 21:51:39 GMT, anno4000@radom.zrz.tu-berlin.de wrote:
>
> > use Hash::Util::FieldHash;
> [snip]
> >> my %names;
> >
> > Hash::Util::FieldHash::fieldhash my %names;
>
> This is all very cool, I only wonder whether it could be made into a
> syntactically sweeter form.
Absolutely. I'm working on it.
> For example I'm not familiar with
> attributes at all, so I don't know if this is plainly utter nonsense,
> but how about something like
>
> my %names : field; # ?
Using attributes is an attractive method for that.
I have gone another way and built a pragmatic module "xfields" (somewhat
similar to the existing "fields") that facilitates the creation of
FieldHash based classes. It isn't quite done yet, but I have put a
workable version up on
http://www.tu-berlin.de/zrz/mitarbeiter/anno4000/xfields/
You can read the pod there or download the tarball and play with
it (you'll need a new-ish version (>= 5.9.4) of bleadperl for that).
See below for a usage example.
I'm still struggling with design issues. I want to make it as simple
as possible, but it's oh-so-hard to decide which features will be
useful and which are going to be cruft. Even a re-design based on
attributes, the way you suggested, isn't out of the question.
On the other hand, I have core ambitions for the module. If I don't
get it done RSN, it'll be too late for 5.10 (if it isn't already).
Anno
PS: From the Examples section of the xfields pod:
#!/usr/local/bin/bleadperl
package Bottle;
use xfields -rw => qw( material cap content);
sub describe {
my $bottle = shift;
my $state = $bottle->cap ? '' : 'n open';
my $descr = "This is a$state " . $bottle->material . ' bottle';
$descr .= ' with a ' . $bottle->cap . ' cap' if $bottle->cap;
$descr .= ".";
if ( my $content = $bottle->content ) {
$descr .= " It contains $content."
} else {
$descr .= " It is empty.";
}
print "$descr\n";
$bottle;
}
package main;
my $bottle = Bottle->new(
material => 'glass',
);
$bottle->describe;
$bottle->cap = 'red screw-on';
$bottle->content = 'water';
$bottle->describe;
$bottle->material = 'clear plastic';
$bottle->cap =~ s/screw-on/plastic/;
$bottle->content = 'a brown sticky liquid, probably Coca Cola';
$bottle->describe;
__END__
------------------------------
Date: Tue, 13 Mar 2007 13:42:50 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: adding a data field to a subclass of HTML::Parser
Message-Id: <rv6dv2dv88ec3u303u8mj5q22kfcpd9fig@4ax.com>
On 13 Mar 2007 11:53:03 GMT, anno4000@radom.zrz.tu-berlin.de wrote:
>> This is all very cool, I only wonder whether it could be made into a
>> syntactically sweeter form.
>
>Absolutely. I'm working on it.
TY for the detailed explanations.
>On the other hand, I have core ambitions for the module. If I don't
>get it done RSN, it'll be too late for 5.10 (if it isn't already).
Then don't lose time answering me, just get it done!! ;-)
Good luck,
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 13 Mar 2007 17:07:33 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: adding a data field to a subclass of HTML::Parser
Message-Id: <55o42lF262pa1U1@mid.dfncis.de>
Michele Dondi <bik.mido@tiscalinet.it> wrote in comp.lang.perl.misc:
> On 13 Mar 2007 11:53:03 GMT, anno4000@radom.zrz.tu-berlin.de wrote:
>
> >> This is all very cool, I only wonder whether it could be made into a
> >> syntactically sweeter form.
> >
> >Absolutely. I'm working on it.
>
> TY for the detailed explanations.
>
> >On the other hand, I have core ambitions for the module. If I don't
> >get it done RSN, it'll be too late for 5.10 (if it isn't already).
>
> Then don't lose time answering me, just get it done!! ;-)
Ah, no. That's the one great thing about this kind of software work
that it goes at *my* pace. If I lose a chance to make my code more
popular, so what? It can always go on CPAN. The world will have to
make do without xfields until I am satisfied.
Anno
------------------------------
Date: Tue, 13 Mar 2007 13:20:18 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: Convert hex to bin
Message-Id: <et658d$f5v$1@mlucom4.urz.uni-halle.de>
Mumia W. wrote:
> On 03/12/2007 12:49 PM, Mirco Wahab wrote:
>> another possibility would be:
>> ...
>>
>> sub hex2bin {
>> base_convert (shift), 16, 2
>> }
>>
>> ...
>> (OK, I said "possibility") ...
>
> That's interesting. What module is "base_convert" a part of?
> Yahoo-ing online, I've been able to find a base_convert() for PHP, but
> not for Perl.
I wrote this because *I think* such
a simple number base conversion
'core functionality' is missing
from Perl (but is available in
PHP).
There is a module Math::BaseCalc
which appears to do that - but
doesn't work that intuitive (no core).
The interface would be like (fictional):
use Numbers::Base qw 'convert'; # core
sub my_hex2bin {
convert (shift), 16, 2
}
Maybe there is already something
appropriate I missed? Perl6?
Regards
Mirco
------------------------------
Date: Tue, 13 Mar 2007 13:35:21 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Convert hex to bin
Message-Id: <9h6dv2hviovos2dsdp9uf6msj0oougrlhj@4ax.com>
On Tue, 13 Mar 2007 10:04:08 GMT, "Mumia W."
<paduille.4060.mumia.w+nospam@earthlink.net> wrote:
>> sub hex2bin {
>> base_convert (shift), 16, 2
>> }
[snip]
>That's interesting. What module is "base_convert" a part of?
I thought it was a joke. Of course, I would have written it like
sub hex2bin {
base_convert +(shift), 16, 2;
}
or
sub hex2bin {
base_convert shift, 16, 2;
}
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Tue, 13 Mar 2007 13:20:38 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: Convert hex to bin
Message-Id: <et66ve$fi1$2@mlucom4.urz.uni-halle.de>
Mumia W. wrote:
> That's interesting. What module is "base_convert" a part of?
>
> Yahoo-ing online, I've been able to find a base_convert() for PHP, but
> not for Perl.
I wrote this because *I think* such
a simple number base conversion
'core functionality' is missing
from Perl (but is available in
PHP).
There is a module Math::BaseCalc
which appears to do that - but
doesn't work that intuitive (no core).
The interface would be like (fictional):
use Numbers::Base qw 'convert'; # core
sub my_hex2bin {
convert shift, 16, 2
}
Maybe there is already something
appropriate I missed? Perl6?
Regards
Mirco
------------------------------
Date: Tue, 13 Mar 2007 09:39:09 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Convert hex to bin
Message-Id: <x7r6rtrywi.fsf@mail.sysarch.com>
>>>>> "MW" == Mumia W <paduille.4060.mumia.w+nospam@earthlink.net> writes:
>> sub hex2bin {
>> base_convert (shift), 16, 2
>> }
MW> That's interesting. What module is "base_convert" a part of?
MW> Yahoo-ing online, I've been able to find a base_convert() for PHP, but
MW> not for Perl.
check Math::BaseCnv (on cpan) and its cnv() function. it will convert
any base number to any base and also do some smart guessing for you. and
it can export some common variation subs too.
i just discovered it while helping a client with hex to base36
conversions.
as for having general base conversions in core, let php have the
bloat. perl already can convert between binary, octal, decimal and hex
in core and in multiple ways (sprintf, hex, oct, pack/unpack). the rest
should be a module as it is.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Tue, 13 Mar 2007 16:26:08 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: Convert hex to bin
Message-Id: <et6g6s$i81$1@mlucom4.urz.uni-halle.de>
Uri Guttman wrote:
> check Math::BaseCnv (on cpan) and its cnv() function. it will convert
> any base number to any base and also do some smart guessing for you. and
> it can export some common variation subs too.
Thanks for that hint (why didn't I find it?) ...
> i just discovered it while helping a client with
> hex to base36 conversions.
Good.
> as for having general base conversions in core, let php have
> the bloat. perl already can convert between binary, octal,
> decimal and hex in core and in multiple ways (sprintf, hex,
> oct, pack/unpack). the rest should be a module as it is.
OK, you like it as it is. But to have a "central
conversion" location in core, which does the obvious
things (hex, oct etc.) if possible and "digs deep"
if necessary - wouldn't be that bad imho.
With this in mind, the OP could have used
for example
...
use Math::BaseCnv;
sub base_convert {
cnv @_
}
my $hnum = '7D';
my $bnum = base_convert $hnum, 16, 2;
printf "%0*s", 4*length($hnum), $bnum;
...
Regards & thanks
Mirco
------------------------------
Date: 13 Mar 2007 08:17:34 -0700
From: "pankaj_wolfhunter@yahoo.co.in" <pankaj_wolfhunter@yahoo.co.in>
Subject: Re: Equivalent in Perl
Message-Id: <1173799053.913459.15340@h3g2000cwc.googlegroups.com>
On Mar 13, 2:32 pm, Ian Wilson <scoblo...@infotop.co.uk> wrote:
> pankaj_wolfhun...@yahoo.co.in wrote:
>
> > here's the code I used:
>
> > #!/usr/bin/perl -w
>
> > use DBI;
>
> > $dbh = DBI->connect("DBI:Oracle:ndmid","ssatyasa","ssatyasa") || die
> > "Database Connection not Made : $DBI::errstr\n";
>
> > ### Prepare a SQL statement for execution $sth = $dbh->prepare(
> > "SELECT SYSDATE FROM DUAL1" );
>
> > ### Execute the statement in the database $sth->execute( );
> > $sth->finish(); $dbh->disconnect();
>
> > I tried redirecting using STDERR but just couldnt make it work. What
> > to put and exactly where?
>
> Since you are apparently unable to use Google, I did it for you. I typed
> in "perl DBI example" and looked at the first item returned. I recommend
> you get into the habit of using Google.
>
> http://www.saturn5.com/~jwb/dbi-examples.htmlhas this example
>
> ------------------------------------8<--------------------------------
> use strict;
> use DBI;
>
> my $dbh = DBI->connect( 'dbi:Oracle:orcl',
> 'jeffrey',
> 'jeffspassword',
> {
> RaiseError => 1,
> AutoCommit => 0
> }
> ) || die "Database connection not made:
> $DBI::errstr";
>
> my $sql = qq{ SELECT id, name, title, phone FROM employees };
> my $sth = $dbh->prepare( $sql );
> $sth->execute();
>
> my( $id, $name, $title, $phone );
> $sth->bind_columns( undef, \$id, \$name, \$title, \$phone );
>
> while( $sth->fetch() ) {
> print "$name, $title, $phone\n";
>
> }
>
> $sth->finish();
> $dbh->disconnect();
> ------------------------------------8<--------------------------------
>
> I'm assuming you know how to use Perl to open a file for writing and how
> to compose a perl "print" statement to write to a file. If not try using
> the perl documentattion by typing these commands:
> perldoc -f open
> perldoc -f print
>
> With that knowledge you can adapt the above example to write the SQL
> data to a file.- Hide quoted text -
>
> - Show quoted text -
Thanks Ian and thanks all.
Didnt know that I am asking something which is really bugging a lot of
ppl here.
Next time I gotta be a bit careful
Thanks again.
------------------------------
Date: Tue, 13 Mar 2007 15:30:46 +0100
From: Matija Papec <blank@yahoo.com>
Subject: gluing client and server
Message-Id: <et6ci4$69f$1@ss408.t-com.hr>
I would like to use older mysql client but unfortunately it doesn't
understand newer authentication, so plan is to make perl proxy which
should authenticate on mysql server and then transparently pass the
traffic through client and server sockets.
Some directions would be very appreciated since I only found dbiproxy
which can be used only with DBD::Proxy driver.
http://search.cpan.org/~timb/DBI-1.54/dbiproxy.PL
------------------------------
Date: Tue, 13 Mar 2007 12:21:50 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: gluing client and server
Message-Id: <m2zm6h15cx.fsf@local.wv-www.com>
Matija Papec <blank@yahoo.com> writes:
> I would like to use older mysql client but unfortunately it doesn't
> understand newer authentication
Configure the database to use old-style passwords. Problem solved.
<http://dev.mysql.com/doc/refman/5.0/en/old-client.html>
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Tue, 13 Mar 2007 18:21:53 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: How get cell count and match total column value
Message-Id: <hbndv25c4ikke0n712j7vtnan6v6u18glm@4ax.com>
On 12 Mar 2007 02:06:28 -0700, "Rahul" <sahoo.byomokesh@gmail.com>
wrote:
[snip]
>Thank you Michel. Many many thanks for quick response. I solved my
>problem. Thanks...thanks...
Just keep in mind that if you solved along the lines of what I did
suggest, as seems probable, then that is an UNRELIABLE solution. Do a
favour to yourself and don't plan on using it on a regular basis.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Tue, 13 Mar 2007 05:51:51 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: how to do file1-file2?
Message-Id: <slrnevd0i7.e3.tadmc@tadmc30.august.net>
robertchen117@gmail.com <robertchen117@gmail.com> wrote:
> my files contains all lines of host names, also file2.
>
> I want a shell could have the result : remove all the line in file1,
> if the line is in the file2.
grep -v -f file2 file1 >newfile
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 13 Mar 2007 03:11:49 -0700
From: "Filippo" <filippo2991@virgilio.it>
Subject: Re: passing passords to pgsql/pg_create/pg_dump programmatically
Message-Id: <1173780709.470125.315970@p10g2000cwp.googlegroups.com>
On 12 Mar, 19:01, "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
wrote:
> filippo wrote:
> > Hello,
> Read the documentation for those commands to determine how the user
> name and/or password is passed, then add the options and values to your
> program. Since you wrote the above code, you should be able to figure
> out how to add another option and value.
these commands don't accept password command line options, just put on
standard output the string "passord:" and read the standard input for
the value from user. I want to interact with them to pass the
information programmatically (redirect std input/output?).
Thanks,
Filippo
------------------------------
Date: Tue, 13 Mar 2007 11:16:38 +0100
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: passing passords to pgsql/pg_create/pg_dump programmatically
Message-Id: <et5tr2$1fg$1@nntp.fujitsu-siemens.com>
Filippo wrote:
> On 12 Mar, 19:01, "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
> wrote:
>=20
>>filippo wrote:
>>
>>>Hello,
>=20
>=20
>>Read the documentation for those commands to determine how the user
>>name and/or password is passed, then add the options and values to your=
>>program. Since you wrote the above code, you should be able to figure
>>out how to add another option and value.
>=20
>=20
> these commands don't accept password command line options, just put on
> standard output the string "passord:" and read the standard input for
> the value from user. I want to interact with them to pass the
> information programmatically (redirect std input/output?).
Have a look at Expect. Originally it's Tcl based, but a Perl port also=20
exists on CPAN.
--=20
These are my personal views and not those of Fujitsu Siemens Computers!
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: 13 Mar 2007 08:06:41 -0700
From: "Monty" <dale.schmitz@offutt.af.mil>
Subject: Random record access
Message-Id: <1173798401.043614.9760@t69g2000cwt.googlegroups.com>
Is there a strategy in Perl to randomly access a file of variable-
length records?
Thanks
------------------------------
Date: 13 Mar 2007 15:40:52 GMT
From: xhoster@gmail.com
Subject: Re: Random record access
Message-Id: <20070313114054.391$5F@newsreader.com>
"Monty" <dale.schmitz@offutt.af.mil> wrote:
> Is there a strategy in Perl to randomly access a file of variable-
> length records?
Many. "seek" and "tell". Tie::File (and many other Tie modules, I'm
sure). All kinds of *DB* modules, like DB_File and DBM::Deep.
And of course you could just slurp the file into an array or a hash,
if it isn't too big.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 13 Mar 2007 08:56:24 -0700
From: "Monty" <dale.schmitz@offutt.af.mil>
Subject: Re: Random record access
Message-Id: <1173801384.294617.160120@30g2000cwc.googlegroups.com>
The file could get big, so loading it up into memory probably isn't a
good idea. I forgot to mention that it's a text file, so I wonder if
that makes a difference. In the meantime I'll look into those
possibilities you gave me.
Thanks
------------------------------
Date: 13 Mar 2007 09:32:43 -0700
From: "Monty" <dale.schmitz@offutt.af.mil>
Subject: Re: Random record access
Message-Id: <1173803563.459535.90090@8g2000cwh.googlegroups.com>
It appears that Tie::File is juuuuuust what I'm looking for!
Thanks
------------------------------
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 220
**************************************