[10701] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4293 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 25 01:07:27 1998

Date: Tue, 24 Nov 98 22:00:19 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 24 Nov 1998     Volume: 8 Number: 4293

Today's topics:
    Re: Can't edit web generated files <gss2@students.eng.wayne.edu>
    Re: Can't edit web generated files (Tad McClellan)
    Re: CGI-Scripts <perlguy@technologist.com>
    Re: Debugging (Ilya Zakharevich)
    Re: how do you put commas in a number? (Matthew Bafford)
    Re: How to print a simple character on the screen ? (Ronald J Kimball)
    Re: How to sort an array of strings case insensitive ? (Matthew Bafford)
    Re: How to sort an array of strings case insensitive ? (BenJamin Prater)
    Re: MacPerl and makefiles (Rich Morin)
    Re: MacPerl and makefiles <doug@zerolimits.com>
        Microsoft Excell (Dave Jones)
    Re: Microsoft Excell <ebohlman@netcom.com>
    Re: nslookup <newspost@morlock.net>
    Re: Parse File Upload.. (Alastair)
        Perl Evaluation Order <woodings@cs.byu.edu>
    Re: Perl Evaluation Order (brian d foy)
    Re: QUICK QUESTION! (Adam Turoff)
    Re: QUICK QUESTION! (brian d foy)
        Remove non-alphabetic characters from string <dalambert@rocketmail.com>
    Re: Remove non-alphabetic characters from string <ebohlman@netcom.com>
        Simple problem for someone.... <aardvark@canada.com>
    Re: Simple problem for someone.... <ebohlman@netcom.com>
        Simple server issues. plambert$1@plambert.org
    Re: Stupid question:  Script never terminates? (Abe)
    Re: sysread / need help w/ single byte I/O, urgent!  pl (Ronald J Kimball)
        templates? (BenJamin Prater)
    Re: templates? <hrafal@rcn.com>
        What to do when printf() doesn't apply <doug@zerolimits.com>
    Re: What to do when printf() doesn't apply <ebohlman@netcom.com>
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Tue, 24 Nov 1998 22:49:33 -0500
From: shienh gurpreet <gss2@students.eng.wayne.edu>
To: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Can't edit web generated files
Message-Id: <Pine.SOL.3.95.981124224438.15669E-100000@iris>



On Tue, 24 Nov 1998, Tom Phoenix wrote:

> On Tue, 24 Nov 1998, shienh gurpreet wrote
> > I have a script th
> > permissions are -rw-r--r--. Please suggest a solution.
> 
> There are many ways to do this, but they're the same whether you program
> in Perl or in some other language. Perhaps the docs, FAQs, and newsgroups
> about CGI programming would be able to help you. But consider making your
> program run under your user-ID. Good luck!
> 
> -- 
> Tom Phoenix       Perl Training and Hacking       Esperanto
> Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/
> 
> 
As I said in my post, I'm not that familiar with the servers and stuff.
Can you please elaborate as to how I can run it under my user-ID. (It
might sound like a  stupid question but thats the truth. I don't know
about it). Thank you.



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

Date: Tue, 24 Nov 1998 23:13:25 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Can't edit web generated files
Message-Id: <ll3g37.6on.ln@flash.net>

shienh gurpreet (gss2@students.eng.wayne.edu) wrote:

: On Tue, 24 Nov 1998, Tom Phoenix wrote:

: > On Tue, 24 Nov 1998, shienh gurpreet wrote
: > > I have a script th
: > > permissions are -rw-r--r--. Please suggest a solution.
: > 
: > There are many ways to do this, but they're the same whether you program
: > in Perl or in some other language. Perhaps the docs, FAQs, and newsgroups
: > about CGI programming would be able to help you. But consider making your
: > program run under your user-ID. Good luck!


: As I said in my post, I'm not that familiar with the servers and stuff.
: Can you please elaborate as to how I can run it under my user-ID. (It
: might sound like a  stupid question but thats the truth. I don't know
: about it). Thank you.


   You can find someone to elaborate about such things in
   a newsgroup where such things are discussed, such as:

   comp.infosystems.www.authoring.cgi
   comp.infosystems.www.servers.mac
   comp.infosystems.www.servers.misc
   comp.infosystems.www.servers.ms-windows
   comp.infosystems.www.servers.unix



   This is the Perl newsgroup.

   Perl does not *have* a server.


   The WWW does have servers.

   So you should be asking in a WWW place, not a Perl place.


   Your question is off-topic for this newsgroup. 

   Please go ask in on on-topic newsgroup.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Tue, 24 Nov 1998 21:39:46 -0600
From: Brent Michalski <perlguy@technologist.com>
Subject: Re: CGI-Scripts
Message-Id: <365B7C02.D91D7272@technologist.com>

Heiko wrote:
> 
> Hi there!
> 
> I4m working on my own CGI-Scripts but I can4t find a server on which I can
> freely execute my own scripts. So, are there any servers like that
> available?
> 
> Bye bye,
>       Heiko

Heiko,

The *best* way, I think, is to set up a web server on your machine. 
Then you can program and test the programs all on the same system...

Good luck!
Brent

-- 
Java?  I've heard of it, it is what I drink while hacking Perl! -me
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$            Brent Michalski             $
$         -- Perl Evangelist --          $
$    E-Mail: perlguy@technologist.com    $
$ Resume: http://www.inlink.com/~perlguy $
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$


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

Date: 25 Nov 1998 02:29:51 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Debugging
Message-Id: <73fq2v$e0m$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Tom Phoenix 
<rootbeer@teleport.com>],
who wrote in article <Pine.GSO.4.02A.9811241648190.4375-100000@user2.teleport.com>:
> On Mon, 23 Nov 1998 joe@webolution.com wrote:
> 
> > I'm looking for a way to execute cgi Perl scripts and have each
> > executed line of code written to a text file. Any suggestions?
> 
> Hack in the debugger to make this happen.

Or, alternatively,

    perldoc perldebug

Ilya


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

Date: Tue, 24 Nov 1998 21:11:56 -0500
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: how do you put commas in a number?
Message-Id: <MPG.10c5317a1c0bbc0298973a@news.scescape.net>

In article <365B19A0.1D42EF71@egdc.net>, eric@egdc.net says...
=> THANKS!!

YOUR WELCOME!!

[snip VCARD crap]

NEVER MIND!

hint:        read perlfaq (all of it)

Since you didn't say what you were having problems with, and your subject 
line (while almost good) doesn't really explain your problem, I'm going 
to take a stab at it.

#!/usr/bin/perl -w
# Put commas in a number.
use strict;

$_ = '30927498436795864029476936925345';

s{(\d)(\d)}{
    ( int(rand(2)) == 1) ?
        "$1,$2"          :
        "$1$2"
}ge;

print "$_\n";

__END__

Hope This Help(s|ed)!

--Matthew


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

Date: Tue, 24 Nov 1998 23:55:47 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: How to print a simple character on the screen ?
Message-Id: <1dj0uw4.1wcphsq1o30s5cN@bos-ip-1-61.ziplink.net>

Larry Rosler <lr@hpl.hp.com> wrote:

> Ronald J Kimball <rjk@coos.dartmouth.edu> says...
> > Larry Rosler <lr@hpl.hp.com> wrote:
> > 
> > > It is not valid Perl with 'use strict;' (ergo, IMO, it is not valid Perl

> > > [...]

> > Your logic stinks.  The validity of a Perl program is not defined by
> > 'use strict;'.
> 
> Let's not get into a flame war about this.  I was being deliberately 
> extremist and you have helped to clarify the narrower point.

Then I guess I was too.  ;-P

> OTOH, note that each of your examples (one of which I snipped) deals 
> with 'use strict q(vars);' which is a different problem entirely.

Okay.  But you didn't say 'use strict q(refs);', you said 'use strict;'.
So I was responding to your post as you wrote it, not as you meant it.
:-)


-- 
 _ / '  _      /         - aka -          rjk@linguist.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Tue, 24 Nov 1998 20:57:48 -0500
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: How to sort an array of strings case insensitive ?
Message-Id: <MPG.10c52e2ba962075c989739@news.scescape.net>

In article <73fjsa$iv2$1@nnrp1.dejanews.com>, thst@my-dejanews.com 
says...
=> As the subject says: How to do that in perl ?
=> If I sort the normal way then capital letters are coming before lower letters.

Hmm, let's see...

First, search for sort.  Then, search for lowercase.

But, you luck out:

#!/usr/bin/perl -w
use strict; # always (unless otherwise)

my @to_sort  = qw(z y x w v u t s r q p o n m l k j i h g f e d c b a A B
C E F D G H I J K Z Y X W V U T S R Q P O N M L);

my @reg_sort = sort {    $a  cmp    $b  } @to_sort;
my @ci1_sort = sort { lc($a) cmp lc($b) } @to_sort;
my @ci2_sort = sort { uc($a) cmp uc($b) } @to_sort;

print "\@reg_sort = [@reg_sort]\n";
print "\@ci1_sort = [@ci1_sort]\n";
print "\@ci2_sort = [@ci2_sort]\n";

__END__

=> Bye Thomas

Hope This Helps!

--Matthew


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

Date: 24 Nov 1998 20:51:03 -0600
From: ben@sofnet.com (BenJamin Prater)
Subject: Re: How to sort an array of strings case insensitive ?
Message-Id: <365b6f00.9549263@news.sofnet.com>

Thomas,

Make the strings lowercase prior to sorting or as your sort...

for (sort { lc $hash{$a} cmp lc $hash{$b} } keys %hash) { ... }

BenJamin Prater


On Wed, 25 Nov 1998 00:43:59 GMT, thst@my-dejanews.com wrote:

>As the subject says: How to do that in perl ?
>If I sort the normal way then capital letters are coming before lower letters.
>
>Bye Thomas
>
>-----------== Posted via Deja News, The Discussion Network ==----------
>http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    



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

Date: Tue, 24 Nov 1998 18:27:05 -0800
From: rdm@cfcl.com (Rich Morin)
Subject: Re: MacPerl and makefiles
Message-Id: <rdm-2411981827210001@140.174.42.30>

In article <1diz2it.111w3tz1vrvgj0N@roxboro0-044.dyn.interpath.net>,
phenix@interpath.com (John Moreno) wrote:

> I'd suggest asking this in alt.comp.lang.applescript (despite the name
> MacPerl questions are welcomed).

Alternatively, for MacPerl-related questions, try the MacPerl email list
(available via the MacPerl Pages: http://www.ptf.com/macperl).

-r

-- 
Canta Forda Computer Laboratory       | Prime Time Freeware - quality 
UNIX consulting, training, & writing  | freeware at affordable prices
+1 650-873-7841                       | +1 408-433-9662   -0727 (Fax)
Rich Morin, rdm@cfcl.com              | www.ptf.com, info@ptf.com


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

Date: Tue, 24 Nov 1998 19:15:31 -0800
From: doug <doug@zerolimits.com>
To: dejahvu@erols.com
Subject: Re: MacPerl and makefiles
Message-Id: <365B7653.523BA39@zerolimits.com>

I'm not familiar with this module, but one thing you
might try is, if the webmaster/sysadmin will allow
you access, use telnet (free terminal program) and write it and test it on
the Unix machine from home.

Mary E Tyler wrote:
> 
> Ak...
> 
> I tremble to ask but here I go again!
> 
> I am writing Perl code on my Mac and do most of my preliminary testing
> there. I downloaded a module from CPAN and it has this makefile.pl which
> crashes MacPerl. Someone tells me that MacPerl doesn't have that
> capability... S'okay.... so how do I use the wonderful module?
> 
> Now let's make it more difficult. My target system is Unix... it's a CGI
> script for my web site. What do I do with that module to make it work in
> both places. If it makes any difference, I am with a web host and have
> no control of the server environment etc.
> 
> Thank you in advance for any help.
> 
> Dejah
> --
> i trust i make myself obscure, i have need of obscurity now- robert bolt
> 
> a heated exchange of unread mail would be welcomed by all- christensen
> 
> Skating Fiction. Featuring the  highly acclaimed serial On The Edge!
> http://www.DejahsPrivateIce.com


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

Date: Wed, 25 Nov 1998 03:03:03 GMT
From: me.you@bigfoot.com (Dave Jones)
Subject: Microsoft Excell
Message-Id: <365b6870.1849646@nntp.clds.net>

I'm asking this in case I overlooked it, is there a Perl module that
lets you gain access to a Microsoft Excess Worksheets, particularly
the contents of individual cells. Returning the row/column/sheet
number/formula could be usefull as well so getting that information is
needed..

Thanks for any suggestions/help..




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

Date: Wed, 25 Nov 1998 05:25:56 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Microsoft Excell
Message-Id: <ebohlmanF2ypr8.9Dx@netcom.com>

Dave Jones <me.you@bigfoot.com> wrote:
: I'm asking this in case I overlooked it, is there a Perl module that
: lets you gain access to a Microsoft Excess Worksheets, particularly
: the contents of individual cells. Returning the row/column/sheet
: number/formula could be usefull as well so getting that information is
: needed..

If you can have a copy of Excel running on the same machine as the 
module, then you can use Win32::OLE to get the information.  If not, go 
over to CPAN and see if there's another module that might help you.



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

Date: Tue, 24 Nov 1998 21:26:27 -0500
From: "Steven Morlock" <newspost@morlock.net>
Subject: Re: nslookup
Message-Id: <IXJ62.281$6d6.544318@lwnws01.ne.mediaone.net>


The read from STDIN includes the line terminator.  You should chomp the string.
The variable 'address' should be a scalar, not an array.

$name = <STDIN>;
chomp $name;

$address = inet_ntoa(inet_aton ($name)) or die "couldn't resolve for $name:$!\ n";
print "The address is a IP address: $address\n";

Steve

nguyen.van@imvi.bls.com wrote in message <73flqj$kjg$1@nnrp1.dejanews.com>...
>Hi everyone,
>
>I tried to write a script like a "nslookup" in unix but face a problem.
>Following is my code.
>
>__________________________________________________________________
>
>use Socket;
>print "please enter Domain name:\n";
>
>$name = <STDIN>;
>
>@address = inet_ntoa(inet_aton ($name)) or die "couldn't resolve for $name:
>$!\ n"; print "The address is a IP address: $address\n";
>
>exit;
>
>_____________________________________________________________________
>
>I ran the script as "./nslookup.pl www.cnn.com" and got the followinf error:
>
>________________________________________________________________________ Bad
>arg length for Socket::inet_ntoa, length is 0, should be 4 at ./nslookup.pl
>___________________________________________________________________________
>
>
>Thanks
>Van Nguyen
>
>-----------== Posted via Deja News, The Discussion Network ==----------
>http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own




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

Date: Wed, 25 Nov 1998 02:35:12 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: Parse File Upload..
Message-Id: <slrn75mr5t.gm.alastair@calliope.demon.co.uk>

Mick <bellears@deakin.edu.au> wrote:
>So...If I have something like...
><input name=bulkfilename2 size=25 maxlength=100 type=file accept=\"*\">
>Do I then parse bulkfilename2 using eq or something like that?

Your life will be _much_ easier if you use the CGI.pm module. Spend a couple of
days reading the docs and trying some programs. The docs are good. It deals with
file uploads and parsing form parameters very well.

http://www.genome.wi.mit.edu/~lstein/

HTH.

-- 

Alastair
work  : alastair@psoft.co.uk
home  : alastair@calliope.demon.co.uk


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

Date: Tue, 24 Nov 1998 20:40:32 -0700
From: Ryan Winfield Woodings <woodings@cs.byu.edu>
Subject: Perl Evaluation Order
Message-Id: <365B7C30.345CD82E@cs.byu.edu>

I am doing a research paper for my Programming Languages class on Perl
and need to know if it uses normal order evaluation or applicative
order, but I haven't been able to find this info anywhere.  Also, in
what situations does it use special forms.  If anyone knows this
information off the top of their head, I could really use some help.

Ryan Woodings
woodings@cs.byu.edu



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

Date: Wed, 25 Nov 1998 00:43:40 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Perl Evaluation Order
Message-Id: <comdog-ya02408000R2511980043400001@news.panix.com>

In article <365B7C30.345CD82E@cs.byu.edu>, Ryan Winfield Woodings <woodings@cs.byu.edu> posted:

> I am doing a research paper for my Programming Languages class on Perl
> and need to know if it uses normal order evaluation or applicative
> order, but I haven't been able to find this info anywhere.

why not try a few test cases and find out?  that's what the 
"research" part means :)

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: 24 Nov 1998 21:27:35 -0500
From: ziggy@panix.com (Adam Turoff)
Subject: Re: QUICK QUESTION!
Message-Id: <73fpun$k7a@panix.com>

brian d foy <comdog@computerdog.com> wrote:
>In article <365B513A.FEDB9B73@axe.humboldt.edu>, Greg Coit <gbc1@axe.humboldt.edu> posted:
>
>> Eric Gessner wrote:
>> 
>> > i am importing a key/value array from an HTML form.  the values are
>> > numbers, and my question is, how do i add them together to come up with
>> > a total?
> 
>> Using the code you supplied, I think this will work:
>> 
>> foreach $number(keys(%input)) {
>> $total += $input{$numbers};
>> }
>
>you could also use the values() function (TMTOWTDI):
>
>   %hash = map { $_, $_ + int(rand(5)) } 1 .. 100;
>   
>   @values = values(%hash);
>   
>   foreach( @values )
>      {
>      $sum += $_;
>      }
>      
>   print "$sum\n";


That foreach is pretty verbose...

%hash = map { $_, $_ + int(rand(5)) } 1 .. 100;
map {$sum += $_} values(%hash);
print "$sum\n";

Z.



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

Date: Wed, 25 Nov 1998 00:35:36 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: QUICK QUESTION!
Message-Id: <comdog-ya02408000R2511980035360001@news.panix.com>

In article <73fpun$k7a@panix.com>, ziggy@panix.com (Adam Turoff) posted:

> brian d foy <comdog@computerdog.com> wrote:

> >      {
> >      $sum += $_;
> >      }

> That foreach is pretty verbose...

> %hash = map { $_, $_ + int(rand(5)) } 1 .. 100;
> map {$sum += $_} values(%hash);
> print "$sum\n";

yeah, but that map is in a void context, and if you look in this
quarter's Perl Journal you'll see that foreach is faster :)

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Tue, 24 Nov 1998 22:35:33 -0600
From: "David Lambert" <dalambert@rocketmail.com>
Subject: Remove non-alphabetic characters from string
Message-Id: <73g1c1$s1f$1@mailaid>

My script gets last names as it's input, and I would like to remove any
non-alphabetic characters from the string, including spaces, punctuation,
and numerals, and output whether any changes were needed.

For example, if the input is:
O'Conner
de la Rosa
Lambert
Doodl3r

I would like the output to be:
"O'Conner" changed to "OConner"
"de la Rosa" changed to "delaRosa"
"Lambert" OK
"Doodl3r" changed to "Doodlr"

Could anyone suggest the best way to do this?

Thanks much,
David Lambert





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

Date: Wed, 25 Nov 1998 05:30:44 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Remove non-alphabetic characters from string
Message-Id: <ebohlmanF2ypz8.9q7@netcom.com>

David Lambert <dalambert@rocketmail.com> wrote:
: My script gets last names as it's input, and I would like to remove any
: non-alphabetic characters from the string, including spaces, punctuation,
: and numerals, and output whether any changes were needed.
[snip]
: Could anyone suggest the best way to do this?

tr is your friend (and it's almost certain to be faster than any
regexp-based solution). 



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

Date: Wed, 25 Nov 1998 05:04:24 GMT
From: richard <aardvark@canada.com>
Subject: Simple problem for someone....
Message-Id: <365CE259.6D37A63B@canada.com>

Hi,
I am trying to write a little prog. that reads in a string, and its
associated value as in the following :  green apple yellow pear purple
plum.
I then want to print out the string and its mapping, and let the user
know if the string isn't in the hash.  I also want to continue to prompt
for input until the user hits ctrl z or "quit".
This is what I have so far.  Can anyone help?
#!/usr/bin/perl
%list = qw (
    green apple
    yellow pear
    purple plum
);
print "Enter your string ^d or quit to exit:";
$string = (<STDIN>);
chomp ($string);
while ($string ne "quit")
{
   print "The value for $string is $list{$string}\n";
}
if ($string eq "")
{
   print "No value found, try again";
}

Thanks



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

Date: Wed, 25 Nov 1998 05:35:50 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Simple problem for someone....
Message-Id: <ebohlmanF2yq7q.A1E@netcom.com>

richard <aardvark@canada.com> wrote:
: I then want to print out the string and its mapping, and let the user
: know if the string isn't in the hash.  I also want to continue to prompt
: for input until the user hits ctrl z or "quit".

: This is what I have so far.  Can anyone help?
: #!/usr/bin/perl

Can you guess what's missing on the end of that line?  Would you believe 
a -w?  Would you believe how much time you can waste in debugging if you 
don't put a -w there?

: %list = qw (
:     green apple
:     yellow pear
:     purple plum
: );
: print "Enter your string ^d or quit to exit:";
: $string = (<STDIN>);
: chomp ($string);
: while ($string ne "quit")
: {
:    print "The value for $string is $list{$string}\n";
: }
: if ($string eq "")
: {
:    print "No value found, try again";
: }

That's not the right way to tell if there was no hash item corresponding 
to the input.  Go to your docs (perlfunc, specifically) and take a look 
at the exists() function.

Once you've got that working, go back to your docs (perlsyn, 
specifically) and look at the various ways to write loops.  You should 
pay special attention to the while, next and last statements.



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

Date: 25 Nov 1998 03:39:43 GMT
From: plambert$1@plambert.org
Subject: Simple server issues.
Message-Id: <365b7bff$0$12758@nntp1.ba.best.com>

I've written a server in perl for a production (but not terribly
mission-critical) function.  It works beautifully, except for an 
occasional gonk.

Specifically, a client will often send multiple lines to the server.
The first line will be acted on, but the rest ignored until the client
waits a few moments and then passes another line to the server.  Then,
all the lines that were ignored are acted upon.

Seems to me like they're getting stuck in a buffer.

The server uses a single process and select() to do the dirty work.
The outline is directly from the advanced perl book:

use IO::Select;

while(1) {
   ($nr) = IO::Select->select($readable_handles, undef, undef, undef);
   foreach $sock (@$nr) {
      if ($sock == $mainsock) {
         # accept a new connection
      } else {
         $buf = <$sock>;
         if ($buf) {
            #act on the buffer
         } else {
            #close socket
         }
      }
   }
}

This symptom only appears when the server is busy.  It seems as though 
the foreach is getting to the affected socket, and one line is read from
$sock, and the rest are left in a buffer.  The next select call ignores
this data already waiting, and so it isn't acted on again until such
time as the client sends more data.  This triggers the select on that
socket, and it is read.  However, for some reason, it reads _all_
the queued data.

I need to have a single-threaded server in order to easily share data
between clients.  Otherwise I'd just fork, since there are few enough
clients it wouldn't hurt the server.  ;-)

Any ideas?  perl is 5.004_04.  

--Paul L.

-- 
And how do you know what you need to know?  Life has certain,
shall we say, boundary problems....  -- Todd Michel McComb



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

Date: Wed, 25 Nov 1998 04:41:54 GMT
From: abe@abe.com (Abe)
Subject: Re: Stupid question:  Script never terminates?
Message-Id: <mUL62.1794$D24.2596515@news1.atl>

In article <73eqe9$gvk$1@news.cyberhighway.net>, eln@cyberhighway.net (Erik) wrote:
>In article <sfr62.1550$oa2.2059507@news3.atl>,
>        abe@abe.com (Abe) writes:
>> I wrote a new script, and my server admin tells me it's been running for 
>> 4 hours straight because it doesn't terminate correctly.  I know it's a 
>> stupid question, but what kind of things would cause the script to not 
>> terminate?
>
>Any number of things...posting some code would probably help if you want
>a more specific answer.

The script is over 100K in length.  The server's CGI tech guy was able 
to narrow it down to an infinite loop in this section of code:

sub GetSpecs
{
  $GotSpecs = 1;
  open (SPECS, "<$dir/specs.txt") || &error_notfound;
  $lockerror = &LockFile(SPECS);
        if ($lockerror) {
                close (SPECS);
                &Header("Options Not Changed",$MessageHeaderFile);
                print "<P ALIGN=CENTER>The script was unable to access 
";
                print "the options file.</P>\n";
                &Footer($MessageFooterFile,"return");
        }
      @Spec = <SPECS>;
      &UnlockFile(SPECS);
        close (SPECS);
      foreach $line(@Spec){ @Specs = split(/\|/,$line);
      
      $Font1Type = $Specs[0];
      $Font1 = $Specs[1];
$Font2Type = $Specs[2];
$Font2 = $Specs[3];
$bodyspec = $Specs[4];
$BoardAdminDisplayName = &ReWebify($Specs[5]);
$BoardAdminPassword = $Specs[6];
$ABPassword = $Specs[6];
$BoardAdminEmail = $Specs[7];
$SubAdminPass1 = $Specs[8];
$SubAdminName1 = &ReWebify($Specs[9]);
$SubAdminDelete1 = $Specs[10];
$SubAdminPass2 = $Specs[11];
$SubAdminName2 = &ReWebify($Specs[12]);
$SubAdminDelete2 = $Specs[13];
$SubAdminPass3 = $Specs[14];
$SubAdminName3 = &ReWebify($Specs[15]);
$SubAdminDelete3 = $Specs[16];
$BoardDisplayName = $Specs[17];
$PasswordProtected = $Specs[18];
$BoardPassword = $Specs[19];
$Max_Messages = $Specs[20];
$BoardHTML = &ReWebify2($Specs[21]);
$IPShow = $Specs[22];
$SubAdminEmail1 = $Specs[23];
$SubAdminEmail2 = $Specs[24];
$SubAdminEmail3 = $Specs[25];
$SearchEngine = $Specs[26];
$Keywords = $Specs[27];
$BanList = $Specs[28];
$FontMessage1 = $Specs[29];
$FontMessage2 = $Specs[30];

}
}

"specs.txt" is a one line text database file that was created by another 
script.  From what I can tell, the script reads the database file 
correctly because it sets the variables properly and continues running.  
>From what my server admin and the CGI guy are saying, this subroutine 
never terminates, but the script prints out all the necessary output.  
I'm guessing that the problem might be that the file is only one line 
long and I'm using a "foreach" statement, but how else could I read in a 
one line database file and still parse it like this?  I'm stumped.


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

Date: Tue, 24 Nov 1998 23:55:49 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: sysread / need help w/ single byte I/O, urgent!  please!
Message-Id: <1dj0vit.16sjqjwldijngN@bos-ip-1-61.ziplink.net>

Tom Phoenix <rootbeer@teleport.com> wrote:

> On 23 Nov 1998, Ralph Forsythe wrote:
> 
> > I need to read the bytes one-at-a-time and do ord() conversions on
> > them - but when I try this it just hangs the program.
> 
> What hangs? Reading bytes, doing ord, something else?
> 
> >    MSB$ = INPUT$ (1, #1)
> >    LSB$ = INPUT$ (1, #1)
> >    reading1 = (ASC(MSB$)*256) + ASC(LSB$)
> 
> Maybe you should write this in Perl. I don't know what language this is,
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

You snipped too much...  From earlier in the post:

> > Here is the Basic code sample they sent with it:
                ^^^^^^^^^^^^^^^^^

I must admit, I did a double take when I saw that code, but reread the
post and found the explanation.

> and I don't know what it's supposed to do. But maybe you want the read()
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

It's supposed to read the bytes one-at-a-time and do ord() conversions
on them, as he said.  :-)

> function, or getc(), documented in perlfunc. Hope this helps!

Rewriting this in Perl is exactly what Ralph wants to do.  But what he
came up with didn't work.  Hopefully he'll post the Perl code he wrote,
and we can find the problem.  :-)

-- 
 _ / '  _      /         - aka -          rjk@linguist.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: 24 Nov 1998 20:52:04 -0600
From: ben@sofnet.com (BenJamin Prater)
Subject: templates?
Message-Id: <365b6fcc.9753558@news.sofnet.com>

I'm looking for a module that will take this:

$aq = Module->new( foo => \&foo,
		bar => \&bar);

$aq->parse($buf);

when $buf looks like:

<foo item="2">Que esta fubara<bar state="5" color="white">Ciesta la
vie</bar></foo>

And call the respective subs in the current package with any
additional info from the tags dumped along with it.

Is XML::Parser what I'm looking for, or is there something better
suited for this parsing job?

Ben Prater


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

Date: Tue, 24 Nov 1998 22:48:56 -0500
From: Howard Rafal <hrafal@rcn.com>
Subject: Re: templates?
Message-Id: <365B7E1E.331F6918@rcn.com>

Hi,

It's not the same syntax that you use, but I really like the
Text::Template package (you can get it at <http://www.cpan.org>) It
allows you to set up a package for use inside the template and then you
can make calls and use variables and even write Perl code within your
template. Your template would look something like this:

<{foo()} item="2">Que esta fubara<{bar()} state="{$state}"
color="white">Ciesta la
vie</bar></{foo()}>

To set this up you would do:

package Example;

sub foo() { ... }

sub bar() { ... }

sub DoTemplate
{
  $EXAMPLE::state = 5;  # an example of a piece of data passed in above
  $temp = new Text::Template('type' => 'FILE', 'source' =>
'bar.tmpl');   # You could use a string
  return $temp->fill_in('package' => Example);
}


BenJamin Prater wrote:

> I'm looking for a module that will take this:
>
> $aq = Module->new( foo => \&foo,
>                 bar => \&bar);
>
> $aq->parse($buf);
>
> when $buf looks like:
>
> <foo item="2">Que esta fubara<bar state="5" color="white">Ciesta la
> vie</bar></foo>
>
> And call the respective subs in the current package with any
> additional info from the tags dumped along with it.
>
> Is XML::Parser what I'm looking for, or is there something better
> suited for this parsing job?
>
> Ben Prater



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

Date: Tue, 24 Nov 1998 19:30:22 -0800
From: doug <doug@zerolimits.com>
Subject: What to do when printf() doesn't apply
Message-Id: <365B79CE.CDFA49E9@zerolimits.com>

I'm writing a form input page in Perl, and I
have the products-prices as key value pairs in a hash.
I print these out with all the rest of the page
in a series of print <<"EOF" statements. The problem
I'm having is that 25.00 gets printed as 25
and 25.50 gets printed as 25.5
The way it's done would make it very difficult to use printf.
Is there some other way to tell perl not to truncate
trailing zeros?
Thanks,
Doug at zerolimits.com
-- 
**********Spam Stopper*************
root@localhost.com
abuse@localhost.com


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

Date: Wed, 25 Nov 1998 05:27:57 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: What to do when printf() doesn't apply
Message-Id: <ebohlmanF2ypuL.9HB@netcom.com>

doug <doug@zerolimits.com> wrote:
: I'm writing a form input page in Perl, and I
: have the products-prices as key value pairs in a hash.
: I print these out with all the rest of the page
: in a series of print <<"EOF" statements. The problem
: I'm having is that 25.00 gets printed as 25
: and 25.50 gets printed as 25.5
: The way it's done would make it very difficult to use printf.
: Is there some other way to tell perl not to truncate
: trailing zeros?

I'd preprocess all the prices, using sprintf(), to make sure they're 
stored as strings rather than numbers, and then use the here-doc to print 
them.



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

Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 4293
**************************************

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