[18829] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 997 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun May 27 14:05:37 2001

Date: Sun, 27 May 2001 11:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <990986709-v10-i997@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 27 May 2001     Volume: 10 Number: 997

Today's topics:
        anyone know why this wont send USERMAIL (script include <rickdeckard@onetel.net.uk>
    Re: anyone know why this wont send USERMAIL (script inc (Randal L. Schwartz)
    Re: anyone know why this wont send USERMAIL (script inc <rickdeckard@onetel.net.uk>
    Re: Calling function reference <kris.verbeeck@chello.be>
        Cannot traverse my own structure... <steffi@shell8.ba.best.com>
    Re: CGI and printing vars <goldbb2@earthlink.net>
        Clarification and question about FAQ <db9@NOSPAM.com>
    Re: Clarification and question about FAQ (Randal L. Schwartz)
    Re: Clarification and question about FAQ <db91@NOSPAM.com>
    Re: dbi, fork and ipc-shareable - having problems <djberg96@hotmail.com>
        How to connect to MSAccess db w/o creating DSN <sdozois@videotron.ca>
    Re: How to connect to MSAccess db w/o creating DSN <bkennedy99@Home.com>
    Re: How to connect to MSAccess db w/o creating DSN <sdozois@videotron.ca>
    Re: Locking files in CGI fails (or not?) <nobody@dev.null>
    Re: Locking files in CGI fails (or not?) (Tad McClellan)
    Re: Perl 5.6.1 on SCO5.0.4 - Problem with dynamic loadi <ppporch@home.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sun, 27 May 2001 16:24:14 +0100
From: "Deckard" <rickdeckard@onetel.net.uk>
Subject: anyone know why this wont send USERMAIL (script included)
Message-Id: <3b111b3b@news-uk.onetel.net.uk>

Hi, i am a newbie @ perl, so there is probably something intrinsically wrong
with this script, something simple, out of place or incorrect for more
experienced eyes, i just cannot get it to send out the USERMAIL part of the
script, i get the ADMIN EMAIL no probs. As far as i can see, i would say it
all seems to sync-in nicely with the HTML form, the names of the inputs etc.
i have been trying all day with no luck, any suggestions or help would be
very nice :)

here is the html page: http://www.johnshone.com/newlinks.html/

and here is the script:

#!/usr/bin/perl
############################################################
# Appraisal Form to Email
Version 1.0              #
# Created 27/05/2001                                          Last Modified
27/05/2001 #
# (C)2001
Rick Deckard             #
############################################################

$doneurl = 'http://www.johnshone.com/index.html';
$mailprog = '/usr/sbin/sendmail';

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
   ($name, $value) = split(/=/, $pair);
   $value =~ tr/+/ /;
   $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
   $value =~ s/<!--(.|\n)*-->//g;
   $value =~ s/<([^>]|\n)*>//g;
   $FORM{$name} = $value;
}

open (ADMINMAIL, "|$mailprog -t") || die "Can't open $mailprog!\n";

   print ADMINMAIL "To: rickdeckard\@onetel.net.uk\n";
   print ADMINMAIL "From: $FORM{'yourname'}\n";
   print ADMINMAIL "Subject: Customer Appraisal\n\n";
   print ADMINMAIL "Dear John,\n\n";
   print ADMINMAIL "   Congratulations,\n";
   print ADMINMAIL "   A viewer of your site has chosen to send\n";
   print ADMINMAIL "   details of your website to a number of there\n";
   print ADMINMAIL "   friends, so that they can also come and visit\n";
   print ADMINMAIL "   The details of there submission are below...\n\n";
   print ADMINMAIL "   All the best, rickdeckard\@onetel.net.uk\n\n";
   print ADMINMAIL "--------------------------------------------------\n";
   print ADMINMAIL "Name: $FORM{'yourname'}\n";
   print ADMINMAIL "Email: $FORM{'email'}\n";
   print ADMINMAIL "Has sent the following people your site details\n";
   print ADMINMAIL "--------------------------------------------------\n";
   print ADMINMAIL "Friend 1 Name:  $FORM{'friend1'}\n";
   print ADMINMAIL "              Email: $FORM{'friendemail1'}\n";
   print ADMINMAIL "--------------------------------------------------\n";
   print ADMINMAIL "Friend 2 Name:  $FORM{'friend2'}\n";
   print ADMINMAIL "              Email: $FORM{'friendemail2'}\n";
   print ADMINMAIL "--------------------------------------------------\n";
   print ADMINMAIL "Friend 3 Name:  $FORM{'friend3'}\n";
   print ADMINMAIL "              Email: $FORM{'friendemail3'}\n";
   print ADMINMAIL "--------------------------------------------------\n";
   print ADMINMAIL "Comments:\n";
   print ADMINMAIL "$FORM{'comments'}\n";
   print ADMINMAIL "--------------------------------------------------\n";

close (ADMINMAIL);

print "Location: $doneurl\n\n";


open (USERMAIL, "|$mailprog -t") || die "Can't open $mailprog!\n";

   print USERMAIL "To: $FORM{'friendemail1'}\n";
   print USERMAIL "From: john\@johnshone.com\n";
   print USERMAIL "Subject: Your friend has sent you info & a website
link\n\n";
   print USERMAIL "Dear $FORM{'friend1'},\n\n";
   print USERMAIL "RE: website link\n";
   print USERMAIL "$FORM{'comments'}\n";

close (USERMAIL);


exit;


regards
Rick




------------------------------

Date: 27 May 2001 08:49:16 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: anyone know why this wont send USERMAIL (script included)
Message-Id: <m1d78ux05f.fsf@halfdome.holdit.com>

>>>>> "Deckard" == Deckard  <rickdeckard@onetel.net.uk> writes:

Deckard> Hi, i am a newbie @ perl, so there is probably something intrinsically wrong
Deckard> with this script,

Yes.

1) it doesn't use CGI
2) it can send untraceable mail in a DOS attack to another user

Please remove it at once.

-- 
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!


------------------------------

Date: Sun, 27 May 2001 16:59:07 +0100
From: "Deckard" <rickdeckard@onetel.net.uk>
Subject: Re: anyone know why this wont send USERMAIL (script included)
Message-Id: <3b112367@news-uk.onetel.net.uk>

please ignore this email, as thanks to Randal, i have now realized the
errors of this way of doing it, it will be ammended using the correct
procedure when i figure out how to do so

thanks
Rick
"Deckard" <rickdeckard@onetel.net.uk> wrote in message
news:3b111b3b@news-uk.onetel.net.uk...
> Hi, i am a newbie @ perl, so there is probably something intrinsically
wrong
> with this script, something simple, out of place or incorrect for more
> experienced eyes, i just cannot get it to send out the USERMAIL part of
the
> script, i get the ADMIN EMAIL no probs. As far as i can see, i would say
it
> all seems to sync-in nicely with the HTML form, the names of the inputs
etc.
> i have been trying all day with no luck, any suggestions or help would be
> very nice :)
>
> here is the html page: http://www.johnshone.com/newlinks.html/
>
> and here is the script:
>
> #!/usr/bin/perl
> ############################################################
> # Appraisal Form to Email
> Version 1.0              #
> # Created 27/05/2001                                          Last
Modified
> 27/05/2001 #
> # (C)2001
> Rick Deckard             #
> ############################################################
>
> $doneurl = 'http://www.johnshone.com/index.html';
> $mailprog = '/usr/sbin/sendmail';
>
> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
> @pairs = split(/&/, $buffer);
> foreach $pair (@pairs) {
>    ($name, $value) = split(/=/, $pair);
>    $value =~ tr/+/ /;
>    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
>    $value =~ s/<!--(.|\n)*-->//g;
>    $value =~ s/<([^>]|\n)*>//g;
>    $FORM{$name} = $value;
> }
>
> open (ADMINMAIL, "|$mailprog -t") || die "Can't open $mailprog!\n";
>
>    print ADMINMAIL "To: rickdeckard\@onetel.net.uk\n";
>    print ADMINMAIL "From: $FORM{'yourname'}\n";
>    print ADMINMAIL "Subject: Customer Appraisal\n\n";
>    print ADMINMAIL "Dear John,\n\n";
>    print ADMINMAIL "   Congratulations,\n";
>    print ADMINMAIL "   A viewer of your site has chosen to send\n";
>    print ADMINMAIL "   details of your website to a number of there\n";
>    print ADMINMAIL "   friends, so that they can also come and visit\n";
>    print ADMINMAIL "   The details of there submission are below...\n\n";
>    print ADMINMAIL "   All the best, rickdeckard\@onetel.net.uk\n\n";
>    print ADMINMAIL "--------------------------------------------------\n";
>    print ADMINMAIL "Name: $FORM{'yourname'}\n";
>    print ADMINMAIL "Email: $FORM{'email'}\n";
>    print ADMINMAIL "Has sent the following people your site details\n";
>    print ADMINMAIL "--------------------------------------------------\n";
>    print ADMINMAIL "Friend 1 Name:  $FORM{'friend1'}\n";
>    print ADMINMAIL "              Email: $FORM{'friendemail1'}\n";
>    print ADMINMAIL "--------------------------------------------------\n";
>    print ADMINMAIL "Friend 2 Name:  $FORM{'friend2'}\n";
>    print ADMINMAIL "              Email: $FORM{'friendemail2'}\n";
>    print ADMINMAIL "--------------------------------------------------\n";
>    print ADMINMAIL "Friend 3 Name:  $FORM{'friend3'}\n";
>    print ADMINMAIL "              Email: $FORM{'friendemail3'}\n";
>    print ADMINMAIL "--------------------------------------------------\n";
>    print ADMINMAIL "Comments:\n";
>    print ADMINMAIL "$FORM{'comments'}\n";
>    print ADMINMAIL "--------------------------------------------------\n";
>
> close (ADMINMAIL);
>
> print "Location: $doneurl\n\n";
>
>
> open (USERMAIL, "|$mailprog -t") || die "Can't open $mailprog!\n";
>
>    print USERMAIL "To: $FORM{'friendemail1'}\n";
>    print USERMAIL "From: john\@johnshone.com\n";
>    print USERMAIL "Subject: Your friend has sent you info & a website
> link\n\n";
>    print USERMAIL "Dear $FORM{'friend1'},\n\n";
>    print USERMAIL "RE: website link\n";
>    print USERMAIL "$FORM{'comments'}\n";
>
> close (USERMAIL);
>
>
> exit;
>
>
> regards
> Rick
>
>




------------------------------

Date: Sun, 27 May 2001 14:21:43 GMT
From: Kris Verbeeck <kris.verbeeck@chello.be>
Subject: Re: Calling function reference
Message-Id: <3B110E77.A74AE87A@chello.be>

nobull@mail.com wrote:

> > With a dispatch table, you mean a mapping between a string and a
> > hard ref, is that correct?  If so, then I would have to know which
> > functions are going to be called when I write the script and not
> > when I run the script.
> 
> Surely you need to know what functions are needed in order to write
> the functions in the first place?

Not if the functions already exist in separate packages.

> > What I'm working on only needs a text file that describes the
> > behaviour of the script through a set of rules.  The functions being
> > called here can be anything.
> 
> So, you are saying your configuration file can somehow instruct your
> script to import additional functions from other sources.

If it's completed, then it should be able to do that.

> > I don't need this script for something mission critical, just a small
> > tool that is general enough to be used in a variety of situations.
> 
> I can't be sure because I've not got all the facts but you have used
> the magic trigger phrase "small tool that is general".  It sounds to
> me very like you should be writing your tool as a module and writing
> the "configuration file" as a Perl script that uses that module.

The configuration file should be easy enough to be constructed by people
not familiar with perl.  That's why I only use plain text.


------------------------------

Date: Sun, 27 May 2001 17:38:59 GMT
From: Robert Nicholson <steffi@shell8.ba.best.com>
Subject: Cannot traverse my own structure...
Message-Id: <yl3bsoeu1xo.fsf@shell8.ba.best.com>

I'm building what I believe to be a structure that looks like this

{ cinemaName, ( { movieTitle, (show times) }, { movieTitle, (show times) } ) }

where the top level is a hash.

so I'm using the following code to build this thing

This returns the showTimes hash

sub parse_movie_td {
        my ($parser, $key) = @_;
        my @movie_listings = ();
        my @times = ();
        while ($token = $parser->get_token()) {
                my $type = $token->[0];
                my $title = '';
#               print "4:$key\n";

                if ($type eq 'S') {
                        if ($token->[1] eq 'td' &&
                                exists $token->[2]{width} &&
                                $token->[2]{width} eq '35%') {
                                $title = parse_movie_title($p,$key);
                        }
                        if ($token->[1] eq 'td' &&
                                exists $token->[2]{width} &&
                                $token->[2]{width} eq '60%') {
                                @times = parse_movie_showtimes($p,$key,$title);
                                my $rec = {};
                                $rec->{$title} = [@times]; 
                        }
                }

                if ($type eq 'E') {
                        if ($token->[1] eq 'tr') {
                                last;
                        }
                }
        }       
        return %times;
}

This collects all movies into the top level hash

There will be a separate pass through here for each cinema found

sub parse_movies {
        my ($parser, $key) = @_;
        my @listings = ();

        while ($token = $parser->get_token()) {
                my $type = $token->[0];
#               print "3:$key:$token->[1]\n";
                if ($type eq 'S') {
                        if ($token->[1] eq 'tr' &&
                                exists $token->[2]{bgcolor} &&
                                $token->[2]{bgcolor} eq '#FFFFFF') {
                                my @showtimes = ();
                                %rec = parse_movie_td($p,$key);
                                push @listings, { %rec };
                        }
                }
                if ($type eq 'E') {
                        if ($token->[1] eq 'table') {
                                $movies{$key} = [@listings];
                                last;
                        }
                }
        }
        print "leaving parse_movies\n";
}

When I print the structure out in the debugger I can see that I'm
almost there but I don't understand why there are empty hashes where
%rec is being used.

  DB<2> x %movies
0  'rat1'
1  ARRAY(0x4cac30)
   0  HASH(0x296b70)
        empty hash
   1  HASH(0x2964a4)
        empty hash
   2  HASH(0x296b58)
        empty hash
   3  HASH(0x296c9c)
        empty hash
   4  HASH(0x4c8db0)
        empty hash
   5  HASH(0x4c9448)
        empty hash
   6  HASH(0x4c8d2c)
        empty hash
   7  HASH(0x4c8f30)
        empty hash
   8  HASH(0x4c9cc0)
        empty hash
   9  HASH(0x4c9700)
        empty hash
   10  HASH(0x4c9a7c)
        empty hash
   11  HASH(0x4ca084)
        empty hash
   12  HASH(0x4c973c)
        empty hash
   13  HASH(0x4c9aac)
        empty hash
   14  HASH(0x4ca3c0)
        empty hash

Does the above indicate that that's a hash reference? It doesn't
look like it given the 0 1 

I should have

{ rat1, ( hash, hash, hash, hash ) }

where hash should look like

{ movieTitle, (showtime, showtime, showtime) }

I looked to me as though I was building this thing correctly above.



------------------------------

Date: Sun, 27 May 2001 11:26:58 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: CGI and printing vars
Message-Id: <3B111CC2.16EAA905@earthlink.net>

Godzilla! wrote:
> 
> Benjamin Goldberg wrote:
> 
> > Godzilla! wrote:
> > > Todd Smith wrote:
> 
> (snipped)
> 
> > Anyway, here's my 26 line program.
> 
> (snipped)
> 
> Not enough arguments for map at test1.pl line 6, near "->Vars;"

Strange, the syntax for map allows the form:

	map EXPR,LIST 

What I have is:

	my %in = map encode_entities $_, $cgi->Vars;

I don't see how or why this is not enough arguments.

> syntax error at test1.pl line 14, near "->start_html {"
> Execution of test1.pl aborted due to compilation errors.

Here's the line:
	print $cgi->start_html {}, BGCOLOR => "#ffffff";

Maybe it'll work if one adds parens?
	print $cgi->start_html({}, BGCOLOR => "#ffffff");

Anyway, it's just a syntax error.  The *design* works fine.

> There exists a distinct difference between code I post and
> code you post.

Mine's prettier?

> My posted code always works. Your posted code rarely works.

Mine is proofread by eye, not by repeatedly running it, finding typoes,
editing, running again, finding more typoes, doing more editing, etc. 
If you have a problem with that, too bad for you.  My code is "almost"
right the first time.  How many edit/run cycles does your code go
through before being posted?

-- 
#! perl -- This took a heck of a lot of work to make.  I hope it works.
@p{split//,'justaperlhacker'}=map hex,qw(6b 71 83 1c1 43 2 3 5 79d 71db
7835 1ddf07 23a871 72656b63); print map {$e=1;for(split//){$e*=$_};pack
'V',$e} qw(ptk ppppprre pperrrlau ppppphc ppjsa r);


------------------------------

Date: Sun, 27 May 2001 10:18:54 -0700
From: David Ball <db9@NOSPAM.com>
Subject: Clarification and question about FAQ
Message-Id: <7dc2htcaudg6qifadarro4lt0f7aevukg5@4ax.com>

There's been a flame war going on and I'd like to discuss it and get some
clarification about the faqs on this group.


First a bit of history. I started by asking a simple perl question. Someone
made a suggestion of doing it a different way and I thanked them and asked
them if they knew of any programs that did that withen my response. For
some reason I was attacked as posting off-topic. I saw no justification for
the attack, and I still don't understand why it would merit one.

The FAQ for this group, archived at faqs.org, contains the following

         *pasted text*

2.1) Is there a USENET group for Perl?

    Yes there is: comp.lang.perl.misc.  This group, which currently can get
    up to 150 messages per day, contains all kinds of discussions about
    Perl; everything from bug reports to new features to the history to
    humour and trivia.  This is the best source of information about
    anything Perl related, especially what's new with Perl5.  Because of
    its vast array of topics, it functions as both a comp.lang.* style
    newsgroup (providing technical information) and also as a rec.* style
    newsgroup, kind of a support group for Perl addicts (PerlAnon?). 

        *end pasted text*


Has a new faq been written for the group. The old one (from 1995) implies
that it's a friendly place for discussion, even comparing it to a rec.*
style newsgroup. I don't see why I should have been flamed for thanking
someone and asking them if they knew of a program that does things the way
they suggested.

Just what are the current limitations on posting here. They certainly don't
seem to match the archived FAQ. If a simple "thank you" and "do you know of
a program that does what you suggested" gets me flamed, then their must be
an extremely rigid FAQ for this group now. 

Could someone point me towards the updated FAQ. I usually try to follow the
guidelines for a group, but when I'm attacked for what I see as a
reasonable post, I tend to respond in kind.

David



------------------------------

Date: 27 May 2001 10:44:09 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Clarification and question about FAQ
Message-Id: <m1n17yvg9i.fsf@halfdome.holdit.com>

>>>>> "David" == David Ball <db9@NOSPAM.com> writes:

David> First a bit of history. I started by asking a simple perl
David> question. Someone made a suggestion of doing it a different way
David> and I thanked them and asked them if they knew of any programs
David> that did that withen my response. For some reason I was
David> attacked as posting off-topic. I saw no justification for the
David> attack, and I still don't understand why it would merit one.

Since I don't see anything relevant for "David Ball" at
groups.google.com (except you flaming Anno and Abigail), could you
please cite a message-ID?

I can only say that while perhaps you see it the way you say it,
you're leaving out important details that will trigger appropriate
responses from the long time helpers in this group.

-- 
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!


------------------------------

Date: Sun, 27 May 2001 10:58:56 -0700
From: David <db91@NOSPAM.com>
Subject: Re: Clarification and question about FAQ
Message-Id: <ttf2htgjkljj7e5vla7v3ceo04m53cm5ue@4ax.com>

On 27 May 2001 10:44:09 -0700, merlyn@stonehenge.com (Randal L. Schwartz)
wrotf:

>>>>>> "David" == David Ball <db9@NOSPAM.com> writes:
>
>David> First a bit of history. I started by asking a simple perl
>David> question. Someone made a suggestion of doing it a different way
>David> and I thanked them and asked them if they knew of any programs
>David> that did that withen my response. For some reason I was
>David> attacked as posting off-topic. I saw no justification for the
>David> attack, and I still don't understand why it would merit one.
>
>Since I don't see anything relevant for "David Ball" at
>groups.google.com (except you flaming Anno and Abigail), could you
>please cite a message-ID?
>
>I can only say that while perhaps you see it the way you say it,
>you're leaving out important details that will trigger appropriate
>responses from the long time helpers in this group.


original post
<3r0mgt812pitutfsdoim8jj2jget9c4tt4@4ax.com>

my thank you and question that was flamed
<h53mgtk7tpkcr8baq78mpl8r8qpuj3hcap@4ax.com>

Regards,

David



------------------------------

Date: Sun, 27 May 2001 17:30:59 GMT
From: "Daniel Berger" <djberg96@hotmail.com>
Subject: Re: dbi, fork and ipc-shareable - having problems
Message-Id: <nRaQ6.37416$V6.1895312@typhoon.mn.mediaone.net>

 > The problem is that your parent program is not waiting for the children
> to finish and hence it will get undefined references if at that time the
> child has not finished yet. You can add waitpid call in the parent to deal
> with this.
> Also, $dbh, $sth should be my variabled defined in child processes.
>
> If you do these, your code will work fine.
>
> HTH
>
> Richard

Well, the goal was to try to run each sql statement concurrently in its own
process.  Playing with this, I got it to work using your method.  Of course,
if I 'wait' for each child, then I am effectively running the queries one
after another rather than simultaneously.

I will have to use Uri's idea of having 4 different shared areas, each
dedicated to an array/fork.

Regards,

Dan




------------------------------

Date: Sun, 27 May 2001 11:15:29 -0700
From: "Eric Laramee" <sdozois@videotron.ca>
Subject: How to connect to MSAccess db w/o creating DSN
Message-Id: <zN8Q6.1435$yT6.98726@weber.videotron.net>

HI all,

In the following code, I'm connecting to a Access database after creating a
DSN (Control Panel - win32ODBC - etc...).
This works fine but is there a way to connect to a database without manually
creating a DSN.  It's easily done in ASP, I'm guessing it's a similar
process in Perl.


thanks for your help.

Eric.

#!/usr/bin/perl
#dbbooks.plx

use warnings;
use strict;
use DBI;

our ($DATASOURCE) = 'DBI:ODBC:booksODBC';

my ($connection, $statement, $bookId, $title);

$connection = DBI->connect($DATASOURCE, 'a', 'b') or die;
$statement  = $connection->prepare("SELECT * from Books");
$statement->execute();

while (($bookId, $title) = $statement->fetchrow_array) {
 print "$title has the following ID $bookId\n";
}

$statement->finish();
$connection->disconnect();




------------------------------

Date: Sun, 27 May 2001 15:33:06 GMT
From: "Ben Kennedy" <bkennedy99@Home.com>
Subject: Re: How to connect to MSAccess db w/o creating DSN
Message-Id: <S69Q6.9024$lP5.4031959@news1.rdc2.pa.home.com>


"Eric Laramee" <sdozois@videotron.ca> wrote in message
news:zN8Q6.1435$yT6.98726@weber.videotron.net...
> HI all,
>
> In the following code, I'm connecting to a Access database after creating
a
> DSN (Control Panel - win32ODBC - etc...).
> This works fine but is there a way to connect to a database without
manually
> creating a DSN.  It's easily done in ASP, I'm guessing it's a similar
> process in Perl.
>

Its pretty simple, a fully qualified DSN with Access is just the driver name
and location of the database:

my $dsn = "driver=Microsoft Access Driver (*.mdb);dbq=$database";
my $dbh = DBI->connect("dbi:ODBC:$dsn");

More complex ODBC drivers (such as MySQL, Oracle, etc) may require a few
more parameters in the $dsn string.  Hope this helps --

--Ben Kennedy





------------------------------

Date: Sun, 27 May 2001 11:41:58 -0700
From: "Eric Laramee" <sdozois@videotron.ca>
Subject: Re: How to connect to MSAccess db w/o creating DSN
Message-Id: <na9Q6.1540$yT6.111942@weber.videotron.net>

Thanks, I'll try it right away!

Eric.

"Ben Kennedy" <bkennedy99@Home.com> wrote in message
news:S69Q6.9024$lP5.4031959@news1.rdc2.pa.home.com...
>
> "Eric Laramee" <sdozois@videotron.ca> wrote in message
> news:zN8Q6.1435$yT6.98726@weber.videotron.net...
> > HI all,
> >
> > In the following code, I'm connecting to a Access database after
creating
> a
> > DSN (Control Panel - win32ODBC - etc...).
> > This works fine but is there a way to connect to a database without
> manually
> > creating a DSN.  It's easily done in ASP, I'm guessing it's a similar
> > process in Perl.
> >
>
> Its pretty simple, a fully qualified DSN with Access is just the driver
name
> and location of the database:
>
> my $dsn = "driver=Microsoft Access Driver (*.mdb);dbq=$database";
> my $dbh = DBI->connect("dbi:ODBC:$dsn");
>
> More complex ODBC drivers (such as MySQL, Oracle, etc) may require a few
> more parameters in the $dsn string.  Hope this helps --
>
> --Ben Kennedy
>
>
>




------------------------------

Date: Sun, 27 May 2001 09:51:55 -0400
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: Locking files in CGI fails (or not?)
Message-Id: <3B11067B.20300@dev.null>



Klax wrote:

> Hello,
> 
> I'm using a CGI written in Perl that receives the data from an HTML
> form and it usually FAILS the FIRST time it is executed. After an
> error, you can press BACK and submit the form again, and it always
> works.
> 
> This CGI opens a text file in the UNIX  system, writes some stuff and
> closes the file. I think the problem might be related with the
> "get_the_lock" and "drop_the_lock" functions.
> 
> What are these functions for? Are they neccesary? This is part the
> code:
> 
> $lockfile="/tmp/bnbform.lck";
> 
> &get_the_lock; 
> open(OUT_FILE,">>$fields{'outputfile'}"); 
> print OUT_FILE "Some stuff:\n";
> print OUT_FILE "---------------------------------------------------\n";
> close(OUT_FILE);
> &drop_the_lock;
> 
> sub get_the_lock
> {
>   local ($endtime);                                   
>   $endtime = 60;                                      
>   $endtime = time + $endtime;                         
>   while (-e $lockfile && time < $endtime) 
>    {
>     # Do Nothing                                    
>    }                                                   
>    open(LOCK_FILE, ">$lockfile");                     
> }
> 
> sub drop_the_lock
> {
>   close($lockfile);
>   unlink($lockfile);
> }
> 
> Thank you very much,
> 
>           Luis
Luis,

Before it's too late and you cause major harm to your server, throw away 
this program and write/obtain something more sound and secure.

First of all, your locking functions are apparently the more benign 
parts of the program. The idea here is that since several instances of 
this program can be running concurrently, you want each instance to 
leave a message saying "I am writing to the text file, keep off," in 
order to avoid two processes writing to the text file at the same time, 
thereby messing it up. Once a process is done, it's supposed to delete 
the message. So if a second process comes along and sees the message, it 
waits one minute or until the message is removed by the first process 
(whichever comes first) before it writes to the text file. This can 
probably be done more gracefully with flock, but it shouldn't cause your 
script to fail. The only potential problem I see here is that if you 
have a lot of copies of the process any given process may actually have 
to wait more than 60 seconds before it gets its turn, so if it ignores 
the lock after 60 seconds, it will mess up the text file anyway. (Is 
this a likely scenario? If your CGI is a guestbook script on the Saddam 
Hussein Fan Club web site, then you probably don't need file locking at 
all. On the other hand, if your company has just bought an ad for the 
halftime break in the Superbowl saying "Be the first to download all 
seven nude pictures of Anna Kournikova to win $1 million" and you are 
expecting this script to handle the incoming traffic, than you should 
look for another job NOW.)

What really scares me, though, is this line:

open(OUT_FILE,">>$fields{'outputfile'}");

In the bit of code that you are providing, the %fields hash is 
undefined, so I have no idea what's in there. Maybe it is undefined and 
then your problem is that you are trying to open a filehandle to a blank 
file. But the naming suggests to me that %fields might contain values 
from a web form. If it is the case than you are opening up a huge 
security gap here: I could, for instance send back /etc/passwd as the 
value of outputfile and create users on your server. Or make OUT_FILE 
into a pipe to sendmail and send my spam to a million people around the 
world from your machine, with you as the sender. You should never 
blindly open files based on user input alone.

One possible scenario that could produce your symptoms is this: Your 
script draws a web form that calls your script to process input. The 
first time you invoke the script, there is no input, so in particular 
outputfile is blank and your open line fails. When you hit the submit 
button on your form, you are transmitting a non-blank outputfile, so 
your text file gets opened and everyone lives happily ever after.

Of course, I can't tell for sure because you have not shown the entire 
code, you have not told us what you mean by the script failing, you have 
not shared any error messages with us and you have not even checked the 
results of the open line, so quite possible even you are unaware of any 
error message that Perl might be trying to convey to you.



------------------------------

Date: Sun, 27 May 2001 08:55:47 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Locking files in CGI fails (or not?)
Message-Id: <slrn9h1uai.8jk.tadmc@tadmc26.august.net>

Klax <galileoweb@hotmail.com> wrote:
>
>I'm using a CGI written in Perl that receives the data from an HTML
>form and it usually FAILS the FIRST time it is executed. After an
>error, you can press BACK and submit the form again, and it always
>works.
>
>This CGI opens a text file in the UNIX  system, writes some stuff and
>closes the file. I think the problem might be related with the
>"get_the_lock" and "drop_the_lock" functions.
>
>What are these functions for? 


For ensuring that two copies of your program running at the same
time (multitasking) will not corrupt the data file.


>Are they neccesary? 


Some form of file locking is necessary in a multitasking environment
such as CGI programs.

But since the routines below do NOT guarantee that the file won't
be corrupted, they are not necessary  :-)

The code below has several "red flags" that indicate poor quality.
I would not trust this code (I assume you got it from somewhere
else rather than writing it yourself?).


>This is part the
>code:
>
>$lockfile="/tmp/bnbform.lck";
>
>&get_the_lock; 
>open(OUT_FILE,">>$fields{'outputfile'}"); 


You should always, yes *always*, check the return value from open():

   open(OUT_FILE, ">>$fields{outputfile}") or
      die "could not open '$fields{outputfile}'  $!";


>sub get_the_lock
>{
>  local ($endtime);                                   
>  $endtime = 60;                                      
>  $endtime = time + $endtime;                         


Dynamic variables (local) should be avoided. You should use lexical (my)
variables whenever possible.

Doing it in 3 steps instead of one seems strange too:

   my $endtime = time + 60;


>  while (-e $lockfile && time < $endtime) 
>   {
>    # Do Nothing                                    
>   }                                                   
>   open(LOCK_FILE, ">$lockfile");                     


   open(LOCK_FILE, ">$lockfile") or die "could not open '$lockfile'  $!";


>}


That code does *not* ensure that the program with the lock has
finished before this copy of the program gets the lock.

The program with the lock gets 60 seconds, then it loses its lock
whether it is finished or not.

The subroutine does not accomplish its intended purpose!

You should fix it, else you risk a corrupted data file. There are
three Frequently Asked Questions regarding file locking. I'd start
fixing it by reading the answers to those questions:

   perldoc -q '\block'


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Sun, 27 May 2001 14:50:59 GMT
From: "Phillip Porch" <ppporch@home.com>
Subject: Re: Perl 5.6.1 on SCO5.0.4 - Problem with dynamic loading
Message-Id: <nv8Q6.76414$I5.17646399@news1.rdc1.tn.home.com>

I was able to get around this problem by:

After running Configure, edited the config.sh file to make fsync='undef'
instead of define. I then continued running Configure after getting out of
the shell escape. Did a make and then a make test. I too received the failed
lib/bigfltpm but no new ones. I am now able to install the old modules that
I wanted without the relocation error.



"Paul Mahoney" <ptm@xact.co.uk> wrote in message
news:9e5dmu$s3a$1@reader-00.news.insnet.cw.net...
> I've download and build perl 5.6.1 on my SCO 5.0.4 system and compiled it
> using gcc 2.95.2 (from sco skunkware). I checked the hints/sco.sh file for
> instructions and run the following:
>    sh Configure -de -Dcc=gcc
>    make
>    make test
>    make install
>
> This went well. Only one test failed (lib/bigfltpm) which didn't worry me.
> So I then tried to rebuild and install my favourite modules...
>
> Running  "make test" I keep getting:
>   Can't Load '/usr/local/lib/perl5/5.6.1/i386-sco/auto/IO/IO.so' for
module
> IO:
>     dynamic linker: /usr/local/bin/perl: relocation error: symbol not
found:
> fsync
>       at /usr/local/lib/perl5/5.6.1/i386-sco/XSLoader.pm line 75.
>         at /usr/local/lib/perl5/5.6.1/i386-sco/IO.pm line 9.
>
> I tried a rebuild of perl using the native "cc", but this made no
> difference.
>
> I really need a dynamic loading version. Can anybody help?
>
> Thanks
> Paul.
>
>




------------------------------

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.  

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 997
**************************************


home help back first fref pref prev next nref lref last post