[21924] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4128 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Nov 16 09:06:26 2002

Date: Sat, 16 Nov 2002 06:05:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 16 Nov 2002     Volume: 10 Number: 4128

Today's topics:
        'if' and the short-circuit 'and' <webmastr@localhost.localdomain>
    Re: 'if' and the short-circuit 'and' <tassilo.parseval@post.rwth-aachen.de>
    Re: 'if' and the short-circuit 'and' <nobull@mail.com>
    Re: 'if' and the short-circuit 'and' (Jay Tilton)
    Re: [Q] Script to search auction sites? (Sir Loin of Beef)
    Re: Calling CGI script in restrcted dir (.htaccess) fro <linuxnb@yahoo.com>
    Re: CPAN local installation (Jay Tilton)
        CSV SQL <lois@hotmail.com>
    Re: CSV SQL <goldbb2@earthlink.net>
    Re: dealing with multiple entires in a multi-dimensiona <nobull@mail.com>
        Download TK module ? <mail@eircom.net>
        Error reading the column names using DBI (Thomas Theakanath)
    Re: How to kill a system or process open  call on timeo <goldbb2@earthlink.net>
        MIME plain text body extraction (matt)
        parameter  <rwh2100@hotmail.com>
        parameter  <rwh2100@hotmail.com>
    Re: parameter <nobody@noplace.com>
    Re: parameter <rwh2100@hotmail.com>
    Re: parameter <tassilo.parseval@post.rwth-aachen.de>
    Re: parameter <rwh2100@hotmail.com>
    Re: Perl searching a huge mySQL database... (krakle)
    Re: Perl searching a huge mySQL database... (krakle)
    Re: Perl searching a huge mySQL database... (krakle)
    Re: Perl searching a huge mySQL database... (krakle)
    Re: Socket client/server example not working on Windows <goldbb2@earthlink.net>
        Sum-Product Number Logic Question <purplefeetguy@sbcglobal.net>
    Re: Sum-Product Number Logic Question <krahnj@acm.org>
    Re: Sum-Product Number Logic Question (Jay Tilton)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 16 Nov 2002 09:34:51 GMT
From: Webmaster <webmastr@localhost.localdomain>
Subject: 'if' and the short-circuit 'and'
Message-Id: <pan.2002.11.16.01.35.17.340178.2730@localhost.localdomain>

Hello,

I can't seem to find a satisfactory answer to this question.

Can anybody tell me the difference between #1 and #2?


	LABEL1: {
		# Statement 1
		last LABEL1 if (defined $ENV{EX_DBFILE} and $Global::DB_File = 1);

		# Statement 2
		last LABEL1 if !$ENV{EX_ALLDBM} and $Global::GDBM;
	}


I really am interested in what the parens do in statement #1 and what
their absence in statement #2 means.

Thanks
NK


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

Date: 16 Nov 2002 11:08:34 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: 'if' and the short-circuit 'and'
Message-Id: <ar58vi$alb$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Webmaster:

> I can't seem to find a satisfactory answer to this question.
> 
> Can anybody tell me the difference between #1 and #2?
> 
> 
> 	LABEL1: {
> 		# Statement 1
> 		last LABEL1 if (defined $ENV{EX_DBFILE} and $Global::DB_File = 1);
> 
> 		# Statement 2
> 		last LABEL1 if !$ENV{EX_ALLDBM} and $Global::GDBM;
> 	}
> 
> 
> I really am interested in what the parens do in statement #1 and what
> their absence in statement #2 means.

They do nothing. In Perl you generally have two ways to create
conditional statements:

    if (CONDITION) { BLOCK }

or

    EXPRESSION if [(] CONDITION [)]

While the parens are obligatory in the first case they are optional in
the second.  That means that the parens in your first statement above
could also be dropped. 

Btw:

    if ... and $Global::DB_File = 1;

is almost always wrong since the second expressions assigns a true value
to the variable which then always evaluates to a true value. It should
be:

    if ... and $Global::DB_File == 1;

unless of course you really want to set the value based on the condition
preceeding the 'and' which is a little obscure. This would better be
written as:

    $Global::DB_File = 1 and last LABEL1 if defined $ENV{EX_DBFILE};

Tassilo
-- 
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;


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

Date: 16 Nov 2002 11:11:21 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: 'if' and the short-circuit 'and'
Message-Id: <u9heehkbvq.fsf@wcl-l.bham.ac.uk>

Webmaster <webmastr@localhost.localdomain> writes:

> I can't seem to find a satisfactory answer to this question.

Maybe that is bacuse the correct answer is not one that would satisfy you.

> 		last LABEL1 if (defined $ENV{EX_DBFILE} and $Global::DB_File = 1);
> 		last LABEL1 if !$ENV{EX_ALLDBM} and $Global::GDBM;

> I really am interested in what the parens do in statement #1

Nothing.

> and what their absence in statement #2 means.

It means the progranner was in the mood to use redundant parens in
statement #1 but not statement #2.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Sat, 16 Nov 2002 12:22:25 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: 'if' and the short-circuit 'and'
Message-Id: <3dd63613.62538214@news.erols.com>

Webmaster <webmastr@localhost.localdomain> wrote:

: I can't seem to find a satisfactory answer to this question.

Where have you looked?  What were the unsatisfactory answers?  What
was unsatisfactory about them?  Unless you share that information,
you're likely to receive more of the same.

: Can anybody tell me the difference between #1 and #2?

Apples and oranges, baby.  They're doing completely different things.

: 	LABEL1: {
: 		# Statement 1
: 		last LABEL1 if (defined $ENV{EX_DBFILE} and $Global::DB_File = 1);

"defined $ENV{EX_DBFILE}" tests whether $ENV{EX_DBFILE} is defined.
"$Global::DB_File = 1" assigns the value 1 to $Global::DB_File, and
always tests true.

: 		# Statement 2
: 		last LABEL1 if !$ENV{EX_ALLDBM} and $Global::GDBM;

"!$ENV{EX_ALLDBM}" tests whether $ENV{EX_DBFILE} holds a non-true
value.
"$Global::GDBM" tests whether $Global::GDBM holds a true value.

: 	}
:
: I really am interested in what the parens do in statement #1 and what
: their absence in statement #2 means.

Perl ignores those parens, but they add a little clarity for the
reader.



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

Date: Sat, 16 Nov 2002 11:51:04 GMT
From: NOSPAMmdknight@pacific.net.sg (Sir Loin of Beef)
Subject: Re: [Q] Script to search auction sites?
Message-Id: <3dd630fe.938857@news.pacific.net.sg>

"Jürgen Exner" <jurgenex@hotmail.com> wrote:

>Sir Loin of Beef wrote:
>> I've just enabled warnings and strict, and get this error now.
>>
>> D:\html10 - auction searcher>perl auctse~1.pl

here's the complete code:

#!/usr/bin/perl

use CGI qw/:standard/;
use warnings;
use strict;
 

  print header,
        start_html('Auction Search'),
        h1('Auction Search v0.4'),
        start_form,
        "Search Term? ",textfield('searchterm'),p,
        "What's the combination?", p,
        checkbox_group(-name=>'words',
		       -values=>['Ebay','Yahoo','Yahoo
Sg','Interauct'],
		       -defaults=>['Ebay','Yahoo']), p,
        submit,
        end_form,
        hr;

if (param()) {
	print "Searching for search term: ",em(param('searchterm')),p,
	 "on auction sites: ",em(join(", ",param('words'))),p,
	hr;


	# check which auction sites were selected and go into
individual search loops for each one
	# @turned_on = $query->param('words');
	# print $turned_on[0];


	$content =
get("http://search.auctions.shopping.yahoo.com/sg/search/auc?alocale=0sg&p=".em(param('searchterm'))."&auccat=");
	print $content;

}



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

Date: Sat, 16 Nov 2002 06:57:00 GMT
From: matt <linuxnb@yahoo.com>
Subject: Re: Calling CGI script in restrcted dir (.htaccess) from outside shtml (SSI) ?
Message-Id: <0%lB9.40643$NH2.1763@sccrnsc01>

MR wrote:

-snip-

>( /www1102/web/ is my absolute web dir)

-snip-

> 
> The line in the shtml is:
>    <!--#exec cgi="/cgi-bin/SR/CAON/caon_aa.cgi" -->

I've only fiddled with SSI, but I'm pretty sure I know the problem.
SSI stands for Server Side Includes. Call this script just like you would 
from the command line - with the full path.

        <!--#exec  /www1102/web/cgi-bin/SR/CAON/caon_aa.cgi -->

Not sure about the SSI exec syntax, but you get the idea.

Also, this is a perl NG. This would have been better posted on 
alt.apache.configuration.

-- Matt





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

Date: Sat, 16 Nov 2002 12:09:23 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: CPAN local installation
Message-Id: <3dd62e54.60554839@news.erols.com>

"Jon" <jonov@iprimus.com.au> wrote:

: I have received a DVD with a copy of CPAN on it. I have installed it onto a
: machine. However I'm not sure how I can use it as a repository for various
: perl installations on various machines. Do I need a web server for this or
: can it be done another way?

I can't quite see how a web server would get it done at all, so I'll
skip that part.

You can set the PERL5LIB environment variable to a directory on a
remote machine, e.g. //name/path/to/site/lib.  The local perl will
automatically add that to its list of places to search for libraries.
See perlrun for details.

I dunno about "various perl installations," though.  You should
probably want to avoid this unless they're all running the same OS and
Perl version.



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

Date: Sat, 16 Nov 2002 06:15:36 GMT
From: "Lois" <lois@hotmail.com>
Subject: CSV SQL
Message-Id: <colB9.40328$NH2.2142@sccrnsc01>

Hi all,

I created a CSV SQL using the following command:
$UserDB=DBI->connect("DBI:CSV:f_dir=.") or die "Cannot connect:
$DBI::errstr\n";
$createTable = $UserDB->prepare("CREATE TABLE userdb(
                             username varchar(32) not null,
                             user_id char(10) not null,
                             group_id char(10) not null) ");
$createTable->execute();
$insert = $UserDB->prepare("INSERT ....);

after the userdb file is created, how can I manually add records to the file
by using vi and yet recognised by the select statement to retrieve record.


Thanks,
lois





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

Date: Sat, 16 Nov 2002 02:41:16 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: CSV SQL
Message-Id: <3DD5F69C.3FBB9A89@earthlink.net>

Lois wrote:
> 
> Hi all,
> 
> I created a CSV SQL using the following command:
> $UserDB=DBI->connect("DBI:CSV:f_dir=.") or die "Cannot connect:
> $DBI::errstr\n";
> $createTable = $UserDB->prepare("CREATE TABLE userdb(
>                              username varchar(32) not null,
>                              user_id char(10) not null,
>                              group_id char(10) not null) ");
> $createTable->execute();
> $insert = $UserDB->prepare("INSERT ....);
> 
> after the userdb file is created, how can I manually add records to
> the file by using vi and yet recognised by the select statement to
> retrieve record.

Add a line of comma seperated values to the file?  It's not that hard.

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: 16 Nov 2002 11:30:53 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: dealing with multiple entires in a multi-dimensional hash
Message-Id: <u9d6p5kaz6.fsf@wcl-l.bham.ac.uk>

Randy <nospam@rostie.net> writes:

> On 15 Nov 2002 21:07:34 +0000, Brian McCauley <nobull@mail.com> wrote:
> 
> >>         # Check to see if this user has another script in here
> >>         if (exists $users{$user}){
> >>                 # Yes they do, add this file to it.
> >>                 $users{$user} .= "\t\t\t$file\t\t$safe\t\t$version";
> >>         }else{
> >>                 # No they don't
> >>                 $users{$user} = "$file\t\t$safe\t\t$version";
> >>         }
> >> 
> >> Isn't there any easier way to do this?
> >
> >That's not a multi-dimensional hash and doesn't seem to relate to the
> >stuff that went before.
> >
> >It's therefore impossible to figure out to what "do this" refers.
> 
> In plain english:
> 
> If this user is already in the index %users, don't create another
> $user entry

Sorry I just don't get it.  The english is plain but your
understanding of what you are tring to ask is not.

The way to do something dependant on if key $user is already in the
index %users is just to test exists($users{$user}) as you do.  There
is no simpler way to do Y.

I thought (and still thik) you were asking about some X, and I showed
you a simpler way to what I guessed X to be.  The simpler way did not
involve Y.

> Maybe I am doing it wrong, what if I make the index %file (instead of
> %users)

You can have muliple hashes indexing a record set.  You can structure
these differently pending on if the index key is unique.

my @record_set = (
  { user => 'joe', file => 'foo' },
  { user => 'joe', file => 'baz' },
  { user => 'jim', file => 'bar' },
);

my (%user,%file);
for (@record_set) {
  $file{$_->{file}} = $_;
  push @{$user{$_->{user}}} => $_;
}

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Sat, 16 Nov 2002 13:49:44 -0800
From: "Ireland" <mail@eircom.net>
Subject: Download TK module ?
Message-Id: <ar5elo$1ff$1@dorito.esatclear.ie>


Hi,

Can someone tell me where I can download the TK module? I have got
ActiveState Perl but I want to get TK.




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

Date: 15 Nov 2002 21:36:37 -0800
From: thomastk@hotmail.com (Thomas Theakanath)
Subject: Error reading the column names using DBI
Message-Id: <78b857d2.0211152136.2d800613@posting.google.com>

Hi,

I have problem reading column names after a query is executed using
DBI module against a mySQL database. The program is similiar to the
following:

my $sth = $dbh->prepare("SELECT * from TEMP");
$sth->execute or die "unable to execute query: $dbh->errstr\n";
my $name = $sth->{NAME};
print "@$name\n";

At the last line, I get the following message:
Can't set DBI::st=HASH(0x2a3ce0)->{NAME}: unrecognised attribute or
invalid value

What could I be doing wrong? Please help

- Thomas.


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

Date: Sat, 16 Nov 2002 03:10:56 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: How to kill a system or process open  call on timeout in Windows
Message-Id: <3DD5FD90.58DD35ED@earthlink.net>

Seth Brundle wrote:
[snip]
> So, I guess there is like, no way for me to timeout a function under
> windows, eh?

It can be done, but not easily.  There are certain things which you can
write timeouts for (such as IO over sockets), and, with a bit of
ingenuity, you can (usually) make it so that timing out *that* acts the
same (or nearly the same) as timing out the thing you want.

As an example: Let's suppose you've got a program, "someprog" which
produces output.  For the sake of simplicity, we'll further assume that
it takes no command line arguments.

Code like the following should work:

   use IO::Socket::INET;
   my $s = IO::Socket::INET->new(Listen=>1);
   use IPC::Open2;
   use Symbol qw(gensym);
   my $pid = open2( ">&".(fileno $s), gensym, join "",
      q[perl -MIO::Socket -e "],
      q[my $x = bless \*STDOUT, q[IO::Socket::INET];],
      q[my $y = $x->accept;],
      q[open STDOUT, q[>&].fileno($y);],
      q[exec q[someprog];],
      q["],
   );
   my $port = $s->sockport;
   close $s;
   $s = IO::Socket::INET->new("127.0.0.1:$port");

   use IO::Select;
   my $select = IO::Select->new($s);
   my $expire = time() + 60;
   LOOP: {
      my $timeout = time() - $timeout;
      last LOOP if $timeout < 0;
      unless( () = $select->can_read($timeout) ) {
         print "Someprog timed out!\n";
         last LOOP;
      }
      my $n = sysread( $s, $_, 8192 );
      defined($n) or die "Error in sysread: $!";
      print;
      redo LOOP if $n;
   }

This code is untested.  Most error checking has been omited for brevity,
but I would *definitly* add it in if you plan on changing this to
something resembling production code.

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: 16 Nov 2002 01:49:46 -0800
From: matthew.nicholas@yale.edu (matt)
Subject: MIME plain text body extraction
Message-Id: <3a855952.0211160149.5eeefb84@posting.google.com>

Hello, 

I am sort of a newbie to Perl, and especially to email handling. What
I am trying to do is write a program that retrieves mail using
Net::POP3 and Mail::Internet, and then extracts the main body message
into a string or array, and discards everything else.

I have been able to access the mailbox and get a reference to an array
containing the lines of the body. While some messages are just plain
text, in others, they are MIME formatted and what I get is something
like:

            This is a multi-part message in MIME format.

             ------=_NextPart_000_000D_01C28A12.9B611330
             Content-Type: text/plain;
	             charset="us-ascii"
             Content-Transfer-Encoding: 7bit

             THIS IS THE TEXT OF THE MESSAGE 

             ------=_NextPart_000_000D_01C28A12.9B611330
             Content-Type: text/html;
             	charset="us-ascii"
             Content-Transfer-Encoding: quoted-printable

             <html xmlns:o=3D"urn:schemas-microsoft-com:office:office"
=
             xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
             xmlns=3D"http://www.w3.org/TR/REC-html40">

and so on. The problem is that depending on which person sends email
to the account, the MIME formatting looks slightly different, so I
cannot just use simple pattern matching to extract the plain text or
html from the body. I think I need to use MIME::Parser to do this in
the following way:

                 $bodyref= Mail::Internet->new(\@Lines)->body();
		 $parser  = new MIME::Parser;
                 my $entity = $parser->parse_data(@$bodyref);

but beyond creating the entity, I am not sure how to proceed. I've
tried a number of things, and read through a lot of newgroups, but I
can't seem to figure it out...It seems like it should be fairly simple
-- all I want is to put the lines of the actual message into a scalar
or array (and only the "new" message -- any attached replies, etc can
be thrown out).

Could anyone tell me how to do this? Any help with this would be MUCH
appreciated. Thanks in advance for your time and effort.

Thanks, 

Matt


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

Date: Sat, 16 Nov 2002 21:09:48 +1100
From: "Rodney Hunter" <rwh2100@hotmail.com>
Subject: parameter 
Message-Id: <7PoB9.28755$Sr6.820068@ozemail.com.au>


Perl newbie q - i have taken all the real code out to leave the test
'print' - how come the subroutine reverts the parameter back to the value
from the earlier pass?

thanks
Rodney Hunter

first pass  job_no=7010      result  B 7010 C 7010 D 7010
secd pass  job_no=7011      result  B 7011 C 7010 D 7011
third pass  job_no=7012      result  B 7012 C 7010 D 7012


# get value passed from form
my $thisjobno = $q->param('job_no');
# print HTML header
printHead('EA Journal');
print <<ENDOFTEXT;
B $thisjobno
ENDOFTEXT
Sect1 ($thisjobno);
print <<ENDOFTEXT;
D $thisjobno
ENDOFTEXT

sub Sect1{
print <<ENDOFTEXT;
C $thisjobno
ENDOFTEXT
}






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

Date: Sat, 16 Nov 2002 21:15:05 +1100
From: "Rodney Hunter" <rwh2100@hotmail.com>
Subject: parameter 
Message-Id: <4UoB9.28756$Sr6.819930@ozemail.com.au>

Perl newbie q - i have taken all the real code out to leave the test
'print' - how come the subroutine reverts the parameter back to the value
from the earlier pass?

thanks
Rodney Hunter

first pass  job_no=7010      result  B 7010 C 7010 D 7010
secd pass  job_no=7011      result  B 7011 C 7010 D 7011
third pass  job_no=7012      result  B 7012 C 7010 D 7012


# get value passed from form
my $thisjobno = $q->param('job_no');
# print HTML header
printHead('EA Journal');
print <<ENDOFTEXT;
B $thisjobno
ENDOFTEXT
Sect1 ($thisjobno);
print <<ENDOFTEXT;
D $thisjobno
ENDOFTEXT

sub Sect1{
print <<ENDOFTEXT;
C $thisjobno
ENDOFTEXT
}







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

Date: Sat, 16 Nov 2002 10:19:27 GMT
From: "Gregory Toomey" <nobody@noplace.com>
Subject: Re: parameter
Message-Id: <01c28d5b$24309820$075d8690@gmtoomey>

Rodney Hunter <rwh2100@hotmail.com> wrote in article
<4UoB9.28756$Sr6.819930@ozemail.com.au>...
> Perl newbie q - i have taken all the real code out to leave the test
> 'print' - how come the subroutine reverts the parameter back to the value
> from the earlier pass?

You used a global variable in the subroutine, which kept its value between
subroutine calls?
See http://perl.plover.com/FAQs/Namespaces.html

gtoomey


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

Date: Sat, 16 Nov 2002 22:05:23 +1100
From: "Rodney Hunter" <rwh2100@hotmail.com>
Subject: Re: parameter
Message-Id: <eDpB9.28761$Sr6.820481@ozemail.com.au>


"Gregory Toomey" <nobody@noplace.com> wrote in message
news:01c28d5b$24309820$075d8690@gmtoomey...
> Rodney Hunter <rwh2100@hotmail.com> wrote in article
> <4UoB9.28756$Sr6.819930@ozemail.com.au>...
> > Perl newbie q - i have taken all the real code out to leave the test
> > 'print' - how come the subroutine reverts the parameter back to the
value
> > from the earlier pass?
>
> You used a global variable in the subroutine, which kept its value between
> subroutine calls?
> See http://perl.plover.com/FAQs/Namespaces.html
>
> gtoomey

thanks - i need to read the reference properly another time (too much work
today) - i have used strict in the main program - do i need it in the sub
also?

# Use the CGI Perl library
use CGI ':standard';
# Use DBI/DBD:
use DBI;
use strict;
# Use vars declares global variables to be used in script
use vars qw($baseURL);
# Declare base URL for return from this page
$baseURL = "index.html";
# Create a new CGI object that contains the passed parameters
my $q = new CGI;

# get value passed from form
my $thisjobno = $q->param('job_no');
# print HTML header
printHead('EA Journal');
print <<ENDOFTEXT;
 B $thisjobno
ENDOFTEXT
Sect1 ($thisjobno);
print <<ENDOFTEXT;
E $thisjobno
ENDOFTEXT

sub Sect1{
print <<ENDOFTEXT;
C $thisjobno
ENDOFTEXT
}






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

Date: 16 Nov 2002 11:14:42 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: parameter
Message-Id: <ar59b2$arj$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Rodney Hunter:

> "Gregory Toomey" <nobody@noplace.com> wrote in message
> news:01c28d5b$24309820$075d8690@gmtoomey...

>> You used a global variable in the subroutine, which kept its value between
>> subroutine calls?
>> See http://perl.plover.com/FAQs/Namespaces.html

> thanks - i need to read the reference properly another time (too much work
> today) - i have used strict in the main program - do i need it in the sub
> also?

No, you don't. When enabling strictures in the in the top-level block
(in your case this was the whole file) they propagate through the whole
script and into every block below. You can, however, temporarily disable
them inside a subroutine or block if you need that for some reason:

    use strict;
    ...
    sub f {
        no strict;
        $var = 1;
    }

Sometimes this can become necessary when some nasty symbol table
manipulations need to be done in which case "no strict 'refs'" is a
common idiom to allow symbolic references. But you don't (yet) need to
know about such subtleties.

Tassilo
-- 
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;


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

Date: Sat, 16 Nov 2002 22:29:04 +1100
From: "Rodney Hunter" <rwh2100@hotmail.com>
Subject: Re: parameter
Message-Id: <rZpB9.28769$Sr6.820596@ozemail.com.au>


"Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de> wrote in
message news:ar59b2$arj$1@nets3.rz.RWTH-Aachen.DE...
> Also sprach Rodney Hunter:
>
> > "Gregory Toomey" <nobody@noplace.com> wrote in message
> > news:01c28d5b$24309820$075d8690@gmtoomey...
>
> >> You used a global variable in the subroutine, which kept its value
between
> >> subroutine calls?
> >> See http://perl.plover.com/FAQs/Namespaces.html
>
> > thanks - i need to read the reference properly another time (too much
work
> > today) - i have used strict in the main program - do i need it in the
sub
> > also?
>
> No, you don't. When enabling strictures in the in the top-level block
> (in your case this was the whole file) they propagate through the whole
> script and into every block below. You can, however, temporarily disable
> them inside a subroutine or block if you need that for some reason:
>
>     use strict;
>     ...
>     sub f {
>         no strict;
>         $var = 1;
>     }
>
> Sometimes this can become necessary when some nasty symbol table
> manipulations need to be done in which case "no strict 'refs'" is a
> common idiom to allow symbolic references. But you don't (yet) need to
> know about such subtleties.
>
> Tassilo
> --
> $_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
> pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
> $_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;

Ok thanks - can you see what's up with that code?




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

Date: 15 Nov 2002 21:29:40 -0800
From: krakle@visto.com (krakle)
Subject: Re: Perl searching a huge mySQL database...
Message-Id: <237aaff8.0211152129.5873e9e@posting.google.com>

tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnat93ig.1u7.tadmc@magna.augustmail.com>...
> > Any tips and insight for me?
> 
> 
> Yes, but this is a family newsgroup, so I'll restrain myself.

I thank you for your response Tad.
By your last comment I sense you are holding back aggression? Well,
relax just a question I asked in an appropiate manner in the
appropiate newsgroup so please save any aggression you have for
someone who comes in here in the opposite mannerism.

Thank you again.


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

Date: 15 Nov 2002 21:33:56 -0800
From: krakle@visto.com (krakle)
Subject: Re: Perl searching a huge mySQL database...
Message-Id: <237aaff8.0211152133.3413afa2@posting.google.com>

Simon Taylor <simon@unisolve.com.au> wrote in message news:<ar233r$95h$1@otis.netspace.net.au>...
> My experience with large MySQL databases and perl has been very positive, 
> though of course a lot depends on what *you* mean by the word "huge". 

Thank you for the link Simon. Yes it does help.
I'm setting up a service that will allow any visitor to a the web site
to sign up. Usernames and additional information will be stored in the
DB and searchable by other users. I can't tell you how many users will
join up but we are predicting thousands. I don't have a lot of
experience with mySQL although I have fiddled with it. So please
excuse the lack of mySQL knowledge here.


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

Date: 15 Nov 2002 21:36:36 -0800
From: krakle@visto.com (krakle)
Subject: Re: Perl searching a huge mySQL database...
Message-Id: <237aaff8.0211152136.444a01aa@posting.google.com>

gorilla@elaine.furryape.com (Alan Barclay) wrote in message news:<1037341115.908167@elaine.furryape.com>...
> In article <237aaff8.0211142142.18511dbb@posting.google.com>,
> krakle <krakle@visto.com> wrote:
> >time is very crucial. With Perl, is it possible to search a large
> >database with in a reasonable amount of time? Any additional modules
> >to look into? Any tips and insight for me?
> 
> This isn't a perl question, it's a database question.

I thank you for your response Alan but this was indeed a Perl
question. I needed to know if I needed any other Perl modules (which
was stated) and if Perl was sufficient for the job (which was stated).
I don't see how asking a question regarding Perl for DB in a DB
newsgroup would serve me any justice. they would redirect me here.


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

Date: 15 Nov 2002 21:40:02 -0800
From: krakle@visto.com (krakle)
Subject: Re: Perl searching a huge mySQL database...
Message-Id: <237aaff8.0211152140.da06dbe@posting.google.com>

ctcgag@hotmail.com wrote in message news:<20021115150902.745$fY@newsreader.com>...
> krakle@visto.com (krakle) wrote:
> > Any additional modules
> > to look into? Any tips and insight for me?
> 
> Additional to what?  We don't what modules you already looked into.

Thank you for your response. If any modules were suggested it would be
additional to the project. Which is what was meant. Regardless, it was
clear.


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

Date: Sat, 16 Nov 2002 02:37:47 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Socket client/server example not working on Windows 2K
Message-Id: <3DD5F5CB.EAB11B1D@earthlink.net>

Rocco Caputo wrote:
[snip]
> Generally speaking, one forks off a pool of DBI connections and passes
> requests to idle ones.  They perform the slow task of... well,
> whatever you tell them to... off in other processes, so things run
> concurrently and much faster.
> 
> The method works beautifully on Unix systems.  Too bad this is fraught
> with trouble on Windows, or it would be ideal.

It can be done on windows without *too* much problem, but you can't
simply use fork() for starting each process in the pool -- you have to
use IPC::Open2.

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Sat, 16 Nov 2002 06:25:37 GMT
From: "Jose D Castillo" <purplefeetguy@sbcglobal.net>
Subject: Sum-Product Number Logic Question
Message-Id: <BxlB9.140$tD4.20915216@newssvr21.news.prodigy.com>

Hello, I am trying to code a solution that will allow me to determine if a
number is a sum-product number. Here is a short description:

   A sum-product number is a number n such that the sum of n's digits
   times the product of n's digits is n itself, for example

     135 = (1+3+5)(1*3*5)
     135 =   (9)    (15)
     135 =      135

I am just looking for a direction on how to setup the logic for this. I plan
on using a loop to iterate the range of number than an inner loop to do the
calculations/comparisons. I know that I can modulus and division to get each
digit in the current iterations number, but I don't know what to do to make
the proper comparisons to determine whether the number is a sum-product
number or not.

Any help will be appreciated.




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

Date: Sat, 16 Nov 2002 07:51:09 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Sum-Product Number Logic Question
Message-Id: <3DD5F8C7.D19B63F8@acm.org>

Jose D Castillo wrote:
> 
> Hello, I am trying to code a solution that will allow me to determine if a
> number is a sum-product number. Here is a short description:
> 
>    A sum-product number is a number n such that the sum of n's digits
>    times the product of n's digits is n itself, for example
> 
>      135 = (1+3+5)(1*3*5)
>      135 =   (9)    (15)
>      135 =      135
> 
> I am just looking for a direction on how to setup the logic for this. I plan
> on using a loop to iterate the range of number than an inner loop to do the
> calculations/comparisons. I know that I can modulus and division to get each
> digit in the current iterations number, but I don't know what to do to make
> the proper comparisons to determine whether the number is a sum-product
> number or not.


for my $num ( 10 .. 9999 ) {
    my $sum  = eval join '+', split //, $num;
    my $prod = eval join '*', split //, $num;
    print "$num\n" if $sum * $prod == $num;
    }



John
-- 
use Perl;
program
fulfillment


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

Date: Sat, 16 Nov 2002 11:19:08 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Sum-Product Number Logic Question
Message-Id: <3dd625b6.58347944@news.erols.com>

"Jose D Castillo" <purplefeetguy@sbcglobal.net> wrote:

: Hello, I am trying to code a solution that will allow me to determine if a
: number is a sum-product number. Here is a short description:
: 
:    A sum-product number is a number n such that the sum of n's digits
:    times the product of n's digits is n itself, for example
: 
:      135 = (1+3+5)(1*3*5)
:      135 =   (9)    (15)
:      135 =      135
: 
: I know that I can modulus and division to get each
: digit in the current iterations number, 

Even easier, treat the number as a string and burst the digits apart.

    my @digits = $number =~ /\d/g;

Assuming you're restricting the code to base-10 numbers, that is.

: but I don't know what to do to make
: the proper comparisons to determine whether the number is a sum-product
: number or not.

The useful comparison operator would be == .

: Any help will be appreciated.

In that case, exploit the results others have already computed.

    #!perl -l
    use warnings;
    use strict;
    for( 0 .. 1E7 ) {
        print "$_ is a sum-product number."
            if is_sum_product($_);
    }

    sub is_sum_product {
        return 1 if
            $_[0] == 1
            || $_[0] == 135
            || $_[0] == 144;
        return 0;
    }



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

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


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