[29353] in Perl-Users-Digest
Perl-Users Digest, Issue: 597 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 28 21:10:11 2007
Date: Thu, 28 Jun 2007 18:09:09 -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 Thu, 28 Jun 2007 Volume: 11 Number: 597
Today's topics:
Re: "Convert" perl command line to simple script <glennj@ncf.ca>
Re: "Convert" perl command line to simple script <Alberto.Schiano@gmail.com>
2 dimentional data call within a conditional fzxdf5@gmail.com
Re: 2 dimentional data call within a conditional <glex_no-spam@qwest-spam-no.invalid>
Re: DBIx::Simple, fails with no error (not CGI this tim <justin.0706@purestblue.com>
Re: FAQ 1.6 What is perl6? <tadmc@seesig.invalid>
Re: FAQ 2.11 Perl Books <tadmc@seesig.invalid>
localtime and mktime <mhearne808@gmail.com>
Re: localtime and mktime <Alberto.Schiano@gmail.com>
Re: localtime and mktime <attn.steven.kuo@gmail.com>
Re: map woes <bik.mido@tiscalinet.it>
Re: map woes <wahab-mail@gmx.de>
Re: new in CGI::Session::Driver::postgredsql nonexistin <gautam.chekuri@gmail.com>
Re: new in CGI::Session::Driver::postgredsql nonexistin <ulvinge@gmail.com>
Re: new in CGI::Session::Driver::postgredsql nonexistin <glex_no-spam@qwest-spam-no.invalid>
Re: new in CGI::Session::Driver::postgredsql nonexistin <gautam.chekuri@gmail.com>
Re: new in CGI::Session::Driver::postgredsql nonexistin <ulvinge@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 28 Jun 2007 21:10:31 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: "Convert" perl command line to simple script
Message-Id: <slrnf888u8.sud.glennj@smeagol.ncf.ca>
At 2007-06-28 02:55PM, "Joe Smith" wrote:
> > bluez34me@gmail.com schreef:
> >
> >> perl -pi -e 's/..\index/index/g' *.html
>
> I'm inclined to believe the original poster made a typo. More sensible would be:
>
> perl -pi -e 's/.\.index/index/g' *.html
I thought he meant that he wanted to find links to the index page in the
parent directory and change it to this directory, but he was using the
Windows directory separator. i.e.:
$s = '<a href="..\index.html">';
$r = '..\index';
$s =~ s/\Q$r/index/g;
But only the OP knows.
--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
------------------------------
Date: Thu, 28 Jun 2007 17:45:08 -0700
From: chanio <Alberto.Schiano@gmail.com>
Subject: Re: "Convert" perl command line to simple script
Message-Id: <1183077908.426169.282020@q69g2000hsb.googlegroups.com>
You say that the perl oneliners cannot translate into a script...
But, you can copy a script to run in the command-line (Linux 'only'):
As always, start with...
perl -e'
Then, press <Enter> and paste the complete script...
End with ' as usual.
Note, you should not have any ' in the script, though...
If the script has something like
$hello = 'Hello' ;
you should change it to...
$hello = q( hello ) ;
If you leave any ' then the script editing will end at that point and
start executing,,,
Linux is very 'perl friendly'.
You could learn a lot from this simetry.
------------------------------
Date: Thu, 28 Jun 2007 13:37:20 -0700
From: fzxdf5@gmail.com
Subject: 2 dimentional data call within a conditional
Message-Id: <1183063040.762245.23560@o61g2000hsh.googlegroups.com>
Greetings,
I am trying to get this snippet to run...but it fails at the
conditional "if" portion.
I think the problem lies in the ...m/\$data[$r][0]\b/...build
portion. I've even 'built" the search expression around a non-arrayed
variable with no luck
What am I doing wrong?
@data= ( ["junk",3,1,3,4], ["trash",4,2,3,4,6] );
@money = ( "junk", "trash");
for ($r=0; $r<2; $r++)
{
if ($money[$r] =~ m/\$data[$r][0]\b/ )
{
print "data[$r][0] = $data[$r]->[0]\n";
}
}
------------------------------
Date: Thu, 28 Jun 2007 15:49:50 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: 2 dimentional data call within a conditional
Message-Id: <46841eef$0$10307$815e3792@news.qwest.net>
fzxdf5@gmail.com wrote:
> Greetings,
>
> I am trying to get this snippet to run...but it fails at the
> conditional "if" portion.
What fails?
>
> I think the problem lies in the ...m/\$data[$r][0]\b/...build
> portion. I've even 'built" the search expression around a non-arrayed
> variable with no luck
No idea what a 'build portion' is..
>
> What am I doing wrong?
use strict;
use warnings;
>
> @data= ( ["junk",3,1,3,4], ["trash",4,2,3,4,6] );
>
> @money = ( "junk", "trash");
>
> for ($r=0; $r<2; $r++)
> {
> if ($money[$r] =~ m/\$data[$r][0]\b/ )
^ no need to escape the '$'.
if ($money[$r] =~ m/$data[$r][0]\b/ )
Why use a match at all??
if( $money[ $r ] eq $data[$r][0] )
> {
> print "data[$r][0] = $data[$r]->[0];
print "data[$r][0]=$data[$r][0]\n";
> }
> }
>
------------------------------
Date: Thu, 28 Jun 2007 23:21:53 -0000
From: Justin C <justin.0706@purestblue.com>
Subject: Re: DBIx::Simple, fails with no error (not CGI this time!)
Message-Id: <slrnf88gkv.en1.justin.0706@satori.local>
In article <1183050172.985662.257880@g4g2000hsf.googlegroups.com>, Paul Lalli wrote:
> On Jun 28, 10:15 am, Justin C <justin.0...@purestblue.com> wrote:
>> My program connects to a database, and is to insert a row into a table.
>> It runs with no errors or warnings but the database is not updated.
>> There is nothing in the Postgresql log either.
>>
>> Here is the code, it's a small as I can make it:
>>
>> #!/usr/bin/perl
>>
>> use warnings ;
>> use strict ;
>> use DBIx::Simple ;
>> use SQL::Abstract ;
>>
>> my $user = "[user]" ;
>> my $password = "[passwd]" ;
>> my $dataSource = DBIx::Simple->connect(
>> 'dbi:Pg:database=prospects', $user, $password,
>> { RaiseError => 1 , AutoCommit => 0 }
>
> You've turned off auto-commit, but never actually comitted your work.
> Either turn AutoCommit back on, or explicitly commit your data. I
> recommend a block similar to:
>
> END {
> if ($?) { # exiting with error
> $dataSource->rollback();
> } else { # success
> $dataSource->commit();
> }
> }
>
> Paul Lalli
Hello, again, Paul. I read a lot of documentation for Perl modules that
work with postgresql, so many that when I got to DBIx::Simple I may have
skimped, and skipped straight to the examples... That and I *always* get
confused by boolean 0/1 and which is which... mind you, I should have
been prompted by the RaiseError => 1. The situation isn't helped by the
fact that I've no SQL experience (learning as I'm going along) and I'm
no Perl expert either - but I know more than I do SQL.
Looking at your suggestion, I understand what you're suggesting, but I
don't fully understand your code... no, that's not true, I don't
understand: "END { "
Maybe I'm showing how green I really am. I can see you're testing for
errors, I understand the rollback, and commit. I can't find, in perldoc
-q or -f anything relating to an 'END'. Could you point me at some docs
to explain what is going on there? I know there is a need to trap out
errors if the database throws back an error, at the moment I'm trying to
get to a point of working code, the error trapping would come along
next, honest!
Thanks for the help with the problem.
Justin.
--
Justin C, by the sea.
------------------------------
Date: Fri, 29 Jun 2007 00:04:35 GMT
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: FAQ 1.6 What is perl6?
Message-Id: <slrnf88ggd.o52.tadmc@tadmc30.sbcglobal.net>
Art VanDelay <art@xiotek.com> wrote:
> Tad McClellan wrote:
>> Jim Carlock <anonymous@127.0.0.1> wrote:
>> > "Tad McClellan" wrote:
>
>> > > Like acceptable spelling.
>> > >
>> > > If some famous Perl guy would of jsut implemented a
>> > > spell-correcting 'bot, then things would of been a lot better
>> > > around here...
>
>> > Acceptable grammar? "would have been" or "would of been"?
>
>> Yes, I know. You missed the joke.
>>
>> I was mocking the troll by repeating his characteristic foibles
>> from earlier appearances here.
>
>
> Unlike someone who attacks without any provocation
It provoked us plenty when it was here last.
> nor provides any
> proof to back up their arguments?
I predicted on June 22 that it would eventually type "jsut" or
"would of", and it did so on June 28.
Am I prescient or did I just recognize its modus operandi?
I believe most people will find the later to be more likely...
> What you're doing looks to me a lot more like trolling than anything the
> accused has done in this thread.
You *are* the accused.
Assuming another persona is the only way it/you can appear to be
getting any support. You've done it so many times that only the
gullible or uninitiated would fall for it now.
I am neither, BTW.
> All you've done is sparked an off topic
> tangent thread that's a waste of bandwidth and spool capacity.
If it helps people to ignore you, then it is not a waste, it
is a service to the commmunity.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Fri, 29 Jun 2007 00:04:35 GMT
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: FAQ 2.11 Perl Books
Message-Id: <slrnf88gji.o52.tadmc@tadmc30.sbcglobal.net>
Clenna Lumina <savagebeaste@yahoo.com> wrote:
> PerlFAQ Server wrote:
>
>> Intermediate Perl (the "Alpaca Book")
>
> I could swear I've always seen this referred to as the "llama" book? Or
> are there two different books?
There are two different books (I am intimately familiar with both).
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Thu, 28 Jun 2007 21:45:11 -0000
From: "mhearne808[insert-at-sign-here]gmail[insert-dot-here]com" <mhearne808@gmail.com>
Subject: localtime and mktime
Message-Id: <1183067111.295731.215260@q75g2000hsh.googlegroups.com>
I think have a fundamental misunderstanding of one of either
localtime() or mktime(). Here's a snippet of code that illustrates
what I find confusing:
#############################
use Time::Local;
use POSIX;
$unixtime4 = time();
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime($unixtime4);
$unixtime5 = mktime($sec,$min,$hour,$mday,$mon,$year);
print STDERR "Time4: $unixtime4\n";
print STDERR "Time5: $unixtime5\n";
#############################
I would expect that $unixtime4 and $unixtime5 would be identical -
however, they are different by exactly 1 hour (on Mac OS X and Linux
RHEL).
Can anyone explain to me why this is?
--Mike
------------------------------
Date: Thu, 28 Jun 2007 14:57:50 -0700
From: chanio <Alberto.Schiano@gmail.com>
Subject: Re: localtime and mktime
Message-Id: <1183067870.118472.239280@q75g2000hsh.googlegroups.com>
mhearne808[insert-at-sign-here]gmail[insert-dot-here]com ha escrito:
> I think have a fundamental misunderstanding of one of either
> localtime() or mktime(). Here's a snippet of code that illustrates
> what I find confusing:
>
> #############################
> use Time::Local;
> use POSIX;
>
> $unixtime4 = time();
> ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
> localtime($unixtime4);
> $unixtime5 = mktime($sec,$min,$hour,$mday,$mon,$year);
>
> print STDERR "Time4: $unixtime4\n";
> print STDERR "Time5: $unixtime5\n";
> #############################
>
> I would expect that $unixtime4 and $unixtime5 would be identical -
> however, they are different by exactly 1 hour (on Mac OS X and Linux
> RHEL).
>
> Can anyone explain to me why this is?
>
> --Mike
Right!
But please, check your system time configuration.
Your script works well.
I get the following result...
Time4: 1183067516
Time5: 1183067516
See?
Find out your locale with POSIX
here, everything Ok (and I live in Argentina, TZ -03)
alberto
------------------------------
Date: Thu, 28 Jun 2007 15:18:16 -0700
From: "attn.steven.kuo@gmail.com" <attn.steven.kuo@gmail.com>
Subject: Re: localtime and mktime
Message-Id: <1183069096.121021.259320@e16g2000pri.googlegroups.com>
On Jun 28, 2:45 pm, "mhearne808[insert-at-sign-here]gmail[insert-dot-
here]com" <mhearne...@gmail.com> wrote:
> I think have a fundamental misunderstanding of one of either
> localtime() or mktime(). Here's a snippet of code that illustrates
> what I find confusing:
>
> #############################
> use Time::Local;
> use POSIX;
>
> $unixtime4 = time();
> ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
> localtime($unixtime4);
> $unixtime5 = mktime($sec,$min,$hour,$mday,$mon,$year);
>
> print STDERR "Time4: $unixtime4\n";
> print STDERR "Time5: $unixtime5\n";
> #############################
>
> I would expect that $unixtime4 and $unixtime5 would be identical -
> however, they are different by exactly 1 hour (on Mac OS X and Linux
> RHEL).
>
> Can anyone explain to me why this is?
Forgot to specify Daylight Saving Time to mktime?
use Data::Dumper;
use POSIX;
my $u4 = time();
my @fields = localtime($u4);
splice(@fields, 6, 2, (0, 0));
print Dumper \@fields;
my $u5 = POSIX::mktime(@fields);
print Dumper [ $u4, $u5 ];
--
Hope this helps,
Steven
------------------------------
Date: Thu, 28 Jun 2007 23:54:18 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: map woes
Message-Id: <g8b8831c7gg3ppnehbkrnit2nt77rqrjs6@4ax.com>
On Thu, 28 Jun 2007 11:45:00 -0700, Joe Smith <joe@inwap.com> wrote:
>Others have pointed out how to do it. I just want to point out the
>comma operator, and how it could be used in this context.
>
> map {s/(\d+)\.news/$1/, $_}
Well, since it's a BLOCK-map(), it can be a semicolon, i.e. two
different statements. In which case it still sports a side effect that
is not what map() should really be for. And then there's a also a risk
of strange behaviours about which I learnt here and reported
elsewhere:
http://perlmonks.org/?node_id=623600
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: Thu, 28 Jun 2007 22:24:38 +0200
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: map woes
Message-Id: <f61cql$145$1@mlucom4.urz.uni-halle.de>
seven.reeds wrote:
> I can open the dir. I can readdir() to get the filenames, grep() to
> get the "\d+\.zone" files but now I want to pull off the numbers, sort
> them numericaly highest to lowest and store them for later use. I
> have tried
>
> my @list =
> sort {$b <=> $a}
> map {s/(\d+)\.news/$1/}
> grep(/\d+\.news/, readdir(NEWSDIR));
>
> The readdir and grep work as I expect. The result of the map is a
> list of "1"s, prolly the count of successful s// matches. Where am I
> messing this up?
There have been correct answers already, but I'll
add another version to the dozen (what I think what would
be somehow appropriate) ...
...
sub descending { $b<=>$a }
...
opendir my $dirh, '.' or die "cant't opendir!$!";
my @list = sort descending map /\d+(?=\.news)/g, readdir $dirh;
closedir $dirh;
...
Regards
M.
------------------------------
Date: Thu, 28 Jun 2007 21:12:36 -0000
From: gautam chekuri <gautam.chekuri@gmail.com>
Subject: Re: new in CGI::Session::Driver::postgredsql nonexisting
Message-Id: <1183065156.943727.184750@g37g2000prf.googlegroups.com>
On Jun 29, 1:04 am, IDK <ulvi...@gmail.com> wrote:
> On Jun 28, 9:46 pm, "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
> wrote:
>
>
>
> > IDK wrote:
> > > On Jun 28, 8:38 pm, goodgautam <gautam.chek...@gmail.com> wrote:
> > >> In your code the first param being passed to CGI::Session's
> > >> constructor reads : "driver:postgredsql;id:md5" ..
> > >> Is that a typo in the code too ( s~postgredsql~postgresql~; ) ? I
> > >> think it should be like driver:postgresql ...http://search.cpan.org/dist/CGI-Session/lib/CGI/Session/Driver/postgr...
>
> > > Wow, that's it!
> > > Thanks!
>
> > > But now it gives me another error:
>
> > Now you should do some debugging before posting another error.
>
> > > [Thu Jun 28 20:52:39 2007] login: (in cleanup) Can't connect to
> > > data source '' because I can't work out what driver to use (it doesn't
> > > seem to contain a 'dbi:driver:' prefix and the DBI_DRIVER env var is
> > > not set) at /usr/share/perl5/CGI/Session/Driver/DBI.pm line 26
> > > [Thu Jun 28 20:52:39 2007] login: (in cleanup) Can't call method
> > > "commit" on unblessed reference at /usr/share/perl5/CGI/Session/Driver/
> > > DBI.pm line 130 during global destruction.
Niklas,
Are you sure you are passing the all the params correctly in your
program ?
I use CGI::Session version 4.20 .. and it all works fine ..
[root@deepdark gautam]# perl -MCGI::Session -e 'print
$CGI::Session::VERSION, "\n";'
4.20
If you are sure that your program is correct, you might want to run it
under the debugger and
see what arguments are being passed to DBI->connect( ) from the code
in /usr/share/perl5/CGI/Session/Driver/DBI.pm at line 26
One thing that we can be sure of from the error msg you pasted is that
DBI->connect didn't get its params correctly ...
- Gautam
------------------------------
Date: Thu, 28 Jun 2007 21:21:21 -0000
From: IDK <ulvinge@gmail.com>
Subject: Re: new in CGI::Session::Driver::postgredsql nonexisting
Message-Id: <1183065681.347218.260720@u2g2000hsc.googlegroups.com>
On Jun 28, 11:12 pm, gautam chekuri <gautam.chek...@gmail.com> wrote:
> > > > [Thu Jun 28 20:52:39 2007] login: (in cleanup) Can't connect to
> > > > data source '' because I can't work out what driver to use (it doesn't
> > > > seem to contain a 'dbi:driver:' prefix and the DBI_DRIVER env var is
> > > > not set) at /usr/share/perl5/CGI/Session/Driver/DBI.pm line 26
> > > > [Thu Jun 28 20:52:39 2007] login: (in cleanup) Can't call method
> > > > "commit" on unblessed reference at /usr/share/perl5/CGI/Session/Driver/
> > > > DBI.pm line 130 during global destruction.
>
> Niklas,
>
> Are you sure you are passing the all the params correctly in your
> program ?
>
> I use CGI::Session version 4.20 .. and it all works fine ..
> [root@deepdark gautam]# perl -MCGI::Session -e 'print
> $CGI::Session::VERSION, "\n";'
> 4.20
>
> If you are sure that your program is correct, you might want to run it
> under the debugger and
> see what arguments are being passed to DBI->connect( ) from the code
> in /usr/share/perl5/CGI/Session/Driver/DBI.pm at line 26
>
> One thing that we can be sure of from the error msg you pasted is that
> DBI->connect didn't get its params correctly ...
>
> - Gautam
A conclusion I got to some time ago was that somehow my parameters
don't
get to the func:
package CGI::Session::Driver::DBI;
sub init {
my $self = shift;
if ( defined $self->{Handle} ) {
...
}
else {
line 26
}
}
And my line:
$session = new CGI::Session("driver:postgresql;id:md5", undef,
{Handle=>$dbh, ColumnType=>"binary"});
{Handle} doesn't seem to get to init, and as I'm not very good at
perl, I don't know why...
The dbh handle is working, and I've written the session code exactly
as instructed by
the docs, so my conclusion is that either the docs or libraries are
wrong. But I may
have misinterpreted the docs...
------------------------------
Date: Thu, 28 Jun 2007 17:19:21 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: new in CGI::Session::Driver::postgredsql nonexisting
Message-Id: <468433e9$0$490$815e3792@news.qwest.net>
IDK wrote:
> $session = new CGI::Session("driver:postgresql;id:md5", undef,
> {Handle=>$dbh, ColumnType=>"binary"});
I don't use it, however to try to help you, I scanned the
documentation for the current CGI::Session on CPAN and this
might be of interest:
Following data source components are supported:
driver - CGI::Session driver. Available drivers are file, db_file, mysql
and sqlite.
If there is a driver for PostgreSQL, it's not mentioned.
Also,
SUPPORT
If you need help using CGI::Session consider the mailing list. You can
ask the list by sending your questions to
cgi-session-user@lists.sourceforge.net .
You can subscribe to the mailing list at
https://lists.sourceforge.net/lists/listinfo/cgi-session-user .
>
> {Handle} doesn't seem to get to init, and as I'm not very good at
> perl, I don't know why...
Either do we.
There's no mention of Handle or ColumnType in the documentation, that I
could see.
>
> The dbh handle is working, and I've written the session code exactly
> as instructed by
> the docs, so my conclusion is that either the docs or libraries are
> wrong. But I may have misinterpreted the docs...
Post a short example. <10 lines should cover it. We don't need to
see the code from CGI::Session, only your code and what errors
you receive.
------------------------------
Date: Thu, 28 Jun 2007 22:44:22 -0000
From: gautam chekuri <gautam.chekuri@gmail.com>
Subject: Re: new in CGI::Session::Driver::postgredsql nonexisting
Message-Id: <1183070662.886454.256140@j4g2000prf.googlegroups.com>
On Jun 29, 3:19 am, "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
wrote:
> IDK wrote:
> > $session = new CGI::Session("driver:postgresql;id:md5", undef,
> > {Handle=>$dbh, ColumnType=>"binary"});
>
> I don't use it, however to try to help you, I scanned the
> documentation for the current CGI::Session on CPAN and this
> might be of interest:
>
> Following data source components are supported:
>
> driver - CGI::Session driver. Available drivers are file, db_file, mysql
> and sqlite.
>
> If there is a driver for PostgreSQL, it's not mentioned.
>
> Also,
>
> SUPPORT
>
> If you need help using CGI::Session consider the mailing list. You can
> ask the list by sending your questions to
> cgi-session-u...@lists.sourceforge.net .
>
> You can subscribe to the mailing list athttps://lists.sourceforge.net/lists/listinfo/cgi-session-user.
>
>
>
> > {Handle} doesn't seem to get to init, and as I'm not very good at
> > perl, I don't know why...
>
> Either do we.
>
> There's no mention of Handle or ColumnType in the documentation, that I
> could see.
>
>
>
> > The dbh handle is working, and I've written the session code exactly
> > as instructed by
> > the docs, so my conclusion is that either the docs or libraries are
> > wrong. But I may have misinterpreted the docs...
>
> Post a short example. <10 lines should cover it. We don't need to
> see the code from CGI::Session, only your code and what errors
> you receive.
well.. the pgsql driver is a third party implementation based on
CGI::Session::Driver
http://search.cpan.org/~sherzodr/CGI-Session-4.10/lib/CGI/Session/Driver/postgresql.pm
Niklas, as suggested by J.G a short example ( without typos etc.. )
would be very helpfull..
i would suggest you turn on strict and warnings in this example..
Such small examples act as test cases, that help in understanding the
problem...
for eg, I did this and I see that things are working fine :
[root@deepdark gautam]# cat ./session.pl
#!/usr/bin/perl
use strict;
use warnings;
use CGI::Session;
use DBI;
my $dbh = DBI->connect("dbi:Pg:dbname=test;host=localhost;port=5432",
"USERNAME", "");
if ( !defined $dbh ) {
die "Cannot connect to database!\n";
}
my $session = new CGI::Session(
"driver:postgresql:id:md5",
undef,
{
Handle => $dbh,
ColumnType => "binary",
}
);
my $CGISESSID = $session->id();
print $session->header();
[root@deepdark gautam]# ./session.pl
Set-Cookie: CGISESSID=1d75a870d52ed9c6064cdb52e406ea49; path=/
Date: Thu, 28 Jun 2007 22:41:23 GMT
Content-Type: text/html; charset=ISO-8859-1
[root@deepdark gautam]#
------------------------------
Date: Thu, 28 Jun 2007 23:18:03 -0000
From: IDK <ulvinge@gmail.com>
Subject: Re: new in CGI::Session::Driver::postgredsql nonexisting
Message-Id: <1183072683.808678.261560@w5g2000hsg.googlegroups.com>
On Jun 29, 12:44 am, gautam chekuri <gautam.chek...@gmail.com> wrote:
> On Jun 29, 3:19 am, "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
> wrote:
>
>
>
> > IDK wrote:
> > > $session = new CGI::Session("driver:postgresql;id:md5", undef,
> > > {Handle=>$dbh, ColumnType=>"binary"});
>
> > I don't use it, however to try to help you, I scanned the
> > documentation for the current CGI::Session on CPAN and this
> > might be of interest:
>
> > Following data source components are supported:
>
> > driver - CGI::Session driver. Available drivers are file, db_file, mysql
> > and sqlite.
>
> > If there is a driver for PostgreSQL, it's not mentioned.
>
> > Also,
>
> > SUPPORT
>
> > If you need help using CGI::Session consider the mailing list. You can
> > ask the list by sending your questions to
> > cgi-session-u...@lists.sourceforge.net .
>
> > You can subscribe to the mailing list athttps://lists.sourceforge.net/lists/listinfo/cgi-session-user.
>
> > > {Handle} doesn't seem to get to init, and as I'm not very good at
> > > perl, I don't know why...
>
> > Either do we.
>
> > There's no mention of Handle or ColumnType in the documentation, that I
> > could see.
>
> > > The dbh handle is working, and I've written the session code exactly
> > > as instructed by
> > > the docs, so my conclusion is that either the docs or libraries are
> > > wrong. But I may have misinterpreted the docs...
>
> > Post a short example. <10 lines should cover it. We don't need to
> > see the code from CGI::Session, only your code and what errors
> > you receive.
>
> well.. the pgsql driver is a third party implementation based on
> CGI::Session::Driverhttp://search.cpan.org/~sherzodr/CGI-Session-4.10/lib/CGI/Session/Dri...
>
> Niklas, as suggested by J.G a short example ( without typos etc.. )
> would be very helpfull..
> i would suggest you turn on strict and warnings in this example..
> Such small examples act as test cases, that help in understanding the
> problem...
>
> for eg, I did this and I see that things are working fine :
>
> [root@deepdark gautam]# cat ./session.pl
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> use CGI::Session;
> use DBI;
>
> my $dbh = DBI->connect("dbi:Pg:dbname=test;host=localhost;port=5432",
> "USERNAME", "");
> if ( !defined $dbh ) {
> die "Cannot connect to database!\n";
>
> }
>
> my $session = new CGI::Session(
> "driver:postgresql:id:md5",
> undef,
> {
> Handle => $dbh,
> ColumnType => "binary",
> }
> );
>
How can the above code work?
"driver:postgresql:id:md5" should be "driver:postgresql;id:md5".
Atleast as I interpret the docs...
The postgres driver is included my package.
With strict I only get loads of:
login: Global symbol "$s" requires explicit package name at ./login
line 25.
And I always has warn on.
Here's all my code:
****************************** login *************************
#!/usr/bin/perl -w
use funcs;
use Digest::SHA1 qw(sha1_base64);
#use strict;
makeHTML('register');
if(!param('user')){
print '<form name="input" action="login" method="post">
Username: <input type="text" name="user"><BR>
Password: <input type="password" name="password"><BR>
<input type="submit" value="Submit">
</form>';
}else{
$user = param('user');
$pass = param('password');
$digest = sha1_base64($pass);
$s = sqlQuerry("SELECT id, pass FROM zerus.players WHERE
name='$user'")
or die "cannot prepare";
@data = $s->fetchrow();
if($data[1] eq $digest){
print "\n<H1>You've successfully logged on</H1>\n"
} else {
print "\n<H1>Wrong password, or no user with that name</H1>
\n"
}
$s->finish or die "Cannot finnish";
}
finnishUp();
********************************** funcs.pm
************************************
use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);
use DBI;
#use Apache::Session::Postgres;
use DBD::Pg qw(:pg_types);
use CGI::Session;
use CGI::Session::Driver::postgresql;
use CGI::Session::ID::md5;
use CGI::Session::Serialize::default;
sub openDB
{
#open db
$dbh = DBI->connect("dbi:Pg:dbname=zerus;host=localhost;port=5432",
"*", "*");
if ( !defined $dbh ) {
die "Cannot connect to database!\n";
}
}
sub makeHTML
{
# Get the CGI form data
print "<HTML><TITLE>${_[0]}</TITLE><BODY bgcolor='\#000000'
text='\#aaa666'>";
}
sub sqlQuerry
{
$sth = $dbh->prepare($_[0]);
if ( !defined $sth ) {
die "Cannot prepare statement: $DBI::errstr\n";
}
$sth->execute;
$sth;
}
sub finnishUp
{
print end_html();
print $@, "<BR>\n";
if(defined($DBI)){ print $DBI::errstr, "<BR>\n"; }
eval { $dbh->disconnect; };
}
openDB;
$session = new CGI::Session("driver:postgresql;id:md5", undef,
{Handle=>$dbh, ColumnType=>"binary"});
$CGISESSID = $session->id();
# send proper HTTP header with cookies:
print $session->header();
#$cgi = new CGI;
#print header();
*************************************************************************
If I replace all the session stuff with the commented out stuff, I get
no
errors.
This is the output:
Set-Cookie: CGISESSID=d07adf2adfd6ded310af61f101c1bed1; path=/
Date: Thu, 28 Jun 2007 23:13:37 GMT
Content-Type: text/html; charset=ISO-8859-1
<HTML><TITLE>register</TITLE><BODY bgcolor='#000000'
text='#aaa666'><form name="input" action="login" method="post">
Username: <input type="text" name="user"><BR>
Password: <input type="password" name="password"><BR>
<input type="submit" value="Submit">
</form>
</body>
</html><BR>
[Fri Jun 29 01:13:37 2007] login: (in cleanup) Can't connect to
data source '' because I can't work out what driver to use (it doesn't
seem to contain a 'dbi:driver:' prefix and the DBI_DRIVER env var is
not set) at /usr/share/perl5/CGI/Session/Driver/DBI.pm line 26
[Fri Jun 29 01:13:37 2007] login: (in cleanup) Can't call method
"commit" on unblessed reference at /usr/share/perl5/CGI/Session/Driver/
DBI.pm line 130 during global destruction.
*************************************************************
------------------------------
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 597
**************************************