[19867] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2062 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 4 06:05:37 2001

Date: Sun, 4 Nov 2001 03:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1004871907-v10-i2062@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 4 Nov 2001     Volume: 10 Number: 2062

Today's topics:
        .cgi program <creafin1998@yahoo.com>
    Re: .cgi program <tim@vegeta.ath.cx>
    Re: Adding Null Values into a Tied HashRef <please@no.spam>
    Re: Adding Null Values into a Tied HashRef nobull@mail.com
        ASCII and portability (Joachim Ziegler)
    Re: DB module to store references? <please@no.spam>
    Re: Email errors <gellyfish@gellyfish.com>
    Re: hi <wwonko@rdwarf.com>
    Re: How to build a timer ... <gellyfish@gellyfish.com>
    Re: how to detect broken link <gellyfish@gellyfish.com>
    Re: How to store a table and retrieve items? <darkon@one.net>
    Re: How to store a table and retrieve items? <jeff@vpservices.com>
    Re: How to store a table and retrieve items? <jeff@vpservices.com>
        i do not understand it(the =~s/.../.../), thanx! (hugh1)
    Re: i do not understand it(the =~s/.../.../), thanx! <tim@vegeta.ath.cx>
    Re: Perl on Windows2000 <gellyfish@gellyfish.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 3 Nov 2001 21:32:16 -0600
From: "John Smith" <creafin1998@yahoo.com>
Subject: .cgi program
Message-Id: <tu9divpqapse4f@corp.supernews.com>

I have a very annoying problem occurring with a new cgi program I wrote.
I'm opening a text file and processing data from the file, then placing the
results in another file.  Done it a million times with no problems.  This
one is a little different in the since that I have 2 'for' loops which will
cause the program to loop approximately 40,000 * (40,000 - n) times, where n
starts at 1 and is incremented.  This is more looping than I usually deal
with in a program.

Anyway, the problem is that the program writes to my output file about 22-27
lines, then terminates.  It was consistantly 27 lines, then went down to 23
lines after I made a change, then down to 22 lines after another change.
After undo-ing my changes, then it still consistantly writes only 22 lines,
then I get a the "
Internal Server Error
The server encountered an internal error or misconfiguration and was unable
to complete your request." error that's so common.  I am running the program
through my browser and do not have access to telnet.

Any advise?  It seems like I'm bumping up against some kind of buffer limit.
Like I said part of my output file gets written (only 22 lines out of about
40,000 that need to be written).  I'm totally unfamilar with these types of
limitations in the cgi/perl world

Thanks in advance.




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

Date: Sun, 04 Nov 2001 03:41:10 GMT
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: .cgi program
Message-Id: <slrn9u9ek4.553.tim@vegeta.ath.cx>

Me parece que John Smith <creafin1998@yahoo.com> dijo:
>  I have a very annoying problem occurring with a new cgi program I wrote.
>  I'm opening a text file and processing data from the file, then placing the
>  results in another file.  Done it a million times with no problems.  This
>  one is a little different in the since that I have 2 'for' loops which will
>  cause the program to loop approximately 40,000 * (40,000 - n) times, where n
>  starts at 1 and is incremented.  This is more looping than I usually deal
>  with in a program.
>  
>  Anyway, the problem is that the program writes to my output file about 22-27
>  lines, then terminates.  It was consistantly 27 lines, then went down to 23
>  lines after I made a change, then down to 22 lines after another change.
>  After undo-ing my changes, then it still consistantly writes only 22 lines,
>  then I get a the "
>  Internal Server Error
>  The server encountered an internal error or misconfiguration and was unable
>  to complete your request." error that's so common.  I am running the program
>  through my browser and do not have access to telnet.
>  
>  Any advise?  It seems like I'm bumping up against some kind of buffer limit.
>  Like I said part of my output file gets written (only 22 lines out of about
>  40,000 that need to be written).  I'm totally unfamilar with these types of
>  limitations in the cgi/perl world
>  
>  Thanks in advance.

You're going to need to give us more details, such as Perl version,
platform that your perl's running on, the type of data it's processing,
and an example of the code that processes it.

And unless you're running your script on a pre-286 processor, your
program should be able to process a lot more than 27 lines before
croaking.

It sounds like an error in your loop logic (you said it's more than
you're used to dealing with, right?) but post some code and sample data
and we'll see what we can do.

Cheers,
Tim
-- 
You are utterly the stupidest, most self-centered, appallingest excuse
for an anthropomorphic personification on this or any other plane!
    -- Death, The Sandman


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

Date: Sun, 04 Nov 2001 09:40:50 GMT
From: Andrew Cady <please@no.spam>
Subject: Re: Adding Null Values into a Tied HashRef
Message-Id: <877kt6ri4i.fsf@homer.cghm>

emoore@cofs.net (E. Moore) writes:

> Can one add a null value into tied hasref?
> 
> I am using the Vars method from CGI.pm.  According to the docs, when
> Vars is use in scalar context, it returns a tied HashRef.
> 
> use strict;
> use CGI qw/param header/;
> my $q = new CGI;
> my $in  =  $q->Vars;
> 
> When I try to add a null value to the hasref
> 
> $in->{lastname} = '';

"Null value"?  That's an empty string.  "Null value" is very
confusing, I thought at first you meant undef...

> and immediately check the result
> 
> if(!defined $in->{lastname}) {
>    print "\$in->{lastname} =>not defined<br>"
> }
> 
> $in->{lastname} 'is not defined.

OK, and the problem is that you want an empty string, not undef.

> I am not familiar with tied hashes.  I've checked the Camel books,
> but can't see if I am doing some wrong, or by definition a null
> value can not go into a tied hash.  Any suggestions?  Thanks.  Eric

Well tied hashes (or tied whatever) MAY support the distinction
between undef and empty strings, or they may not.  Actually they can
do pretty much whatever they want; the value they return doesn't have
to have anything to do with the value you set.  It could use the value
you set as an srand seed to the values it returns.  It's just the
return value of a function.  If the function never returns an empty
string, you'll never get an empty string out of it, even if that's
what you assign.

In practice, we might expect undef/empty string to be a common
problem, as the representation the tied hash uses may not not support
any natural way to differentiate between them.  I know some tied-hash
DBM's don't support undef; I doubt there's any way to store undef in
an array tied to a text file with recno.  I'm surprised that CGI
wouldn't, though.  Perhaps CGI must treat an empty string the same way
as an undef one when it's generating actual HTML, so it doesn't let
you make the distinction.  It's probably in the CGI documentation
somewhere, anyway.


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

Date: 04 Nov 2001 10:10:12 +0000
From: nobull@mail.com
Subject: Re: Adding Null Values into a Tied HashRef
Message-Id: <u98zdmlud7.fsf@wcl-l.bham.ac.uk>

emoore@cofs.net (E. Moore) writes:

> Can one add a null value into tied hasref?

You mean a tied hash via a reference.

That is up to the implementor of the tied hash.

That's kinda the whole point of tied things - you can use the same
syntax as Perl's built-in types but roll your own semantics.

> use strict;
> use CGI qw/param header/;
> my $q = new CGI;
> my $in  =  $q->Vars;
> 
> $in->{lastname} = '';

> if(!defined $in->{lastname}){
>    print "\$in->{lastname} =>not defined<br>"
>    }
 
> $in->{lastname} 'is not defined.

I am unable to reproduce this bug.

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


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

Date: 4 Nov 2001 02:05:28 -0800
From: ziegler@algorilla.de (Joachim Ziegler)
Subject: ASCII and portability
Message-Id: <93aad7d0.0111040205.739f1ebc@posting.google.com>

hi,

some questions about character encoding and portability:

does perl depend on ASCII (or an extension of ASCII) being the
internal character encoding?

are there still machines today that use something like EBCDIC or any
completely other character encoding?

if so, are perl-programs ready to run on such machines?
this means, that if i write something like

print "hello world\n";

does ist print 'hello world' on an EBCDIC machine?

are questions like these an important subject in making perl programs
portable? 


thank you in advance,
greetings from germany,
joachim


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

Date: Sun, 04 Nov 2001 09:42:21 GMT
From: Andrew Cady <please@no.spam>
Subject: Re: DB module to store references?
Message-Id: <871yjeri1z.fsf@homer.cghm>

"Phil R Lawrence" <prlawrence@lehigh.edu> writes:

> Hello,
> 
> I need to sort a largish file of individual reports; last time I
> used a hash to do it.  This time around the file was too big -- ran
> out of memory.

What do you mean you used a hash to do it?  You can't sort a hash.  If
you're storing this data in a hash -- don't.  You have to copy it to a
list to sort it anyway.  Lose the hash.

> I thought I would use NDBM_File or somesuch to put my hash on the
> filesystem instead of in memory, but this and other *DBM_File
> modules store only flat scalars.  :-(

Huh?  What's in the hash instead of scalars?

> Before I ask my sysadmin to install Berkley DB (for use with
> DB_File), can anyone recommend another module/approach that I might
> try?
> 
> FWIW, the data I need to sort by is not in the file, so I can't use
> a plain UNIX utility such as sort.  I am noting a unique identifier
> found on each report in the file and doing a database lookup to sort
> those unique identifiers by related information found in the
> database.  It seemed easiest to simply store an aref of the report
> lines in a hash using the unique identifiers as hash keys.

OK, I think I maybe get what you're doing here.  The hash is
references to your records as keys and DB query results as values?

Well, there's no reason you couldn't put the references into the tied
hash; you don't need the DB to save the values between invocations.
You could also use indices rather than references.  But, you really
shouldn't be using a hash for this.  As I said above, you have to copy
to a list anyway.  The hash's memory use is entirely superfluous;
don't put it on disk, get rid of it altogether.

Store your data in a list.  If you need two pieces of data per element
(one to save, one to sort on), make it a list of lists.

Perl's builtin "sort" creates a copy of the sorted list (afaik it
doesn't optimize this away for @a = sort @a), so if you're really
short on memory and the list elements are big, you might want to sort
indices into the list rather than the list elements themselves.  Of
course, you can only save so much this way.  If you still can't fit
it, use a merge sort.


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

Date: 4 Nov 2001 10:49:43 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Email errors
Message-Id: <9s36g7$sf8$6@uranium.btinternet.com>

Milan Jaksic <milan@balkanmedia.com> wrote:
> Hi
> 
> I am trying to write script that could handle mail errors, and this is the
> part of script that i thought it would work:
> 

<send>

> when I tried to see what hapens when i try to send mail to unknown user the
> following hapens:
> I get a message in browser that it could not send mail since the user is
> unknown on domain, and it
> writes mail to file dead letterl.
> 
> So my question is how to capture error while sending mail in my own file;
> 

This is a question of the configuration of the sendmail.  It is specifically
down to the 'ErrorMode' configuration which you can read about in the
sendmail manpage.

/J\
-- 
Jonathan Stowe                      |
<http://www.gellyfish.com>          |      This space for rent
                                    |


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

Date: Sun, 4 Nov 2001 07:18:57 +0000 (UTC)
From: Louis Erickson <wwonko@rdwarf.com>
Subject: Re: hi
Message-Id: <9s2q51$e00$1@holly.rdwarf.com>

Mark Goodge <mark@good-stuff.co.uk> wrote:
: hugo wrote:

<snip>

:> How can I have people include the ' character without it causing
:> problems for mysql?

: It needs to be escaped. Before passing the string to SQL, change all the
: instances of ' to \' so that they are passed straight through.

: Assuming your input variable is called $input, then this will do it:

:   $input =~ s/\'/\\'/g ;

: It also makes sense to escape anything else that could cause problems
: for SQL, such as double quotes. 

The Perl DBI code (perldoc DBI) has a useful function called quote,
which does the right thing for whichever database that you're using
and will handle all the wierd corner cases that a simple regexp
might not catch.

Assuming you have a valid handle, $dbh, you can say:

$sql = $dbh->quote("sql string");

It will return a properly escaped string for you.

Hope it helps.



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

Date: 4 Nov 2001 10:56:37 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: How to build a timer ...
Message-Id: <9s36t5$sf8$7@uranium.btinternet.com>

Olivier <ochampag@nortelnetworks.com> wrote:
> Hi all,
> 
> I need to do a timer in millisecond ... as a function :
> 
> Timer(x millisecond, action) will execute the action in x millisecond and
> not in second...
> What kind of function date/time/ ??? should be good for that ?
> 

I would read the section entitled :

       How can I measure time under a second?

in perlfaq8

/J\
-- 
Jonathan Stowe                      |
<http://www.gellyfish.com>          |      This space for rent
                                    |


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

Date: 4 Nov 2001 11:00:04 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: how to detect broken link
Message-Id: <9s373k$sf8$8@uranium.btinternet.com>

Pujo C A <adustipujo1@mediaone.net> wrote:
> 
> Hi,
> 
> I am trying to make a bots  , but I encounter a new problem. with a broken
> link the LWP::simple is not doing very good job.
> So I wonder is there any way that I can sense that first.
> 
> 

The use LWP::UserAgenet so you can access the status returned from the
server.

/J\
-- 
Jonathan Stowe                      |
<http://www.gellyfish.com>          |      This space for rent
                                    |


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

Date: Sun, 04 Nov 2001 02:37:35 GMT
From: "David K. Wall" <darkon@one.net>
Subject: Re: How to store a table and retrieve items?
Message-Id: <Xns914EDC420C689darkononenet@24.2.68.108>

jeff@vpservices.com (Jeff Zucker) wrote:

> David Wall <darkon@one.net> wrote in message
> news:<Xns914D8B7B2C6A3darkononenet@207.126.101.97>... 
>> ississauga@hotmail.com wrote on 02 Nov 2001:
>> > 
>> > A table has prices for items having width and height,
> 
> [snip]
> 
>> If you use Jeff Zucker's AnyData module then you can expand the table
>> at will and not have to worry.  Well, not much -- you do have to make
>> sure that each combination of height category and width category is
>> unique. 
> 
> You don't have to worry even if there are non-unique combinations. 
> See below.

Well, I didn't mean to imply that AnyData *couldn't* return more than one 
piece of data, just that I didn't want it to in this case.

[snip my code]
> 
> That will work fine if you only want to grab the first of potentially
> several prices that match the criteria.  If you want to grab all of
> the prices for rows matching the criteria (even if there are
> non-unique rows or combinations), do this instead of that price line:

I was counting on the prices being unique.  If I go to a store to buy an 
item, I don't generally expect them to tell me it costs x, y, or z amount 
of money.  (I'd pick the cheapest, of course. :-)

-- 
David Wall - darkon@one.net
"When the end of the world comes, I want to be in Cincinnati. Everything
happens ten years later there." -- Mark Twain


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

Date: Sat, 03 Nov 2001 18:58:06 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: How to store a table and retrieve items?
Message-Id: <3BE4AEBE.CCBFA936@vpservices.com>

"David K. Wall" wrote:
> 
> jeff@vpservices.com (Jeff Zucker) wrote:
> 
> > David Wall <darkon@one.net> wrote in message
> > news:<Xns914D8B7B2C6A3darkononenet@207.126.101.97>...
> >> ississauga@hotmail.com wrote on 02 Nov 2001:
> >> >
> >> > A table has prices for items having width and height,
> >
> > [snip]
> >
> >> If you use Jeff Zucker's AnyData module then you can expand the table
> >> at will and not have to worry.  Well, not much -- you do have to make
> >> sure that each combination of height category and width category is
> >> unique.
> >
> > You don't have to worry even if there are non-unique combinations.
> > See below.
> 
> Well, I didn't mean to imply that AnyData *couldn't* return more than one
> piece of data, just that I didn't want it to in this case.

Right. But AnyData can also return a single piece even if there are
non-unique keys -- either the first price matching in your example, or
(with the addition of a minimum price checker), the lowest price in my
example.

> I was counting on the prices being unique.  If I go to a store to buy an
> item, I don't generally expect them to tell me it costs x, y, or z amount
> of money.

But if you own the store and are considering buying something, the list
of things to buy might contain x, y and z amounts of money. The OP
didn't mention if this is a price list of items he has and wants to sell
or items he's considering buying. :-)

-- 
Jeff



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

Date: Sat, 03 Nov 2001 18:58:50 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: How to store a table and retrieve items?
Message-Id: <3BE4AEEA.A1F2541D@vpservices.com>

"David K. Wall" wrote:
> 
> jeff@vpservices.com (Jeff Zucker) wrote:
> 
> > David Wall <darkon@one.net> wrote in message
> > news:<Xns914D8B7B2C6A3darkononenet@207.126.101.97>...
> >> ississauga@hotmail.com wrote on 02 Nov 2001:
> >> >
> >> > A table has prices for items having width and height,
> >
> > [snip]
> >
> >> If you use Jeff Zucker's AnyData module then you can expand the table
> >> at will and not have to worry.  Well, not much -- you do have to make
> >> sure that each combination of height category and width category is
> >> unique.
> >
> > You don't have to worry even if there are non-unique combinations.
> > See below.
> 
> Well, I didn't mean to imply that AnyData *couldn't* return more than one
> piece of data, just that I didn't want it to in this case.

Right. But AnyData can also return a single piece even if there are
non-unique keys -- either the first price matching in your example, or
(with the addition of a minimum price checker), the lowest price in my
example.

> I was counting on the prices being unique.  If I go to a store to buy an
> item, I don't generally expect them to tell me it costs x, y, or z amount
> of money.

But if you own the store and are considering buying something, the list
of things to buy might contain x, y and z amounts of money. The OP
didn't mention if this is a price list of items he/she has and wants to
sell or items he/she's considering buying. :-)

-- 
Jeff



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

Date: 4 Nov 2001 00:39:48 -0800
From: weiwe1@yeah.net (hugh1)
Subject: i do not understand it(the =~s/.../.../), thanx!
Message-Id: <7dcf30ba.0111040039.1dff16f2@posting.google.com>

i can not know how to understand it:

$name =~ s /%([\da-f][\d[a-f]/chr(hex($1))/egi

i do not know what sould first to do!!!!!
it translate  %[0-9][a-f][a-f] to charects????? but $1 point to what??
and i can find usage about chr and hex and tr/../../

$name =~ tr/+/ /;

why not use s/+/ /????

very thanx!


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

Date: Sun, 04 Nov 2001 09:27:28 GMT
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: i do not understand it(the =~s/.../.../), thanx!
Message-Id: <slrn9ua2ta.6am.tim@vegeta.ath.cx>

Me parece que hugh1 <weiwe1@yeah.net> dijo:
>  i can not know how to understand it:
>  
>  $name =~ s /%([\da-f][\d[a-f]/chr(hex($1))/egi

This code is broken.

$name =~ s/%([\da-f][\da-f])/chr(hex($1))/egi;

>  i do not know what sould first to do!!!!!
>  it translate  %[0-9][a-f][a-f] to charects????? but $1 point to what??
>  and i can find usage about chr and hex and tr/../../

perldoc -f chr
perldoc -f hex

It's a URL decoding regex, eg: 'two%20words' -> 'two words'. But you
knew that.  $1 holds what is matched by the sequence inside the parens.
eg, 'two%20words': the whole regex matches '%20' (the first time thru),
but only '20' is matched inside the parens; then, the /e switch makes
the expression in the second section replace that matched in the first.

    '%20' -> chr(hex(20)) -> chr(32) -> ' '

 ...and repeat for as many times as it finds a substring that matches the
expression on the left.

>  $name =~ tr/+/ /;
>  
>  why not use s/+/ /????

Try it.  What happens?

When simply swapping one character for another, using a 1 to 1 match or
entire maps, tr/// is _much_ more efficient than firing up the whole
regex engine just to replace a '+' with ' '.

(Another reason is, s/+/ / won't compile.  A literal '+' must be escaped
in a substitution. But you found this out when you tried it, right?)

For further information:

    perldoc perlop      # for the tr///, y///, s///, and m// operators
    perldoc perlre      # for details on perl's implementation of re's

>  very thanx!

HTH
Tim
-- 
How dare the government intervene to stifle innovation in the computer
industry! That's Microsoft's job, dammit!


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

Date: 4 Nov 2001 10:37:22 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Perl on Windows2000
Message-Id: <9s35p2$sf8$5@uranium.btinternet.com>

In comp.lang.perl.misc Joseph J. Whalen <joe.whalen@broadbeam.com> wrote:
> I am interested in running Perl on Windows 2000 in order to support perl CGI
> scripts through IIS.  I have a copy of ActivePerl installed on the system.
> In all of the FAQ's that I've seen, it is recommended to also use
> cgi2shell.exe.  I can not seem to find this utility anywhere for download.

I have never heard of it but thats by the by.

> My questions:
> 
> 1. Is there someplace this can be downloaded from?  If so, where.
> 2. Are there any other utilities I can use to replace the functionality
> cgi2shell provides?

No I don't know.

> 3. Is there another way to get perl CGI's working under IIS other than the
> path that I've taken.
> 

The ActivePerl installer should have already configure the appropriate
script mapping which will enable Perl programs to be run by the server as
a CGI program.  You should have been asked a question about this when
the installer was run.  (Assuming you installed via the MS Installer).

If you do not have appropriate script map entries you should in the first
instance read the documentation that comes with the ActivePerl distribution
which has specific intructions for configuring IIS then if you are still
not sure then you should ask in one the groups:

    comp.infosystems.www.servers.*

/J\
-- 
Jonathan Stowe                      |
<http://www.gellyfish.com>          |      This space for rent
                                    |


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

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


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