[32074] in Perl-Users-Digest
Perl-Users Digest, Issue: 3338 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 29 21:09:26 2011
Date: Tue, 29 Mar 2011 18:09:10 -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, 29 Mar 2011 Volume: 11 Number: 3338
Today's topics:
pattern matching and abstract functions <cartercc@gmail.com>
Re: pattern matching and abstract functions <ikramkurdi@gmail.com>
Re: pattern matching and abstract functions <uri@StemSystems.com>
Re: pattern matching and abstract functions <tadmc@seesig.invalid>
Re: pattern matching and abstract functions <cartercc@gmail.com>
Re: pattern matching and abstract functions <uri@StemSystems.com>
Re: REVISED: Variable length array to XML <dpich@polartel.com>
Re: REVISED: Variable length array to XML <uri@StemSystems.com>
Re: Search script to index dynamic pages <jurgenex@hotmail.com>
Re: two attempts at DBI connect call <tadmc@seesig.invalid>
Re: two attempts at DBI connect call <mvdwege@mail.com>
Re: two attempts at DBI connect call <xhoster@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 29 Mar 2011 09:38:25 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: pattern matching and abstract functions
Message-Id: <0a132615-05e3-4fbf-8c90-2af8a1205e92@n2g2000prj.googlegroups.com>
Let's suppose you have a web app, and your HTML user interface
contains menu items like this:
<a href="site?menu=home">HOME</a>
<a href="site?menu=faq">FAQ</a>
<a href="site?menu=links">LINKS</a>
<a href="site?menu=contact">CONTACT US</a>
On the server side, you have code that looks like this (as STYLE A):
use CGI;
my $menu = param('menu');
if ($menu eq 'home') { do_this(); }
elsif ($menu eq 'faq') { do_that(); }
elsif ($menu eq 'links') { do_something_else(); }
elsif ($menu eq 'contact') { do_another_thing(); }
else { print "CGI ERROR, unknown $menu\n"; }
Some languages (Lisp and Erlang, for instance) have functions that are
conceptually overloaded and specialized according to their parameters.
For example, using a Perlish hypothetical language, you might do this
(as STYLE B):
do_this('home');
do_this('faq');
do_this('links');
do_this('contact');
do_this(_); # underscore represents an unknown value
Is there any way to specialize functions in Perl based on the value of
their parameters? The app is written in a procedural style, not OO,
and I'd like a way to introduce polymorphism without rewriting it as
an OO app.
The motivation for this question is an application that started with a
small number of elsif branches, and now has dozens of branches and has
become a nightmare to maintain. I have written a little script that
can change the source code from STYLE A to STYLE B but I haven't been
able to figure out a way to use Perl for Lisp-like specialization or
Erlang-like pattern matching.
Thanks, CC.
------------------------------
Date: Tue, 29 Mar 2011 13:43:06 -0700 (PDT)
From: Ikram Kurdi <ikramkurdi@gmail.com>
Subject: Re: pattern matching and abstract functions
Message-Id: <20de8325-f9b2-4869-980f-98fe803e1f82@r4g2000prm.googlegroups.com>
On Mar 29, 11:38=A0am, ccc31807 <carte...@gmail.com> wrote:
> Let's suppose you have a web app, and your HTML user interface
> contains menu items like this:
> =A0<a href=3D"site?menu=3Dhome">HOME</a>
> =A0<a href=3D"site?menu=3Dfaq">FAQ</a>
> =A0<a href=3D"site?menu=3Dlinks">LINKS</a>
> =A0<a href=3D"site?menu=3Dcontact">CONTACT US</a>
>
> On the server side, you have code that looks like this (as STYLE A):
> use CGI;
> my $menu =3D param('menu');
> if ($menu eq 'home') { do_this(); }
> elsif ($menu eq 'faq') { do_that(); }
> elsif ($menu eq 'links') { do_something_else(); }
> elsif ($menu eq 'contact') { do_another_thing(); }
> else { print "CGI ERROR, unknown $menu\n"; }
>
> Some languages (Lisp and Erlang, for instance) have functions that are
> conceptually overloaded and specialized according to their parameters.
> For example, using a Perlish hypothetical language, you might do this
> (as STYLE B):
> do_this('home');
> do_this('faq');
> do_this('links');
> do_this('contact');
> do_this(_); # underscore represents an unknown value
>
> Is there any way to specialize functions in Perl based on the value of
> their parameters? The app is written in a procedural style, not OO,
> and I'd like a way to introduce polymorphism without rewriting it as
> an OO app.
>
> The motivation for this question is an application that started with a
> small number of elsif branches, and now has dozens of branches and has
> become a nightmare to maintain. I have written a little script that
> can change the source code from STYLE A to STYLE B but I haven't been
> able to figure out a way to use Perl for Lisp-like specialization or
> Erlang-like pattern matching.
>
> Thanks, CC.
Not sure if this is exactly what you want: You can do 'named
arguments' this way:
callSubroutine(arg1=3D>val,arg2=3D>val,arg3=3D>val);
Inside the subroutine you can put them inside a hash:
%h =3D @_;
Then check for the existence of keys:
if(exists($h{arg1})) { do this; }
or check the value of the keys:
if($h{arg1} =3D val) { do this; }
If you don't want to pass any values with the arguments, you can just
do this:
callSubroutine(arg1=3D>undef,arg2=3D>undef);
Again put @_ into a hash and check for the existence of keys with
'exists'.
------------------------------
Date: Tue, 29 Mar 2011 16:55:53 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: pattern matching and abstract functions
Message-Id: <87tyelejdy.fsf@quad.sysarch.com>
>>>>> "c" == ccc31807 <cartercc@gmail.com> writes:
c> On the server side, you have code that looks like this (as STYLE A):
c> use CGI;
c> my $menu = param('menu');
c> if ($menu eq 'home') { do_this(); }
c> elsif ($menu eq 'faq') { do_that(); }
c> elsif ($menu eq 'links') { do_something_else(); }
c> elsif ($menu eq 'contact') { do_another_thing(); }
c> else { print "CGI ERROR, unknown $menu\n"; }
c> Some languages (Lisp and Erlang, for instance) have functions that are
c> conceptually overloaded and specialized according to their parameters.
c> For example, using a Perlish hypothetical language, you might do this
c> (as STYLE B):
c> do_this('home');
c> do_this('faq');
c> do_this('links');
c> do_this('contact');
c> do_this(_); # underscore represents an unknown value
you are thinking about multiple dispatch and the key is the TYPE of the
variable is different, not the value. value is only a runtime thing and
so all langs would need some other way to determine how to handle each
value. in perl this is done via a dispatch table which is simply a hash
of values (e.g. 'home') to code refs (e.g. \&do_this_home). this has
been discussed many times here so google for more about them.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Tue, 29 Mar 2011 16:56:28 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: pattern matching and abstract functions
Message-Id: <slrnip4l36.pjm.tadmc@tadbox.sbcglobal.net>
ccc31807 <cartercc@gmail.com> wrote:
> my $menu = param('menu');
> if ($menu eq 'home') { do_this(); }
> elsif ($menu eq 'faq') { do_that(); }
> elsif ($menu eq 'links') { do_something_else(); }
> elsif ($menu eq 'contact') { do_another_thing(); }
> else { print "CGI ERROR, unknown $menu\n"; }
A "dispatch table" would be great for that.
my %action = (
home => \&do_this,
faq => \&do_that,
links => \&do_something_else,
contact => \&do_another_thing,
);
if (exists $action{$menu}) {
$action{$menu}->();
}
else {
print "CGI ERROR, unknown $menu\n";
}
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
------------------------------
Date: Tue, 29 Mar 2011 15:32:56 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: pattern matching and abstract functions
Message-Id: <6586f3d3-884f-4002-aca5-9047947ebb0a@32g2000vbe.googlegroups.com>
On Mar 29, 5:56=A0pm, Tad McClellan <ta...@seesig.invalid> wrote:
> my %action =3D (
> =A0 =A0 home =A0 =A0=3D> \&do_this,
> =A0 =A0 faq =A0 =A0 =3D> \&do_that,
> =A0 =A0 links =A0 =3D> \&do_something_else,
> =A0 =A0 contact =3D> \&do_another_thing,
> );
I haven't tried this yet, so this may be off, but it looks like you
have constructed a hash with keys matching the value of the parameter
containing the user selected value (e.g., home, faq, etc.), and a
reference to the function to be triggered according to the value of
the key.
I can deal with this, but it will require me to think of a name for
each function ... not too difficult since I can use the value of the
parameter (like menu, faq, etc.). However, I was really looking for
something that triggered on the value of the parameter itself.
The only other thing, that I didn't mention, is that this is an
interface for a database, and we potentially have 20 or 30 variables
coming in (to insert a person into PERSON, for example). I'm using
lexical variables for these values, and this has never been a problem.
The functions call DBI functions and pass in the action (select,
insert, update, delete) and the relevant data, and I don't see any
need whatsoever to make any change in that code.
Thanks, CC.
------------------------------
Date: Tue, 29 Mar 2011 18:41:07 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: pattern matching and abstract functions
Message-Id: <87wrjhczy4.fsf@quad.sysarch.com>
>>>>> "c" == ccc31807 <cartercc@gmail.com> writes:
c> On Mar 29, 5:56 pm, Tad McClellan <ta...@seesig.invalid> wrote:
>> my %action = (
>> home => \&do_this,
>> faq => \&do_that,
>> links => \&do_something_else,
>> contact => \&do_another_thing,
>> );
c> I haven't tried this yet, so this may be off, but it looks like you
c> have constructed a hash with keys matching the value of the parameter
c> containing the user selected value (e.g., home, faq, etc.), and a
c> reference to the function to be triggered according to the value of
c> the key.
c> I can deal with this, but it will require me to think of a name for
c> each function ... not too difficult since I can use the value of the
c> parameter (like menu, faq, etc.). However, I was really looking for
c> something that triggered on the value of the parameter itself.
that *IS* triggered on the value itself. even if you could do what you
imagine you want you would still need a way to distinguish what code
handles what input. your way delays the handling until later but without
such a dispatch table you still need an if/else tree or a switch
statement. this is true even for languages with multiple dispatch, you
have to declare a sub for each type (again TYPE not value) of input. you
can't hide the decision tree under the carpet. somewhere you need to
look at the different input values and do different things. doing it
early in a dispatch table is the easiest, cleanest, fastest and most
idiomatic way in perl. it is done all over the place and you need to
learn how to use them.
c> The only other thing, that I didn't mention, is that this is an
c> interface for a database, and we potentially have 20 or 30 variables
c> coming in (to insert a person into PERSON, for example). I'm using
c> lexical variables for these values, and this has never been a problem.
c> The functions call DBI functions and pass in the action (select,
c> insert, update, delete) and the relevant data, and I don't see any
c> need whatsoever to make any change in that code.
so? you can call any sub via a dispatch table. you can even pass in
extra args or whatever in the calling call. the main idea is just using
a key (your input value NOT TYPE) to decide which sub to call. i said
google for many discussion on dispatch tables over many years.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Tue, 29 Mar 2011 11:57:04 -0500
From: Don Pich <dpich@polartel.com>
Subject: Re: REVISED: Variable length array to XML
Message-Id: <ArSdnQwM6cz9kg_QnZ2dnUVZ_tydnZ2d@polarcomm.com>
Thank you for the great advice.
Here is my current code:
___ CODE ___
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my $infile = '/media/Docs/Scripts/Perl/Putty/putty.csv.back';
open (CSVFILE, $infile) || die ("Could not open $infile! $!");
my @final;
while ( my $line = <CSVFILE> ) {
$line =~ tr/"\r\n//d;
my @cleanline = split /,/, $line;
my ( undef, @prefinal ) = split /\\/, $cleanline[ 1 ];
push @final, [ @prefinal, @cleanline[ 0, 3 ] ];
}
close $infile;
my %hash;
foreach my $leaf (@final) {
my $ptr = \%hash;
foreach my $i ( 0 .. $#$leaf - 1 ) {
my $node = $leaf->[$i];
if( $i != $#$leaf - 1 ) {
$ptr->{$node} = {}
unless( exists $ptr->{$node} );
$ptr = $ptr->{$node};
} else {
$ptr->{$node} = $leaf->[$i + 1];
}
}
}
print qq(<SESSION>\n);
foreach my $k1 (sort keys %hash) {
print qq( <$k1>\n);
foreach my $k2 (sort keys %{$hash{$k1}}) {
print qq( <$k2>\n);
foreach my $k3 (sort keys %{$hash{$k1}{$k2}}) {
print qq( <$k3>\n);
foreach my $k4 (sort keys %{$hash{$k1}{$k2}{$k3}}) {
print qq( <$k4>\n);
foreach my $k5 (sort keys %{$hash{$k1}{$k2}{$k3}{$k4}}) {
print qq( <$k5>\n);
foreach my $k6 (sort keys %{$hash{$k1}{$k2}{$k3}{$k4}{$k5}}) {
print qq( <$k6>\n);
foreach my $k7 (sort keys %{$hash{$k1}{$k2}{$k3}{$k4}{$k5}
{$k6}}) {
print qq( <$k7>\n);
print qq( $hash{$k1}{$k2}{$k3}{$k4}{$k5}{$k6}{$k7}
\n);
print qq( </$k7>\n);
}
print qq( </$k6>\n)
}
print qq( </$k5>\n);
}
print qq( </$k4>\n);
}
print qq( </$k3>\n);
}
print qq( </$k2>\n);
}
print qq( </$k1>\n);
}
print qq(</SESSION>\n);
# Print Entire HASH
#print Dumper %hash;
# Print Entire Array
#for my $i ( 1 .. $#final ) {
# print "@{$final[$i]} \n";
#}
exit(0);
___ CODE ___
The data in putty.csv.back is this:
____ INPUT ___
"LNKN.41F.01.01","Sessions\NOC-CO\Occam\LakotaRing\LNKN\LNKN.41F.01
\LNKN.41F.01.01","","cli@10.22.31.101"
"LNKN.41F.01.02","Sessions\NOC-CO\Occam\LakotaRing\LNKN\LNKN.41F.01
\LNKN.41F.01.02","","cli@10.22.31.102"
"LNKN.41F.01.03","Sessions\NOC-CO\Occam\LakotaRing\LNKN\LNKN.41F.01
\LNKN.41F.01.03","","cli@10.22.31.103"
"LNKN.41F.01.04","Sessions\NOC-CO\Occam\LakotaRing\LNKN\LNKN.41F.01
\LNKN.41F.01.04vacant","","cli@10.22.31.104"
"LNKN.41F.01.05","Sessions\NOC-CO\Occam\LakotaRing\LNKN\LNKN.41F.01
\LNKN.41F.01.05vacant","","cli@10.22.31.105"
"LNKN.41F.01.06","Sessions\NOC-CO\Occam\LakotaRing\LNKN\LNKN.41F.01
\LNKN.41F.01.06vacant","","cli@10.22.31.106"
"LNKN.41F.01.07","Sessions\NOC-CO\Occam\LakotaRing\LNKN\LNKN.41F.01
\LNKN.41F.01.07vacant","","cli@10.22.31.107"
"LNKN.41F.01.09","Sessions\NOC-CO\Occam\LakotaRing\LNKN\LNKN.41F.01
\LNKN.41F.01.09vacant","","cli@10.22.31.109"
"LNKN.41F.01.10","Sessions\NOC-CO\Occam\LakotaRing\LNKN\LNKN.41F.01
\LNKN.41F.01.10vacant","","cli@10.22.31.110"
"LNKN.41F.01.11","Sessions\NOC-CO\Occam\LakotaRing\LNKN\LNKN.41F.01
\LNKN.41F.01.11vacant","","cli@10.22.31.111"
"LNKN.41F.01.12","Sessions\NOC-CO\Occam\LakotaRing\LNKN\LNKN.41F.01
\LNKN.41F.01.12","","cli@10.22.31.112"
___ INPUT ___
The data that is produces is this:
___ OUTPUT ___
<SESSION>
<NOC-CO>
<Occam>
<LakotaRing>
<LNKN>
<LNKN.41F.01>
<LNKN.41F.01.01>
<LNKN.41F.01.01>
cli@10.22.31.101
</LNKN.41F.01.01>
</LNKN.41F.01.01>
<LNKN.41F.01.02>
<LNKN.41F.01.02>
cli@10.22.31.102
</LNKN.41F.01.02>
</LNKN.41F.01.02>
<LNKN.41F.01.03>
<LNKN.41F.01.03>
cli@10.22.31.103
</LNKN.41F.01.03>
</LNKN.41F.01.03>
<LNKN.41F.01.04vacant>
<LNKN.41F.01.04>
cli@10.22.31.104
</LNKN.41F.01.04>
</LNKN.41F.01.04vacant>
<LNKN.41F.01.05vacant>
<LNKN.41F.01.05>
cli@10.22.31.105
</LNKN.41F.01.05>
</LNKN.41F.01.05vacant>
<LNKN.41F.01.06vacant>
<LNKN.41F.01.06>
cli@10.22.31.106
</LNKN.41F.01.06>
</LNKN.41F.01.06vacant>
<LNKN.41F.01.07vacant>
<LNKN.41F.01.07>
cli@10.22.31.107
</LNKN.41F.01.07>
</LNKN.41F.01.07vacant>
<LNKN.41F.01.09vacant>
<LNKN.41F.01.09>
cli@10.22.31.109
</LNKN.41F.01.09>
</LNKN.41F.01.09vacant>
<LNKN.41F.01.10vacant>
<LNKN.41F.01.10>
cli@10.22.31.110
</LNKN.41F.01.10>
</LNKN.41F.01.10vacant>
<LNKN.41F.01.11vacant>
<LNKN.41F.01.11>
cli@10.22.31.111
</LNKN.41F.01.11>
</LNKN.41F.01.11vacant>
<LNKN.41F.01.12>
<LNKN.41F.01.12>
cli@10.22.31.112
</LNKN.41F.01.12>
</LNKN.41F.01.12>
</LNKN.41F.01>
</LNKN>
</LakotaRing>
</Occam>
</NOC-CO>
</SESSION>
___ OUTPUT ___
This is getting very close. Here is the tricky part now. I need to
calculate the length of the hash. Reading several docs, the proper
method for calculating the length of elements in a hash is:
my $size = scalar(keys %hash);
I will need to implement some form of this because my data is variable
(I.E., I can have a hash 4 elements long, or as above, it would be 8
elements long). My plan is to create some 'if' loops. So in a very
generic sense. I'm trying to have the script make a decision that says
if the hash is 8 elements long, it will produce a leaf that is 8 elements
long. If it has 4 elements, it will produce a leaf that is 4 elements
long.
my $size = print qq(<SESSION>\n);
print qq(<SESSION>\n);
foreach my $k1 (sort keys %hash) {
print qq( <$k1>\n);
foreach my $k2 (sort keys %{$hash{$k1}}) {
print qq( <$k2>\n);
foreach my $k3 (sort keys %{$hash{$k1}{$k2}}) {
print qq( <$k3>\n);
if ($size == 4) {
foreach my $k4 (sort keys %{$hash{$k1}{$k2}{$k3}}) {
print qq( <$k4>\n);
print qq( $hash{$k1}{$k2}{$k3}\n);
print qq( </$k4>\n);
}
} elsif ($size == 8);{
foreach my $k4 (sort keys %{$hash{$k1}{$k2}{$k3}}) {
print qq( <$k4>\n);
foreach my $k5 (sort keys %{$hash{$k1}{$k2}{$k3}{$k4}}) {
print qq( <$k5>\n);
foreach my $k6 (sort keys %{$hash{$k1}{$k2}{$k3}{$k4}{$k5}}) {
print qq( <$k6>\n);
foreach my $k7 (sort keys %{$hash{$k1}{$k2}{$k3}{$k4}{$k5}
{$k6}}) {
print qq( <$k7>\n);
print qq( $hash{$k1}{$k2}{$k3}{$k4}{$k5}{$k6}{$k7}
\n);
print qq( </$k7>\n);
}
print qq( </$k6>\n)
}
print qq( </$k5>\n);
}
print qq( </$k4>\n);
}
}
print qq( </$k3>\n);
}
print qq( </$k2>\n);
}
print qq( </$k1>\n);
}
print qq(</SESSION>\n);
I don't think my script will calculate the proper width for the element.
This works fine for a simple hash. But a hash of hash seems like it's
very difficult to calculate.
------------------------------
Date: Tue, 29 Mar 2011 16:51:44 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: REVISED: Variable length array to XML
Message-Id: <871v1pfy5b.fsf@quad.sysarch.com>
>>>>> "DP" == Don Pich <dpich@polartel.com> writes:
DP> Thank you for the great advice.
looks like you didn't take any of my advice. a template system is the
way to go here. you are reinventing a general purpose wheel in a very
specific and bad way. your code could be reduced to about 30 lines or
less with Template::Simple.
DP> Here is my current code:
DP> my %hash;
DP> foreach my $leaf (@final) {
DP> my $ptr = \%hash;
DP> foreach my $i ( 0 .. $#$leaf - 1 ) {
DP> my $node = $leaf->[$i];
DP> if( $i != $#$leaf - 1 ) {
DP> $ptr->{$node} = {}
DP> unless( exists $ptr->{$node} );
DP> $ptr = $ptr->{$node};
DP> } else {
DP> $ptr->{$node} = $leaf->[$i + 1];
learn about autovivification. there is no need to manually make a hash
ref if one doesn't exist. assume it does and perl creates it for you.
DP> }
DP> }
DP> }
DP> print qq(<SESSION>\n);
DP> foreach my $k1 (sort keys %hash) {
DP> print qq( <$k1>\n);
DP> foreach my $k2 (sort keys %{$hash{$k1}}) {
DP> print qq( <$k2>\n);
DP> foreach my $k3 (sort keys %{$hash{$k1}{$k2}}) {
DP> print qq( <$k3>\n);
DP> foreach my $k4 (sort keys %{$hash{$k1}{$k2}{$k3}}) {
DP> print qq( <$k4>\n);
DP> foreach my $k5 (sort keys %{$hash{$k1}{$k2}{$k3}{$k4}}) {
DP> print qq( <$k5>\n);
none of my great advice on using refs here was taken. this is unreadable
and unmaintainable code.
<massive snip>
if your data and structures are so simple and short you need only about
5 lines to show it works or not. pasting large amounts of input and
output is annoying.
DP> This is getting very close. Here is the tricky part now. I need to
DP> calculate the length of the hash. Reading several docs, the proper
DP> method for calculating the length of elements in a hash is:
DP> my $size = scalar(keys %hash);
there is no such thing as the length of hash. and scalar is not needed
there as the scalar assignment will force scalar context on keys.
DP> I will need to implement some form of this because my data is variable
DP> (I.E., I can have a hash 4 elements long, or as above, it would be 8
DP> elements long). My plan is to create some 'if' loops. So in a very
DP> generic sense. I'm trying to have the script make a decision that says
DP> if the hash is 8 elements long, it will produce a leaf that is 8 elements
DP> long. If it has 4 elements, it will produce a leaf that is 4 elements
DP> long.
again, a template will do all of that for you.
DP> I don't think my script will calculate the proper width for the element.
DP> This works fine for a simple hash. But a hash of hash seems like it's
DP> very difficult to calculate.
that makes no sense as usual. hashes don't have width. if you can do
anything on a hash, you can do it on a hash of hashes. it is just
another hash lower down. you can't see to separate that concept yet.
again, switch to a templater. you are going down a very bad path now. if
i had the serious interest i would code this up for you. but you are
ignoring my comments it seems so i will ignore your needs.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Tue, 29 Mar 2011 07:14:33 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Search script to index dynamic pages
Message-Id: <i1q3p65dtfo7he6usnh9a8r3i9te7erdgp@4ax.com>
Rob <rdw204@gmail.com> wrote:
>As the majority of the content on the website is dynamic content, does
>anybody know of any search CGI scripts that will index pages with
>dynamic CGI content? (e.g. "website.com/cgi-bin/viewpage.cgi?id=100" )
How would that script know which parameters are supported? Is id=100
legal? Is id=100000000000000 legal? Is it myid=... instead of id=...?
>If such a script is not available, is there a way to return content
>from a dynamic page to a CGI script (for indexing purposes)?
That is trivial, see
perldoc -q "How do I fetch an HTML file?"
jue
------------------------------
Date: Tue, 29 Mar 2011 08:48:09 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: two attempts at DBI connect call
Message-Id: <slrnip3ofi.oqq.tadmc@tadbox.sbcglobal.net>
dn.perl@gmail.com <dn.perl@gmail.com> wrote:
> I would like to try to connect via string-1, and if it fails connect
> via string-2. But the program just aborts when a dbi->connect call
> fails.
You can trap fatal errors in Perl with "eval BLOCK".
> my $dbh ;
> $dbh = DBI->connect("dbi:Oracle:tns-string1 etc etc etc");
eval {$dbh = DBI->connect("dbi:Oracle:tns-string1 etc etc etc")}
> if (!$dbh ) {
> $dbh = DBI->connect("dbi:Oracle:tns-string2 etc etc etc");
> }
> ## die if both attempts fail
> die $dbh->errstr if !$dbh ; ## I can live without this statement
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
------------------------------
Date: Tue, 29 Mar 2011 20:42:58 +0200
From: Mart van de Wege <mvdwege@mail.com>
Subject: Re: two attempts at DBI connect call
Message-Id: <86ei5pepjh.fsf@gareth.avalon.lan>
Tad McClellan <tadmc@seesig.invalid> writes:
> dn.perl@gmail.com <dn.perl@gmail.com> wrote:
>
>> I would like to try to connect via string-1, and if it fails connect
>> via string-2. But the program just aborts when a dbi->connect call
>> fails.
>
>
> You can trap fatal errors in Perl with "eval BLOCK".
>
Yeah, but is that necessary in this case?
As long as the RaiseError attribute is not set, DBI->connect just
returns an error code.
Is RaiseError set by default these days? On my system it isn't (Debian
Sid, DBI 1.616, DBD::Pg 2.17.2).
The following code continues executing after the failed connect:
----- BEGIN CODE -----
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
my $dbh = DBI->connect('dbi:Pg:dbname=nonexistant',undef,undef);
print "Status" . DBI::errstr ."\n";
----- END CODE -----
Mart
--
"We will need a longer wall when the revolution comes."
--- AJS, quoting an uncertain source.
------------------------------
Date: Tue, 29 Mar 2011 17:13:54 -0700
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: two attempts at DBI connect call
Message-Id: <4d927331$0$28387$ed362ca5@nr5-q3a.newsreader.com>
dn.perl@gmail.com wrote:
> I have two tns-connection-strings with me. Only one of them is active
> at any given time.
> Same schema, usernames, passwords apply to both.
>
> I would like to try to connect via string-1, and if it fails connect
> via string-2. But the program just aborts when a dbi->connect call
> fails. No second chance allowed.
>
> Sample code:
> my $dbh ;
> $dbh = DBI->connect("dbi:Oracle:tns-string1 etc etc etc");
> if (!$dbh ) {
> $dbh = DBI->connect("dbi:Oracle:tns-string2 etc etc etc");
> }
> ## die if both attempts fail
> die $dbh->errstr if !$dbh ; ## I can live without this statement
> return $dbh ;
>
> I suspect there must be some internal variable set by default to make
> a program exit if DBI->connect fails.
No, I don't think so. Is there a RaiseError=1 hidden in your "etc"?
> How can I make the above code work?
You could use eval {}, but it shouldn't be needed.
Xho
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 3338
***************************************