[28396] in Perl-Users-Digest
Perl-Users Digest, Issue: 9760 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Sep 24 14:05:48 2006
Date: Sun, 24 Sep 2006 11:05: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 Sun, 24 Sep 2006 Volume: 10 Number: 9760
Today's topics:
Re: An interactive interpreter/shell? <robb@acm.org>
Re: differences between hashes and arrays ? (Chris Mattern)
empty fields <awk@hotmail.com>
Re: empty fields <depesz@depesz.com>
Re: empty fields <nobull67@gmail.com>
Re: empty fields <nobull67@gmail.com>
Re: empty fields <nobull67@gmail.com>
Re: empty fields <nobull67@gmail.com>
Re: empty fields <see.sig@rochester.rr.com>
Re: FAQ 9.24 How do I fetch a news article or the activ <ed@noreply.com>
Re: Help with plotting <bik.mido@tiscalinet.it>
Re: Help with plotting <hjp-usenet2@hjp.at>
Re: Learning perl - for experienced programmers <cwilbur@mithril.chromatico.net>
New release of Config-Model, first draft for Xorg model <domi@komarr.grenoble.hp.com>
Re: Russel Quong's "Perl in 20 pages" <cwilbur@mithril.chromatico.net>
Re: Russel Quong's "Perl in 20 pages" (Randal L. Schwartz)
Re: submatch scoping in while <ced@blv-sam-01.ca.boeing.com>
Re: submatch scoping in while <noreply@gunnar.cc>
Re: tying db records and other objects, speed? <abigail@abigail.be>
Re: tying db records and other objects, speed? <skimba@dambo.di>
Re: tying db records and other objects, speed? <skimba@dambo.di>
Re: Zero equals pipe?? <bik.mido@tiscalinet.it>
Re: Zero equals pipe?? <see.sig@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 24 Sep 2006 03:07:33 -0700
From: "robb@acm.org" <robb@acm.org>
Subject: Re: An interactive interpreter/shell?
Message-Id: <1159092453.187584.84810@k70g2000cwa.googlegroups.com>
>
> perldoc -q shell
> Is there a Perl shell?
Thanks - that was helpful.
------------------------------
Date: Sun, 24 Sep 2006 15:52:25 -0000
From: syscjm@sumire.eng.sun.com (Chris Mattern)
Subject: Re: differences between hashes and arrays ?
Message-Id: <12hdadp337m2pf1@corp.supernews.com>
In article <ef3itu.rg.1@news.isolution.nl>, Dr.Ruud wrote:
>Chris Mattern schreef:
>> Jack:
>
>>> why arent folks using hashes instead of arrays since (I believe) they
>>> are faster to access and take up the same or less memory than
>>> arrays..
>>
>> Um, no, arrays are much more efficient than hashes.
>
>No, they are and they aren't. It all depends on what you use them for.
>
Well, yes, I meant on the lowest level of looking at expense
of doing a retrieval. Obviously trying to make an array do
the job of a hash would be very *in*efficient.
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
------------------------------
Date: Sun, 24 Sep 2006 12:18:11 +0200
From: Awkish <awk@hotmail.com>
Subject: empty fields
Message-Id: <45165b63$0$28403$ba620e4c@news.skynet.be>
Hi,
I must parse files of this form:
field1,,,field4,,field6,,,,,,
That is, the fields of each line are separated by a comma, and the fields
can be empty.
With awk I can do this:
awk -F, '{print $6; print NF}'
with the above line I get:
field6
12
and that's what I want
How can I get the same result with Perl?
I tried:
perl -F, 'print $F[5];print $#F+1'
which gives:
field6
5
Perl drops the "empty" fields after the last non-empty field :-(
------------------------------
Date: Sun, 24 Sep 2006 12:40:17 +0200
From: hubert depesz lubaczewski <depesz@depesz.com>
Subject: Re: empty fields
Message-Id: <ht3iu3-j8n.ln1@xxx.home.depesz.com>
On 2006-09-24, Awkish <awk@hotmail.com> wrote:
> Perl drops the "empty" fields after the last non-empty field :-(
=> perl -e 'use Data::Dumper; my $q = q{field1,,,field4,,field6,,,,,,}; my @w = split /,/, $q, -1; print Dumper(\@w);'
$VAR1 = [
'field1',
'',
'',
'field4',
'',
'field6',
'',
'',
'',
'',
'',
''
];
depesz
--
mój boże, spraw abym milczał, dopóki się nie upewnię, że naprawdę mam
coś do powiedzenia. (c) 1998 depesz
------------------------------
Date: 24 Sep 2006 04:47:04 -0700
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: empty fields
Message-Id: <1159098424.238683.62790@i42g2000cwa.googlegroups.com>
Awkish wrote:
> Hi,
> I must parse files of this form:
>
> field1,,,field4,,field6,,,,,,
>
>
> That is, the fields of each line are separated by a comma, and the fields
> can be empty.
>
> With awk I can do this:
>
> awk -F, '{print $6; print NF}'
>
> with the above line I get:
> field6
> 12
> and that's what I want
>
>
> How can I get the same result with Perl?
> I tried:
>
> perl -F, 'print $F[5];print $#F+1'
>
> which gives:
> field6
> 5
>
> Perl drops the "empty" fields after the last non-empty field :-(
Yes, this is a feature of the default beaviour of split() but can be
overidden by making the 3rd argument negative.
AFAIK there's no way to do this with autosplit so you need to spell it
out.
perl -ne '@F=split/,/,$_,-1; print $F[5];print $#F+1'
------------------------------
Date: 24 Sep 2006 06:09:02 -0700
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: empty fields
Message-Id: <1159103342.590536.30030@d34g2000cwd.googlegroups.com>
Brian McCauley wrote:
> perl -ne '@F=split/,/,$_,-1; print $F[5];print $#F+1'
Oops, forgot the chomp! There probably should be a chomp too.
perl -nle '@F=split/,/,$_,-1; print $F[5];print $#F+1'
------------------------------
Date: 24 Sep 2006 06:16:40 -0700
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: empty fields
Message-Id: <1159103800.183704.149970@k70g2000cwa.googlegroups.com>
Mumia W. (reading news) wrote:
> #!/bin/sh
>
> echo 'field1,,,field4,,field6,,,,,,' | \
> perl -wle '
> while (<>) {
> @F = split /,/, $_;
> print $F[5];
> print scalar @F;
> }
> '
You forgot to chomp(). (That's what made me realise I'd done so too in
another branch).
That'll be OK if $F[5] is not the last element but if any line in the
input has exactly 6 fields then you'll get an extra newline in the
output.
If you'd not forgotten to chomp() then you would have gotten away with
omitting the -1 on the split().
Note: If you use the -n switch with the -l switch Perl will insert the
chomp for you.
perl -wnle '
@F = split /,/, $_, -1;
print $F[5];
print scalar @F;
'
------------------------------
Date: 24 Sep 2006 06:18:27 -0700
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: empty fields
Message-Id: <1159103907.179301.159880@k70g2000cwa.googlegroups.com>
Brian McCauley wrote:
> If you'd not forgotten to chomp() then you would have gotten away with
> omitting the -1 on the split().
That should, of course, say "wouldn't have gotten away".
------------------------------
Date: Sun, 24 Sep 2006 16:21:02 GMT
From: Bob Walton <see.sig@rochester.rr.com>
Subject: Re: empty fields
Message-Id: <OfyRg.47844$uH6.18280@twister.nyroc.rr.com>
Awkish wrote:
...
> With awk I can do this:
>
> awk -F, '{print $6; print NF}'
>
> with the above line I get:
> field6
> 12
> and that's what I want
>
>
> How can I get the same result with Perl?
...
perldoc a2p
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: Sun, 24 Sep 2006 16:56:25 GMT
From: ed <ed@noreply.com>
Subject: Re: FAQ 9.24 How do I fetch a news article or the active newsgroups?
Message-Id: <20060924180212.61c29240@localhost.localdomain>
On Sun, 24 Sep 2006 06:03:02 -0700
PerlFAQ Server <brian@stonehenge.com> wrote:
> 9.24: How do I fetch a news article or the active newsgroups?
>
> Use the Net::NNTP or News::NNTPClient modules, both available from
> CPAN. This can make tasks like fetching the newsgroup list as
> simple as
>
> perl -MNews::NNTPClient
> -e 'print News::NNTPClient->new->list("newsgroups")'
OMG, I wrote some functionality thinking IO::Socket::INET would be
simple enough, it took an evening but I wish I'd looked in CPAN first...
heh, live and learn.
--
Regards, Ed :: http://www.s5h.net
just another linux hacker
Humpty Dumpty sat on the wall. Then Vin Diesel picked him up and used
him to egg the King's Castle.
------------------------------
Date: 24 Sep 2006 14:59:17 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Help with plotting
Message-Id: <s3tch2hmdn6s0b4khft3v32jok6lsg8jk2@4ax.com>
On 22 Sep 2006 09:54:57 -0600, Eric Schwartz <emschwar@pobox.com>
wrote:
>> OTOH they're sometimes too picky for my tastes. While developing
>> something on a debian box I had been needing a module which relied on
>> a certain package. I had a hard time trying to install and put the
>> module to work until I realized it wanted a -devel part of the package
>> too.
>
>But this is true of Redhat and Suse, or at least their enterprise
>distros, with which I have some passing familiarity. RHEL4 update 4
>has 255 -devel packages, each with its own non-devel. Offhand, I
>haven't checked how many packages don't have -devel equivalents, but
>it's clearly not uncommon there either.
To be fair, I wasn't fair. I apologize for that. The whole story is
available from
http://perlmonks.org/?node_id=472433
To cut it short, I was trying to install RRDTool::OO. This is not
surprisingly an OO interface to RRDtool. The latter is a single
software package which has its own perl interface, RRDs, also used by
R::O. In the end it all boiled down to the fact that Debian *splitted*
RRDtool into rrdtool and librrds-perl which provides RRDs, whereas I'd
like to underline that RRDs is part of the "core" RRDtool distro, and
not a separate add-on. So again, just a little bit too picky IMHO...
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: Sun, 24 Sep 2006 15:49:06 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Help with plotting
Message-Id: <slrnehd36i.cbi.hjp-usenet2@yoyo.hjp.at>
On 2006-09-24 12:59, Michele Dondi <bik.mido@tiscalinet.it> wrote:
> On 22 Sep 2006 09:54:57 -0600, Eric Schwartz <emschwar@pobox.com>
> wrote:
>
>>> OTOH they're sometimes too picky for my tastes. While developing
>>> something on a debian box I had been needing a module which relied on
>>> a certain package. I had a hard time trying to install and put the
>>> module to work until I realized it wanted a -devel part of the package
>>> too.
>>
>>But this is true of Redhat and Suse, or at least their enterprise
>>distros, with which I have some passing familiarity.
Yup.
> To cut it short, I was trying to install RRDTool::OO. This is not
> surprisingly an OO interface to RRDtool. The latter is a single
> software package which has its own perl interface, RRDs, also used by
> R::O. In the end it all boiled down to the fact that Debian *splitted*
> RRDtool into rrdtool and librrds-perl which provides RRDs, whereas I'd
> like to underline that RRDs is part of the "core" RRDtool distro, and
> not a separate add-on. So again, just a little bit too picky IMHO...
This is common for many Linux distributions. It is often the case that
some software consists of a library and some command-line tools. In this
case it is often split into three packages: A library package, which
contains the libraries and assorted files needed at run-time, a package
which contains the command line tools, and a devel-package, which
contains all the stuff which isn't needed at run-time, but for
developing other software which uses the library. So if you need only
the library (e.g., because it is used by some other software), you need
to install only the library package, but not the tools and development
packages. Saves some disk-space and makes the system easier to maintain
(software which isn't installed can't break).
hp
PS: AFAICS, perl is split into 9 packages on Debian.
--
_ | Peter J. Holzer | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR | > ist?
| | | hjp@hjp.at | Was sonst wäre der Sinn des Erfindens?
__/ | http://www.hjp.at/ | -- P. Einstein u. V. Gringmuth in desd
------------------------------
Date: 24 Sep 2006 10:12:56 -0400
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: Learning perl - for experienced programmers
Message-Id: <87wt7tfj4n.fsf@mithril.chromatico.net>
strombrg <strombrg@gmail.com> writes:
> ...could you? It's possible to write good or bad code in just about
> any language, but some languages definitely make it easier to write bad
> code and other languages definitely make it easier to write good code.
More to the point, some languages abstract away some things, and
others don't. When I write SQL, I'm not worrying about how the data
is represented in the filesystem and when and how it gets cached.
When I write Perl, I'm not worrying about how many bytes of memory are
being allocated and whether that memory will be freed in the end.
When I write C, I'm often doing both.
Charlton
------------------------------
Date: Sun, 24 Sep 2006 15:22:16 GMT
From: Dominique Dumont <domi@komarr.grenoble.hp.com>
Subject: New release of Config-Model, first draft for Xorg model
Message-Id: <J63s15.1J5t@zorch.sf-bay.org>
Hello
I'm happy to announce the new release of the Config::Model [1] perl
module (v0.602) .
This version provide some modifications necessary to provide a
configuration model for Xorg.
I'm still working in this Xorg configuration model. You can view the
first files directly on CVS [2].
Currently, I have:
- a model for InputDevice Files and Modules section of xorg.conf
- a preliminary parser for xorg.conf
You may have noticed that progress is quite slow. I sure could use
some help in providing a working configuration model for Xorg.
Other changes of Config-Model are:
* config-model: added -help and -man options to command line
* Model.pm (load): model file now must return an array ref and not
invoke Model methods. See t/big_model.pm for an example
(load): can load model file for model class that contain '::'. In
this case the model file is searched in a sub-directory just like
a perl class (E.g Model::Foo -> Model/Foo.pm)
* HashId.pm (create_default): can initialise children nodes while
creating default keys. (Necessary to be able to write a
configuration model for Xorg)
* AnyId.pm (move): new method
You can download this package from CPAN [3] or sourceforge [4].
Cheers
[1] http://config-model.sourceforge.net/
[2] http://config-model.cvs.sourceforge.net/config-model/xorg/
[3] http://search.cpan.org/dist/Config-Model/
[4] http://sourceforge.net/project/showfiles.php?group_id=155650
--
Dominique Dumont
"Delivering successful solutions requires giving people what they
need, not what they want." Kurt Bittner
------------------------------
Date: 24 Sep 2006 10:10:38 -0400
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: Russel Quong's "Perl in 20 pages"
Message-Id: <871wq1gxsx.fsf@mithril.chromatico.net>
Mirco Wahab <wahab@chemie.uni-halle.de> writes:
> Regarding the purpose of the whole Visibooks stuff,
> (http://visibooks.com/study.html) the book *might* be
> not that bad after all.
>
> To give, from the start, young people clear
> instructions to get technical things done
> (which they don't really understand and didn't
> expect to master at all) helps them to get a
> sense of self-efficacy and motivates them for
> some time.
Even then, it would be far better to give accurate information.
One of the things I hated when I was teaching was that I'd run into
students who had been taught something that was flat-out wrong,
usually because it was expedient for the teacher. A student without
exposure to such a teacher only had to learn the materials and
techniques; a student who had had such a teacher, though, had to spend
extra effort un-learning what he or she had previously learned.
If the point of Visibooks is to create programmers full of wrong
information but who nonetheless have high confidence in their
correctness -- well, they can stop now. Such programmers are in more
than adequate supply.
Charlton
------------------------------
Date: 24 Sep 2006 08:35:59 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: Russel Quong's "Perl in 20 pages"
Message-Id: <86fyehffa8.fsf@blue.stonehenge.com>
>>>>> "Charlton" == Charlton Wilbur <cwilbur@mithril.chromatico.net> writes:
Charlton> One of the things I hated when I was teaching was that I'd run into
Charlton> students who had been taught something that was flat-out wrong,
Charlton> usually because it was expedient for the teacher. A student without
Charlton> exposure to such a teacher only had to learn the materials and
Charlton> techniques; a student who had had such a teacher, though, had to
Charlton> spend extra effort un-learning what he or she had previously
Charlton> learned.
That's why we admit up front that we're "rounding off the corners" sometimes
in Learning Perl and Intermediate Perl... at least in the main text. We
always fix the lies in the footnotes. Hence, lots of footnotes.
However, in class, we don't have time to say the footnotes, so again, we admit
we lie, and that they should "read the book" to get the lies. I wish there
were another way. I guess it's sad perhaps when people don't even keep track
of when they are lying.
print "Just another Perl hacker,"; # the original!
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: Sun, 24 Sep 2006 11:29:31 GMT
From: Charles DeRykus <ced@blv-sam-01.ca.boeing.com>
Subject: Re: submatch scoping in while
Message-Id: <J63H97.1zE@news.boeing.com>
Mumia W. (reading news) wrote:
> On 09/23/2006 05:20 PM, Mirco Wahab wrote:
>> [...]
>> $i = 0;
>> @x = ('aaa','bbb');
>>
>> $i++ while ( $x[$i] !~/^(.)b/ && $i<@x ) ;
>>
>> print "\$1 is *$1*, i is $i\n";
>>
>>
>> Regards
>>
>> Mirco
>
> That's pretty good. It's just an inverted version of the OP's code; I
> wish I'd tried it. This idea crossed my mind for about ź a second, but I
> assumed that the same blocking problem would be there.
>
The inverted version is a statement modifier which doesn't create a
local block scope for $1.
$ perl -le 'while ("aa" =~ /^(.)a/) {last;};print $1' # undef
$ perl -le 'print $1 and exit while ("aa" =~ /^(.)a/)' # a
I didn't find this explained in perlsyn although maybe it's hiding
elsewhere.
--
Charles DeRykus
------------------------------
Date: Sun, 24 Sep 2006 15:02:16 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: submatch scoping in while
Message-Id: <4nndr0FatvmpU1@individual.net>
Julian Bradfield wrote:
> In article <4nlqetFaroshU1@individual.net>,
> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
>>
>>>
>>>@x = ( 'aaa','bbb');
>>>while ( $x[$i] !~ /^(.)b/ && $i <= $#x ) { $i++; }
>>>print "\$1 is *$1*, i is $i\n";
>>
>>No. Even if 'bbb' matches ^(.)b at the last loop iteration, you don't
>>test that. You test whether they *do not* match, so the test fails, and
>>$1 is not set.
>
> Wrong. As demonstrated by the if example later in my post, match variables
> are set by a !~ . (Otherwise $a !~ /foo/ would not be equivalent to
> ! ($a =~ /foo/) !)
Hmm.. Yes, apparently I was wrong. Don't remember how I reached that
faulty conclusion. Sorry for the confusion. :(
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 24 Sep 2006 14:23:03 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: tying db records and other objects, speed?
Message-Id: <slrnehd565.40l.abigail@alexandra.abigail.be>
Oobi Van Doobi (skimba@dambo.di) wrote on MMMMDCCLXXII September MCMXCIII
in <URL:news:lCqRg.18783$Au2.16784@reader1.news.jippii.net>:
%% Hi,
%% have some issues regarding tying of db records.
%% I have the past few days done a class/package that tie's a database record
%% to a hash. I am very happy with this solution, as I can just take the CGI
%% params and put them into the hash, and voila they are in the database.
%%
%% But:What about speed? Could some kind soul please advice a little if this
%% (tie'ing records like this) is a good thing to do, or if I should take
%% another route.
How can we tell? Only you know whether the speed of a choosen solution
is acceptable. We already know speed isn't your number one priority -
otherwise you wouldn't have picked Perl to implement it in.
%% Background to the project:
%% 1)web application
%% 2)mod_perl to some extent
%% 3)number of users only about 5-10
%% 4)using MySQL
Yes, and?
Abigail
--
sub _ {$_ = shift and y/b-yB-Y/a-yB-Y/ xor !@ _?
exit print :
print and push @_ => shift and goto &{(caller (0)) [3]}}
split // => "KsvQtbuf fbsodpmu\ni flsI " xor & _
------------------------------
Date: Sun, 24 Sep 2006 19:34:24 +0300
From: Oobi Van Doobi <skimba@dambo.di>
Subject: Re: tying db records and other objects, speed?
Message-Id: <2_xRg.19107$HR7.10674@reader1.news.jippii.net>
Mark Clements wrote:
> Oobi Van Doobi wrote:
>> Hi,
>> have some issues regarding tying of db records.
>> I have the past few days done a class/package that tie's a database
>> record to a hash. I am very happy with this solution, as I can just take
>> the CGI params and put them into the hash, and voila they are in the
>> database.
>>
>> But:What about speed? Could some kind soul please advice a little if this
>> (tie'ing records like this) is a good thing to do, or if I should take
>> another route.
>>
>> Background to the project:
>> 1)web application
>> 2)mod_perl to some extent
>> 3)number of users only about 5-10
>> 4)using MySQL
>>
>> Many thank's and have a good day
>
> Run some benchmarks (eg Benchmark::Timer) and establish where your code
> is spending most of its time. Decide whether your application is already
> fast enough. You can waste an awful lot of time trying to get minor
> speed-ups, time that could be spent on more productive tasks.
>
> If your existing codebase is composed of clear, maintainable code then
> you are already ahead of your game. Performance, especially in a small
Hmm, all is made as modules/packages. I have made even a Column in a table
as a package, that I tie to, also a record is a tied hash. The great thing
with tie'ing is flexibility. The same code applies naturally to all tables.
The hash package that I tie to a record checks for column types and column
names and use them as parameters with CGI. Then I can use the column
information as input types ( textarea, input, checkboxes and such) in the
gui part.
Here is the tied table record hash package:
<code>
package TransPool::Row;
use TransPool::Column;
use TransPool::ColumnTypes;
use DBI;
use TransPool::Debug;
use strict;
my $DEBUG = TransPool::Debug->new()->{DEBUG};
sub TIEHASH
{
#DB HANDLE, TABLE NAME
my $self = shift;
my $dbh = shift;
my $tname = shift;
my $idcol = shift;
my $cond = shift;
my $table =
{
DBH=>$dbh,
TABLENAME=>$tname,
IDCOL=>$idcol,
CONDITION=>$cond,
COLUMNS=>{},
ROWS=>undef,
};
my $rh;
my $qcond = $dbh->quote($cond);
my $sql_on_id_col = "SELECT $idcol FROM $tname WHERE $idcol = $qcond";
my $sth = $dbh->prepare($sql_on_id_col);
if ( !$sth->execute() )
{
print "error:$sql_on_id_col:$DBI::errstr";
return bless $table, $self;
}
if ( $sth->rows == 0 )
{
my $sql_insert = "INSERT INTO $tname ($idcol) VALUES($qcond)";
my $sth_insert = $dbh->prepare($sql_insert);
$sth_insert->execute() or print "insert failed:$sql_insert:$DBI::errstr";
return bless $table, $self;
}
return bless $table, $self;
}
sub FETCH
{
my $self = shift;
my $key = shift;
#( $dbh, $table, $column, $idcol, $id ) = @_;
tie
$self->{COLUMNS}{$key},
"Column",
$self->{DBH},
$self->{TABLENAME},
$key,
$self->{IDCOL},
$self->{CONDITION}
;
return $self->{COLUMNS}{$key};
}
sub STORE
{
my $self = shift;
my $key = shift;
my $value = shift;
tie
$self->{COLUMNS}{$key},
"Column",
$self->{DBH},
$self->{TABLENAME},
$key,
$self->{IDCOL},
$self->{CONDITION}
;
$self->{COLUMNS}{$key} = $value;
}
sub DELETE
{
my $self = shift;
return undef;
}
sub CLEAR
{
#deletes a record as identified by the condition
my $self = shift;
my $qval = $self->{DBH}->quote($self->{CONDITION});
my $sql = "DELETE FROM $self->{TABLENAME} WHERE $self->{IDCOL}=$qval";
my $sth = $self->{DBH}->prepare($sql);
if ( !$sth->execute() )
{
print "failed to delete record(s):$sql:$DBI::errstr\n";
}
}
sub EXISTS
{
my $self = shift;
my $key = shift;
return exists $self->{COLUMNS}{$key};
}
sub FIRSTKEY
{
my $self = shift;
return scalar each %{$self->{COLUMNS}{Field}};
}
sub NEXTKEY
{
my $self = shift;
return scalar each %{$self->{COLUMNS}{Field}};
}
sub DESTROY
{
my $self = shift;
return;
}
1;
</code>
For example, this is what I do:
here is a sample parameter value pair list from CGI:
<cgi>
TransporterUniqueId=1
TransporterName=Oola Bandoola
TransporterAddress=Adr1
TransporterAddress2=Adr2
TransporterTel=1234
TransporterFax=2345
TransporterEmail=bo@someplace.net
TransporterSite=www.ownsite.obi
TransporterCountry=1
</cgi>
so, when those parameters arrive on the server I can just do:
my %row;
tie %row, "TransPool::Row", ...parameters here....set unique id;
and then after getting the cgi object from mod_perl I can loop on cgi params
( to update only those present in the cgi object):
foreach my $p($cgi->param)
{
$row{p} = $cgi->param($p);
}
or to get only the specified set of params
my @ary;
foreach my $p($cgi->param)
{
push @ary, $row{p};
}
return @ary;
> application, is one of the last things you should worry about.
Yes, I guess you are right there, I'll go for maintainability and
flexibility and drop speed issues for now.
>
> Note: somebody else will be able to give your more details about the
> efficiency of tie. I never use it in my own code, and must admit have
> not even read the documentation for it in some time.
>
> Mark
General comments, or in particular, on this approach are very much welcome,
Thank's
Thank's for your input, Mark.
Greger
------------------------------
Date: Sun, 24 Sep 2006 19:35:25 +0300
From: Oobi Van Doobi <skimba@dambo.di>
Subject: Re: tying db records and other objects, speed?
Message-Id: <U_xRg.19108$HR7.19105@reader1.news.jippii.net>
Abigail wrote:
> Oobi Van Doobi (skimba@dambo.di) wrote on MMMMDCCLXXII September MCMXCIII
> in <URL:news:lCqRg.18783$Au2.16784@reader1.news.jippii.net>:
> %% Hi,
> %% have some issues regarding tying of db records.
> %% I have the past few days done a class/package that tie's a database
> record
> %% to a hash. I am very happy with this solution, as I can just take the
> CGI
> %% params and put them into the hash, and voila they are in the database.
> %%
> %% But:What about speed? Could some kind soul please advice a little if
> this
> %% (tie'ing records like this) is a good thing to do, or if I should take
> %% another route.
>
> How can we tell? Only you know whether the speed of a choosen solution
> is acceptable. We already know speed isn't your number one priority -
> otherwise you wouldn't have picked Perl to implement it in.
>
> %% Background to the project:
> %% 1)web application
> %% 2)mod_perl to some extent
> %% 3)number of users only about 5-10
> %% 4)using MySQL
>
> Yes, and?
>
>
>
> Abigail
ah, perl vs java or cobol or C++? or something else?
------------------------------
Date: 24 Sep 2006 14:59:22 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Zero equals pipe??
Message-Id: <fanch25e1lckumk6snrbnij4100arf9pdd@4ax.com>
On 23 Sep 2006 18:17:38 -0700, ilya2@rcn.com wrote:
>if ( '1' == '|') { ... some statement ... }
>
>if ( '0' == '|') { ... another statement ... }
>
>By any sensible measure, both statements must return FALSE. First one
>did that. Second one returned TRUE.
Any sensible measure as of which particular doc?
>What's going on and how do I get around it?
perl -we '"0"=="|"'
gives me a hint that 'eq' == '==' but that not 'eq' eq '==', i.e. 'eq'
neq '=='.
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: Sun, 24 Sep 2006 16:33:49 GMT
From: Bob Walton <see.sig@rochester.rr.com>
Subject: Re: Zero equals pipe??
Message-Id: <NryRg.55491$8j3.26370@twister.nyroc.rr.com>
Sisyphus wrote:
> <ilya2@rcn.com> wrote in message
> .
> .
>> if ( '0' == '|') { ... another statement ... }
>>
>
> Any string that begins with numeric characters will be assigned the numeric
> value of those numeric characters. Hence:
>
> '1' == 1
> '0' == 0
> '1234' == 1234
> '1234garbage' == 1234
> '12garbage34' == 12
>
> But any string that begins with a non-numeric character will be assigned a
> numeric value of 0.Hence:
>
> 'garbage1234' == 0
> '|' == 0
>
> From that you can see that '0' == '|' will evaluate as true since 0 == 0.
>
> (This is documented somewhere .... but damned if I could find it in a hurry
> :-)
That would be in
perldoc perlop
in the "Equality Operators" section.
...
> Rob
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
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 9760
***************************************