[19259] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1454 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 6 18:10:47 2001

Date: Mon, 6 Aug 2001 15:10:18 -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: <997135818-v10-i1454@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 6 Aug 2001     Volume: 10 Number: 1454

Today's topics:
    Re: Perl Logical Knot Problem <stephen.p.harris@worldnet.att.net>
    Re: Perl Logical Knot Problem <stephen.p.harris@worldnet.att.net>
    Re: Perl Logical Knot Problem <stephen.p.harris@worldnet.att.net>
    Re: Perl Logical Knot Problem <godzilla@stomp.stomp.tokyo>
    Re: Perl Logical Knot Problem <stephen.p.harris@worldnet.att.net>
    Re: Perl Logical Knot Problem <mjcarman@home.com>
    Re: Perl Logical Knot Problem <mjcarman@home.com>
    Re: Perl multithreading on WIN32 - Help needed <bart.lateur@skynet.be>
        Perl MYSQL DBI help sought <killspam@redyonder.co.uk>
    Re: Perl MYSQL DBI help sought <vze2r2j8@verizon.net>
        q: launching a perl program not in a window <ow22@nospam-cornell.edu>
        q: launching a perl script from a perl script <ow22@nospam-cornell.edu>
    Re: q: launching a perl script from a perl script <ilya@martynov.org>
    Re: q: launching a perl script from a perl script <ow22@nospam-cornell.edu>
    Re: Regular Expression (John J. Trammell)
    Re: string extraction <ren@tivoli.com>
        Trouble Finding Parse::RecDescent for Perl 5.004 (Bob Dilworth)
    Re: Trouble Finding Parse::RecDescent for Perl 5.004 <brentdax1@earthlink.net>
    Re: validate IP address <bcaligari@fireforged.com>
    Re: validate IP address (Logan Shaw)
    Re: validate IP address <EvR@compuserve.com>
    Re: validate IP address (Randal L. Schwartz)
    Re: validate IP address <EvR@compuserve.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 06 Aug 2001 18:53:23 GMT
From: "Stephen Harris" <stephen.p.harris@worldnet.att.net>
Subject: Re: Perl Logical Knot Problem
Message-Id: <DIBb7.35827$gj1.3342027@bgtnsc05-news.ops.worldnet.att.net>


"> > @desired = ("zip","code","area","pre","local");  # 1 below code
> > foreach $i (@desired) {                                        # 2 below
> > code
> >     if  ($FORM{$i} ne  ""                                       # 3
below
> > code
> >  &&  $FORM{'zip'}  !~ /^[0-9]{5}$/g &&  $FORM{'code'} !~/^[0-9]{4}$/g
> >  &&  $FORM{'area'} !~ /^[0-9]{3}$/g &&  $FORM{'pre'}  !~ /^[0-9]{3}$/g
> >  &&  $FORM{'local'}  !~ /^[0-9]{4}$/g) {
>
> What do you think that /g gains you?  I think the best thing
> for you to do at this point is to keep hammering at the code,
> and put in lots of print statements to figure out exactly what
> it's doing.  You'll be a better coder after figuring this out
> for yourself.
>

When I did not have the /g,  and I had the zip field full(5 digits)
it would not return an error code if the other fields were partial.
Putting the /g in the zip field made the program find more errors.
Likewise I think the /g prevents first match success in same length fields.




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

Date: Mon, 06 Aug 2001 18:55:51 GMT
From: "Stephen Harris" <stephen.p.harris@worldnet.att.net>
Subject: Re: Perl Logical Knot Problem
Message-Id: <XKBb7.35828$gj1.3344356@bgtnsc05-news.ops.worldnet.att.net>


"Brent Dax" <brentdax1@earthlink.net> wrote in message
news:Apzb7.496$t41.63537@newsread2.prod.itd.earthlink.net...
>
> "Stephen Harris" <stephen.p.harris@worldnet.att.net> wrote in message
> news:mQyb7.4536$1p1.402752@bgtnsc04-news.ops.worldnet.att.net...
> ...
> > The problem came up with the optional fields. I tried to set it up
> > so that it would approve the form if they did not fill out the
> > phone and zip code. But if they did fill it out then it would warn
> > them of and incomplete field or not all digits used.
> >
> > Two fields one for  zip: XXXX   and one for code: XXXX
> > Three fields for area: ###  pre: ### and local: ####
> >
> > Next I'll show the code I used for this filtering. What this produced
> > is anomalous results. I'm wondering (I'm new) if the strange results
> > were caused because procedural nots are not quite the same as
> > mathematical nots(according to the online version of SICP/Scheme).
> >
> > @desired = ("zip","code","area","pre","local");  # 1 below code
> > foreach $i (@desired) {                                        # 2 below
> > code
> >     if  ($FORM{$i} ne  ""                                       # 3
below
> > code
> >  &&  $FORM{'zip'}  !~ /^[0-9]{5}$/g &&  $FORM{'code'} !~/^[0-9]{4}$/g
> >  &&  $FORM{'area'} !~ /^[0-9]{3}$/g &&  $FORM{'pre'}  !~ /^[0-9]{3}$/g
> >  &&  $FORM{'local'}  !~ /^[0-9]{4}$/g) {
> ...
>
> Problem is, you're checking *all* the fields each time the if statement
> executes.  What you need to do is something like this:
>
>     @desired = ("zip","code","area","pre","local");
>     %checkre{@desired} = (
>         '^[0-9]{5}$',
>         '^[0-9]{4}$',
>         '^[0-9]{3}$',
>         '^[0-9]{3}$',
>         '^[0-9]{4}$'
>     );                #build a hash of the regular expressions to validate
> against
>
>     for(@desired) {    #or use foreach
>         if($FORM{$_} ne '' && $FORM{$_} !~ /$checkre{$_}/) {
>
> Here, I'm building a hash of regular expressions keyed by field name and
> matching the field against the regexp.  (If you're going to use %checkre
> again and you're on Perl 5.6 or later, using qr// instead of '' would
speed
> things up considerably.)  The other way to do it is to do a switch
> statement.  Damian Conway's Switch.pm, available from the CPAN, will allow
> you to do that:
>
>     use Switch 'fallthrough';
>     @desired = qw(zip code area pre local);
>
>     FIELDS: for(@desired) {
>         next if $FORM{$_} eq '';
>         switch($_) {
>             case "zip"   { $form{zip}   !~ /^[0-9]{5}$/ or next FIELDS }
>             case "code"  { $form{code}  !~ /^[0-9]{4}$/ or next FIELDS }
>             case "area"  { $form{area}  !~ /^[0-9]{3}$/ or next FIELDS }
>             case "pre"   { $form{pre}   !~ /^[0-9]{3}$/ or next FIELDS }
>             case "local" { $form{local} !~ /^[0-9]{4}$/ or next FIELDS }
>             #error handler here
>         }
>     }
>
> Note that this code is all untested--it could be incorrect.  (That switch
> statement looks particularly suspicious, but I can't see anything wrong
with
> it.)
>
> HTH,
> --Brent Dax
> brentdax1@earthlink.net
>
>
Thanks for your reply. I'll try to figure it out.




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

Date: Mon, 06 Aug 2001 19:09:55 GMT
From: "Stephen Harris" <stephen.p.harris@worldnet.att.net>
Subject: Re: Perl Logical Knot Problem
Message-Id: <7YBb7.35838$gj1.3345221@bgtnsc05-news.ops.worldnet.att.net>


"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote in message
news:3B6ED045.9FE67132@stomp.stomp.tokyo...
> Stephen Harris wrote:
>
> (snipped)
>
> > The guestbook has three required fields
> > (name, email and comment) which seemed
> > to work OK.
>
> Those fields and related code either work ok or
> do not work ok. Your "seemed" is inappropriate.
>
>
> > The problem came up with the optional fields. I tried to set it up
> > so that it would approve the form if they did not fill out the
> > phone and zip code. But if they did fill it out then it would warn
> > them of and incomplete field or not all digits used.
>
>
> Your code is quite illogical and most inefficient.
>
> Add maximum length restrictions to your form action
> to prevent entries longer than desired.
>
> For my test code below my signature, you can check
> both zip and phone combined, or with easy modification,
> check zip and phone as independent units. As is, my
> code checks zip and phone as a single unit. My Error
> check sub-routine can be modified to do whatever you
> like, such as checking the actual data within each field
> and reporting a custom error message based on field
> content or lack thereof.
>
>
> Godzilla!
> --
>
> TEST SCRIPT:
> ____________
>
> #!perl
>
> $FORM{'zip'} = 12345;
> $FORM{'code'} = 6789;
> $FORM{'area'} = 123;
> $FORM{'pre'} = 456;
> $FORM{'local'} = 7891;
>
> @desired = ("zip", "code", "area", "pre", "local");
>
> for (@desired)
>  {
>   if (!($FORM{$_}))
>    { $FORM{$_} = 1; }
>   $count = $FORM{$_} =~ tr/0-9//;
>   $check = "$check$count";
>  }
>
> if ($check == 54334)
>  { print "Successful Check\n\n"; }
> else
>  { &Error; }
>
> sub Error
>  {
>   if (substr ($check, 0, 1) != 5)
>    { print "Five Digit Zip Code In Error\n"; }
>   if (substr ($check, 1, 1) != 4)
>    { print "Four Digit Zip Code In Error\n"; }
>   if (substr ($check, 2, 1) != 3)
>    { print "Three Digit Area Code In Error\n"; }
>   if (substr ($check, 3, 1) != 3)
>    { print "Three Digit Prefix Code In Error\n"; }
>   if (substr ($check, 4, 1) != 4)
>    { print "Four Digit Phone Number In Error\n"; }
>  }
>
> exit;

I am goint to paste this into Xemacs save it and then
telnet it to the Unix box and test it. I did not see how
the optionality of a blank field was accounted for
without an error message, but I hope so.

Also I found IndiPerl quite helpful before I tinkered
Apache to work. So here goes, I will report back.

Thanks,
Stephen




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

Date: Mon, 06 Aug 2001 12:23:14 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Perl Logical Knot Problem
Message-Id: <3B6EEEA2.B7CA8FEA@stomp.stomp.tokyo>

Stephen Harris wrote:
 
> Godzilla! wrote:
> > Stephen Harris wrote:

 (snipped)

> I did not see how the optionality of a blank field
> was accounted for without an error message, but I hope so.

 "For my test code below my signature, you can check
  both zip and phone combined, or with easy modification,
  check zip and phone as independent units. As is, my
  code checks zip and phone as a single unit.

  My Error check sub-routine can be modified to do whatever you
  like, such as checking the actual data within each field
  and reporting a custom error message based on field
  content or lack thereof."

Simple matter of checking for any entry data in any of
your optional fields. Any entry data, correct or not,
indicates intent to fill in optional fields.

for (@desired)
 {
  if ($FORM{$_})
   { &Run_Check_Routine; last; }
 }


for (@zip_code_desired)
 {
  if ($FORM{$_})
   { &Run_Check_Zip_Code_Routine; last; }
 }

for (@phone_desired)
 {
  if ($FORM{$_})
   { &Run_Check_Phone_Routine; last; }
 }


Easy, yes?

Godzilla!
-- 
$_='84453414415540
8555448741435857585155744445743488341
84487415448448741448808484808143515574
585758515574548
4444188841880841434555
84448878841414344141434435551435155748
84447855854575555155448341';
tr/873514/975318642abcdef/;
s/([0-9A-Fa-f]{2})/sprintf("%c",hex($1))/ge;
$_=reverse($_);tr// H-OV-ZP-UA-G/;
eval $_;


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

Date: Mon, 06 Aug 2001 19:44:43 GMT
From: "Stephen Harris" <stephen.p.harris@worldnet.att.net>
Subject: Re: Perl Logical Knot Problem
Message-Id: <LsCb7.35859$gj1.3346801@bgtnsc05-news.ops.worldnet.att.net>


"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote in message
news:3B6EEEA2.B7CA8FEA@stomp.stomp.tokyo...
> Stephen Harris wrote:
>
> > Godzilla! wrote:
> > > Stephen Harris wrote:
>
>  (snipped)
>
> > I did not see how the optionality of a blank field
> > was accounted for without an error message, but I hope so.
>
>  "For my test code below my signature, you can check
>   both zip and phone combined, or with easy modification,
>   check zip and phone as independent units. As is, my
>   code checks zip and phone as a single unit.
>
>   My Error check sub-routine can be modified to do whatever you
>   like, such as checking the actual data within each field
>   and reporting a custom error message based on field
>   content or lack thereof."
>
> Simple matter of checking for any entry data in any of
> your optional fields. Any entry data, correct or not,
> indicates intent to fill in optional fields.
>
> for (@desired)
>  {
>   if ($FORM{$_})
>    { &Run_Check_Routine; last; }
>  }
>
>
> for (@zip_code_desired)
>  {
>   if ($FORM{$_})
>    { &Run_Check_Zip_Code_Routine; last; }
>  }
>
> for (@phone_desired)
>  {
>   if ($FORM{$_})
>    { &Run_Check_Phone_Routine; last; }
>  }
>
>
> Easy, yes?
>
> Godzilla!

I cut out my code and pasted yours in. It printed out
"Successful Check" in every instance whether or not
the field was partially completed. I included your code
where I put it in place of mine in the whole program.

the exit; stopped my success message, so I commented
it out and then I got both your success message and mine.
Even though the optional fields were incomplete.
So I will take some time to look over your new post.

Regards,
Stephen



#!/usr/bin/perl
print "Content-type:text/html\n\n";

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;  # added to strip line breaks
  $value =~ s/\r//g;
 $value =~ s/\cM//g;
 $FORM{$name} = $value;
}

# Make sure all the blanks required fields are filled in.
print "<html><head><title>Results</title></head>\n<body>\n";
@required = ("firstname","lastname","email","comment");

foreach $i (@required) {
  if ($FORM{$i} eq "" ) {

&dienice("You must fill out the seperate fields for your name, comment and
correct email address.");
}
     }

      if($FORM{'email'} !~ /[\w\-]+\@[\w\-]+\.[\w\-]+/){

&dienice("You must fill out the seperate fields for your name, comment and
correct email format.");

}
$FORM{'zip'} = 12345;
$FORM{'code'} = 6789;
$FORM{'area'} = 123;
$FORM{'pre'} = 456;
$FORM{'local'} = 7891;

@desired = ("zip", "code", "area", "pre", "local");

for (@desired)
 {
  if (!($FORM{$_}))
   { $FORM{$_} = 1; }
  $count = $FORM{$_} =~ tr/0-9//;
  $check = "$check$count";
 }

if ($check == 54334)
 { print "Successful Check\n\n"; }
else
 { &Error; }

sub Error
 {
  if (substr ($check, 0, 1) != 5)
   { print "Five Digit Zip Code In Error\n"; }
  if (substr ($check, 1, 1) != 4)
   { print "Four Digit Zip Code In Error\n"; }
  if (substr ($check, 2, 1) != 3)
   { print "Three Digit Area Code In Error\n"; }
  if (substr ($check, 3, 1) != 3)
   { print "Three Digit Prefix Code In Error\n"; }
  if (substr ($check, 4, 1) != 4)
   { print "Four Digit Phone Number In Error\n"; }
 }

exit;




# now we proceed.
print <<EndHead;
<h2>Mission Accomplished</h2>
<b>Chance favors the prepared mind!</b><p>
<img src="thanks.gif"><p>
<a href="http://pengo.cabrillo.cc.ca.us/~stu35/index.html">Home</a><p>
EndHead

print "</body></html>\n";

open(OUTF,">>survey.out") or dienice("Couldn't open survey.out for writing:
$!");
print OUTF "$FORM{'firstname'}|$FORM{'lastname'}|";
print OUTF "$FORM{'email'}|$FORM{'comment'}|";
print OUTF "$FORM{'address'}|$FORM{'city'}|";
print OUTF "$FORM{'state'}|$FORM{'zip'}|";
print OUTF "$FORM{'code'}|$FORM{'area'}|";
print OUTF "$FORM{'pre'}|$FORM{'local'}|";
print OUTF "$FORM{'control'}\n";

close(OUTF);
# omitted </form> in the html tags below
sub dienice {
 my($msg) = @_;
 print "<h2>Error_Press_Back_Button<--Sends_You_To_Signup</h2>\n";
 print $msg;
 print "</body></html>";
 exit;
}
























































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

Date: Mon, 06 Aug 2001 15:05:03 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Perl Logical Knot Problem
Message-Id: <3B6EF86F.638CCC30@home.com>

Stephen Harris wrote:
> 
[Attributions lost. C'mon folks, learn how to quote!]

> > >  &&  $FORM{'zip'}  !~ /^[0-9]{5}$/g &&  
> > > [...]
> >
> > What do you think that /g gains you? 
>
> I think the /g prevents first match success in same length fields.

Maybe you should read the documentation so that you *know* what /g does
instead of guessing?

From perlop:
    The /g modifier specifies global pattern matching--that is, 
    matching as many times as possible within the string. How it 
    behaves depends on the context. In list context, it returns a list 
    of the substrings matched by any capturing parentheses in the 
    regular expression. If there are no parentheses, it returns a list 
    of all the matched strings, as if there were parentheses around the 
    whole pattern.

    In scalar context, each execution of m//g finds the next match, 
    returning true if it matches, and false if there is no further 
    match. The position after the last match can be read or set using 
    the pos() function; see pos in the perlfunc manpage. A failed match 
    normally resets the search position to the beginning of the string, 
    but you can avoid that by adding the /c modifier (e.g. m//gc). 
    Modifying the target string also resets the search position.

-mjc


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

Date: Mon, 06 Aug 2001 16:12:26 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Perl Logical Knot Problem
Message-Id: <3B6F083A.C85959BC@home.com>

Stephen Harris wrote:
> 
> #!/usr/bin/perl

Always enable warnings and use strict; (You may want to remove -w for
released CGI scripts, but use them during development.)

> print "Content-type:text/html\n\n";
> 
> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
> [...]

Please do NOT roll your own CGI implementation. Use CGI.pm.

[And kindly ignore Godzilla when she starts ranting about "cargo-cult"
programming and other silly reasons that you shouldn't use CGI.pm.]

> open(OUTF,">>survey.out") or dienice("Couldn't open survey.out for
>   writing: $!");

You're checking the status of your open. That's worth a point. However,
you lose a point for relying on the current working directory under CGI
(you can't) and another point for not locking your file. (If two people
call your script at the same time, you will most likely have your file
trashed.)

-mjc


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

Date: Mon, 06 Aug 2001 18:19:06 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Perl multithreading on WIN32 - Help needed
Message-Id: <suntmtkjv8md16riuokh7etcchbjsn7jkj@4ax.com>

bhakami@4tv.net wrote:

>I am running perl (5.6.0) on Windows NT (WIN32). Can anyone tell me if any kind
>of multithreading implementation is available, and where I can find it.

Yes. You've got it, I think. Try fork().

-- 
	Bart.


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

Date: Mon, 06 Aug 2001 19:24:21 GMT
From: "Alan Farrington" <killspam@redyonder.co.uk>
Subject: Perl MYSQL DBI help sought
Message-Id: <F9Cb7.81396$_b4.6529742@news1.cableinet.net>

Evening all

I wonder if anyone can help me in identifying why the code listed below is
not returning the result I expect.Whilst I do have some Java knowledge, I am
new to the Perl game so please bear with me if it all seems a bit obvious
and infantile.

Basically I have an MySQL database and I wish to import into it information
about users of a NT system using the Win32API : : NET module. I have
successfully imported the necessary information by using a SQL insert
command, but what I want to do is to search for the user name in the
database first and if it is already there use a separate block of code with
an SQL update command.

The MySQL database has a table nt_detail which has three columns - name,
full_name and comment

The problem seems to arise in the sub sql_update routine. The first problem
is that it when I invoke  the SQL query

$query = "SELECT user_name FROM nt_detail WHERE user_name = $name";

to check for an existing record whilst the variable $name appears to pick up
a correct value it throws the following error, not withstanding that the
Administrator is already entered into the name column.

DBD::mysql::st execute failed: Unknown column 'Administrator' in 'where
clause'
at importB_nt line 61.

The consequence of this is that $name_sql which is assigned to the value of
fetchrow_array( ) is always undefined.

Additionally talking of the said fetchrow_array( ) function is throwing the
following error which I don't understand.

DBD::mysql::st fetchrow_array failed: fetch( ) without execute() at
importB_nt li
ne 62.

If anyone could throw any light on the above or point me in the right
direction, I would be much obliged.

Cheers

Alan
--
To reply change red to blue.
alan_farrington@redyonder.co.uk

XXXXXXXXXXXXXXXXXXXXXXX Full Code Listing XXXXXXXXXXXXXXXXXXXXXXXXXX

#! /usr/bin/perl -w

use strict;
use Win32API::Net;
use Win32::NetAdmin;
use DBI;

my ($dsn)="DBI:mysql:m0ajf:localhost";
my ($user_name)="root";
my ($password)="";
my ($dbh,$sth);
my $server;

my %users_info;
my @users;
my $users_ref = \@users;
my $users_info= \%users_info;
my ($name,$full_name,$comment,$name_sql);
my $query;

# connect to database

$dbh=DBI ->connect($dsn,$user_name,$password, {RaiseError=> 0, PrintError
=>1});

obtain_data();


$sth ->finish();
$dbh ->disconnect();


sub obtain_data

 {

 Win32::NetAdmin::GetDomainController ("","",$server);
 Win32::NetAdmin::GetUsers($server,2,$users_ref);

 foreach $users_ref(@users)
  {
  Win32API::Net::UserGetInfo($server,$users_ref,2,$users_info);

  $name = $users_info {'name'};
  $full_name = $users_info {'fullName'};
  $comment = $users_info{'usrComment'};

print "\n\t**********name is $name*************\n";

# call to sub
  sql_update();
  }
 }


sub sql_update

 {
  $query = "SELECT user_name FROM nt_detail WHERE user_name = $name";
  $sth = $dbh ->prepare($query);
  $sth ->execute();                        ******line61*****
  ($name_sql)=$sth->fetchrow_array();    *******line62********

  if (defined($name_sql))
  {
print "\nUpdate loop entered for existing records\n";

  $sth=$dbh-> prepare("UPDATE nt_detail
SET(user_name,full_name,comment)WHERE user_name = $name"
  . "values ('$name','$full_name','$comment')");
  $sth -> execute();
  }

  else

   {
print "\nInsert loop entered for new records\n";

   $sth=$dbh-> prepare("INSERT nt_detail(user_name,full_name,comment)"
   . "values ('$name','$full_name','$comment')");
   $sth -> execute();
   }


 }







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

Date: Mon, 06 Aug 2001 20:59:27 GMT
From: "Kurt Stephens" <vze2r2j8@verizon.net>
Subject: Re: Perl MYSQL DBI help sought
Message-Id: <PyDb7.259$p57.49231@typhoon2.gnilink.net>

"Alan Farrington" <killspam@redyonder.co.uk> wrote in message
news:F9Cb7.81396$_b4.6529742@news1.cableinet.net...
> Evening all
>
> I wonder if anyone can help me in identifying why the code listed below is
> not returning the result I expect.Whilst I do have some Java knowledge, I
am
> new to the Perl game so please bear with me if it all seems a bit obvious
> and infantile.
>
> Basically I have an MySQL database and I wish to import into it
information
> about users of a NT system using the Win32API : : NET module. I have
> successfully imported the necessary information by using a SQL insert
> command, but what I want to do is to search for the user name in the
> database first and if it is already there use a separate block of code
with
> an SQL update command.
>
> The MySQL database has a table nt_detail which has three columns - name,
> full_name and comment
>
> The problem seems to arise in the sub sql_update routine. The first
problem
> is that it when I invoke  the SQL query
>
> $query = "SELECT user_name FROM nt_detail WHERE user_name = $name";
>
> to check for an existing record whilst the variable $name appears to pick
up
> a correct value it throws the following error, not withstanding that the
> Administrator is already entered into the name column.
>
> DBD::mysql::st execute failed: Unknown column 'Administrator' in 'where
> clause'
> at importB_nt line 61.

This is a due to a quoting problem in you SQL syntax.  The statement above
will create the $query string 'SELECT user_name FROM nt_detail WHERE
user_name = Administrator'.  MySQL interprets 'Administrator' as a column
name, and fails because the column is not found in table nt_detail.  You
need to place quotes around $name, or better yet eliminate the quoting
issues using palceholders and binding $name in the execute statement.

Here are several options ranging from bad to best:

# 1 - (BAD) This will fail if $name contains single quotes
$query = "SELECT user_name FROM nt_detail WHERE user_name = '$name'";

# 2 - (Better) $dbh->quote() method eliminates unsafe quoting issues
$query = "SELECT user_name FROM nt_detail WHERE user_name = " .
$dbh->quote($name);

# 3 - (Best) Using placeholders
$query = "SELECT user_name FROM nt_detail WHERE user_name = ?";
my $sth = $dbh->prepare($query);
$sth->execute($name);

Refer to the DBI documentation for more information about binding.  You may
also want to consider writing a setup routine that prepares the select,
update and insert queries as seperate statement handles that you can reuse
in your loop, rather than repeating the prepare/execute process for each
record.

my ($dbh, $select_sth, $update_sth, $insert_sth);

# connect to database

$select_sth = $dbh->prepare(<<__SQL__);
SELECT user_name
FROM nt_detail
WHERE user_name = ?
__SQL__

$update_sth = $dbh->prepare(<<__SQL__);
UPDATE nt_detail
SET
    user_name = ?,
    full_name = ?,
    comment = ?
WHERE user_name = ?
__SQL__

$insert_sth = $dbh->prepare(<<__SQL__);
INSERT INTO nt_detail (user_name, full_name, comment)
VALUES (?, ?, ?)
__SQL__


HTH,

Kurt Stephens





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

Date: Mon, 6 Aug 2001 13:31:43 -0700
From: "Oliver" <ow22@nospam-cornell.edu>
Subject: q: launching a perl program not in a window
Message-Id: <9kmurv$eil$1@news01.cit.cornell.edu>

Hi, i was wondering if anyone knew the html code for launching a perl
program into a hidden frame or somthing, basically i have a perl program
that updates an html file, i want to call this perl program but not have it
actually launch the program into a window. so i cant just use the standarf
href. okay thanks a lot

oliver




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

Date: Mon, 6 Aug 2001 13:39:21 -0700
From: "Oliver" <ow22@nospam-cornell.edu>
Subject: q: launching a perl script from a perl script
Message-Id: <9kmva9$f60$1@news01.cit.cornell.edu>

is it just

system ("script.cgi");?

that doesnt seem to be working for me. thanks

oliver




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

Date: 07 Aug 2001 00:41:55 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: q: launching a perl script from a perl script
Message-Id: <87g0b47wfg.fsf@abra.ru>


O> is it just
O> system ("script.cgi");?

O> that doesnt seem to be working for me. thanks

It can be wrong path, wrong permissions and so on. Check return code
to find exact reason. See 'perldoc -tf system' for example.

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: Mon, 6 Aug 2001 13:42:12 -0700
From: "Oliver" <ow22@nospam-cornell.edu>
Subject: Re: q: launching a perl script from a perl script
Message-Id: <9kmvfk$f6q$1@news01.cit.cornell.edu>

yea let me add to that, it works when i run the first perl script from the
command line, but the second time around, the system call is not executed.
thanks

oliver

"Ilya Martynov" <ilya@martynov.org> wrote in message
news:87g0b47wfg.fsf@abra.ru...
>
> O> is it just
> O> system ("fullpath/script.cgi");?
>
> O> that doesnt seem to be working for me. thanks
>
> It can be wrong path, wrong permissions and so on. Check return code
> to find exact reason. See 'perldoc -tf system' for example.
>
> --
>  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> | Ilya Martynov (http://martynov.org/)
|
> | GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6
|
> | AGAVA Software Company (http://www.agava.com/)
|
>  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-




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

Date: 06 Aug 2001 18:23:07 GMT
From: trammell@bayazid.hypersloth.invalid (John J. Trammell)
Subject: Re: Regular Expression
Message-Id: <slrn9mt6bs.6k5.trammell@haqq.hypersloth.net>

On 06 Aug 2001 11:00:10 -0500, Ren Maddox <ren@tivoli.com> wrote:
[snip]
> A quick benchmark on my system found that /^\d*$/ is actually faster
> than /\D/.  I expect this is due to some of the regex optimizations
> for anchored patterns.

I have used it (and /\S/ as well), but only because it makes more
sense to me; the regex is just easier on my internal parser.

> Here is a summary, followed by the script and actual result:
> 
>            Good         Bad @ beginning   Bad @ middle   Bad @ end
> 
> /\D/       85462.91/s   389282.72/s       127475.78/s    77312.43/s
> /^\d*$/    92451.37/s   409717.23/s       158048.81/s    96383.85/s

Well I'll be demmed.  Now I need to decide if it's worth it.



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

Date: 06 Aug 2001 12:32:49 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: string extraction
Message-Id: <m3ofptf60u.fsf@dhcp9-161.support.tivoli.com>

On Sat, 04 Aug 2001, krahnj@acm.org wrote:

> I don't think so.
> 
> perl -le'$string = "one xxx two xxx three xxx four xxx\n";
> $number_xxx_found = $string =~ m!xxx!g; print $number_xxx_found'
> 1

The idiom of interposing a set of empty parens in the assignment
solves this problem:

perl -le'$string = "one xxx two xxx three xxx four xxx\n";
$number_xxx_found = () = $string =~ m!xxx!g; print $number_xxx_found'
4

-- 
Ren Maddox
ren@tivoli.com


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

Date: Mon, 06 Aug 2001 18:17:25 GMT
From: bdilworth@mco.edu (Bob Dilworth)
Subject: Trouble Finding Parse::RecDescent for Perl 5.004
Message-Id: <3b6ede41.20836529@news4u.mco.edu>

All:

Please pardon me if this is an inappropriate question for this group.

I'm having difficulty finding a version of Parse::RecDescent that runs
under Perl 5.004.  The versions available through CPAN all require at
least 5.005.  I've searched dejanews for any references to a version
that runs under 5.004 but didn't find any (references).

If anyone could point me toward a relevant URL I'd be most
appreciative.

Again, sorry for the question.

Bob Dilworth
Toledo, Ohio


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

Date: Mon, 06 Aug 2001 19:14:07 GMT
From: "Brent Dax" <brentdax1@earthlink.net>
Subject: Re: Trouble Finding Parse::RecDescent for Perl 5.004
Message-Id: <30Cb7.5681$t41.93366@newsread2.prod.itd.earthlink.net>

"Bob Dilworth" <bdilworth@mco.edu> wrote in message
news:3b6ede41.20836529@news4u.mco.edu...
> All:
>
> Please pardon me if this is an inappropriate question for this group.
>
> I'm having difficulty finding a version of Parse::RecDescent that runs
> under Perl 5.004.  The versions available through CPAN all require at
> least 5.005.  I've searched dejanews for any references to a version
> that runs under 5.004 but didn't find any (references).
>
> If anyone could point me toward a relevant URL I'd be most
> appreciative.
>
> Again, sorry for the question.

I don't think Parse::RecDescent will run on 5.004.  Consider this a sign
that 5.004 is out-of-date and you should upgrade to 5.005 or better--modules
usually don't require a version just for the hell of it.

5.005 is just as stable as 5.004 (if not more so) and has many useful new
features, such as threads and precompiled regular expressions.

--Brent Dax
brentdax1@earthlink.net




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

Date: Mon, 6 Aug 2001 19:13:53 +0200
From: "B. Caligari" <bcaligari@fireforged.com>
Subject: Re: validate IP address
Message-Id: <9kmj0201sbd@enews1.newsguy.com>


"Brent Dax" <brentdax1@earthlink.net> wrote in message
news:5xzb7.339$nb4.62234@newsread1.prod.itd.earthlink.net...
> "Jag Man" <a0197620@MailAndNews.com> wrote in message
> news:3B91180F@MailAndNews.com...
> > I have an IP variable with default value 000.000.000.000 I needs to
verify
> > that the input value for this variable is a valid IP address.
> >
> > Need a shortest possible subroutine.
>
> If you mean valid as in "correct number of numbers", a short regular
> expression will do the trick:
>
>     $ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
>     #make sure you have four digit sequences 1-3 numbers each, separated
by
> periods,
>     #and that the IP takes up the entire variable
>
> If you mean make sure the IP address exists, I don't know how to do that.

modified your regex slightly to allow only those numbers in the range 0-255


((map {$_<256 || ()} $ip =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/)
== 4)
  || die "$ip is not a valid IP Address\n";

B.





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

Date: 6 Aug 2001 13:40:25 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: validate IP address
Message-Id: <9kmoap$dd9$1@charity.cs.utexas.edu>

In article <3B91180F@MailAndNews.com>,
Jag Man  <a0197620@MailAndNews.com> wrote:
>I have an IP variable with default value 000.000.000.000 I needs to verify 
>that the input value for this variable is a valid IP address.

Here's one that works according to the standards I use for "valid IP
address".  This doesn't allow leading zeros, although it does allow
"10.0.0.1".

	sub valid_ip
	{
	    my ($ip) = @_;
	    my @octets = split (/\./, $ip);
	    return 0 if @octets != 4;
	    return 4 == grep (
		/^([1-9]\d*|0)$/ and $_ >= 0 and $_ <= 255,
		@octets
		);
	}

>Need a shortest possible subroutine.

I don't see why you'd *need* that, although it might be interesting.

  - Logan
-- 
"Our grandkids love that we get Roadrunner and digital cable."
(Advertisement for Time Warner cable TV and internet access, July 2001)


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

Date: Mon, 6 Aug 2001 15:03:36 -0600
From: "Richard A. Evans" <EvR@compuserve.com>
Subject: Re: validate IP address
Message-Id: <9kn0n6$iu5$1@suaar1ac.prod.compuserve.com>

> I have an IP variable with default value 000.000.000.000 I needs to verify
> that the input value for this variable is a valid IP address.
>
> Need a shortest possible subroutine.

$ip_addr =~
/^(([01]?\d\d?|2[0-4]\d|25[0-5])\.){3}([01]?\d\d?|2[0-4]\d|25[0-5])$/;




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

Date: 06 Aug 2001 14:45:32 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: validate IP address
Message-Id: <m1ofpsuakj.fsf@halfdome.holdit.com>

>>>>> "Richard" == Richard A Evans <EvR@compuserve.com> writes:

>> I have an IP variable with default value 000.000.000.000 I needs to verify
>> that the input value for this variable is a valid IP address.
>> 
>> Need a shortest possible subroutine.

Richard> $ip_addr =~
Richard> /^(([01]?\d\d?|2[0-4]\d|25[0-5])\.){3}([01]?\d\d?|2[0-4]\d|25[0-5])$/;

    $ perl
    $ip_addr = "127.1";
    die "broken!" unless
      $ip_addr =~
      /^(([01]?\d\d?|2[0-4]\d|25[0-5])\.){3}([01]?\d\d?|2[0-4]\d|25[0-5])$/;
    ^D
    broken! at - line 2.
    $

Try again.

-- 
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: Mon, 6 Aug 2001 15:53:47 -0600
From: "Richard A. Evans" <EvR@compuserve.com>
Subject: Re: validate IP address
Message-Id: <9kn3j5$rrc$1@suaar1ab.prod.compuserve.com>

>     $ perl
>     $ip_addr = "127.1";
>     die "broken!" unless
>       $ip_addr =~
>
/^(([01]?\d\d?|2[0-4]\d|25[0-5])\.){3}([01]?\d\d?|2[0-4]\d|25[0-5])$/;
>     ^D
>     broken! at - line 2.
>     $
>
> Try again.

Seems to me that the regex works as expected.  It *should* error if $ip_addr
is not in the form xxx.xxx.xxx.xxx where the xxx must be <255.  Am I missing
something?

Regards,

Rick Evans




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

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


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