[9461] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3053 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 3 16:17:04 1998

Date: Fri, 3 Jul 98 13:09:38 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 3 Jul 1998     Volume: 8 Number: 3053

Today's topics:
    Re: Scope mangling (Mark-Jason Dominus)
    Re: setting directory permissions... <qdtcall@esb.ericsson.se>
        Silly things to do in Perl (or: is that Laptop waterpro <quednauf@nortel.co.uk>
        slurping when it's not supposed to? <schultz@cray.com>
    Re: slurping when it's not supposed to? <bowlin@sirius.com>
    Re: So, what's wrong with JAVA? <jc_cann@ix.netcom.com>
    Re: Sorting Database Entries (John Hocking)
    Re: Sorting Database Entries (John Hocking)
        SWAP and memory problem. (Ariel Kornberg)
    Re: SWAP and memory problem. <simonf@conduit.co.uk>
    Re: SWAP and memory problem. <quednauf@nortel.co.uk>
    Re: system() and security again (Marc Haber)
    Re: system() and security again <rra@stanford.edu>
    Re: system() and security again (Marc Haber)
        Text/plain --> URL/Encoded magweb@my-dejanews.com
    Re: Text/plain --> URL/Encoded (brian d foy)
    Re: Text/plain --> URL/Encoded (Josh Kortbein)
        The vagaries of read()ing (John Siracusa)
        threads, perl5.004_68, and perlTk <mcariaso@genelogic.com>
    Re: threads, perl5.004_68, and perlTk (Andrew Allen)
        tie and NDBM_File <norman@dcs.st-and.ac.uk>
    Re: time out for IO::Socket::accept() <jay@rgrs.com>
    Re: Timeouts on receiving from a socket <cyboon@sns.com.sg>
    Re: TIP: How to post good questions <indy@NOSPAMdemobuilder.com>
    Re: TIP: How to post good questions (Bob Trieger)
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 2 Jul 1998 20:54:02 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Scope mangling
Message-Id: <6nha3a$cuo$1@monet.op.net>
Keywords: criterion exploitation hardbake meander


In article <6ngmor$2uq$1@zarathustra.calstatela.edu>,
Graffiti  <ramune@zarathustra.remove.this.spam.block.calstatela.edu> wrote:
>	Is it possible to change the scope of a variable in a
>manner such as this?
>
>sub a {
>my($foo);
>	do_stuff;
>	&b();
>	change_my_to_local($foo);
>	&c();
>	change_local_to_my($foo);
>}

Answer 0: Gosh, this smells like a premature closure if there ever was
          one.  What on earth are you *really* trying to accomplish?

Answer 1: No.

Answer 2:

sub a {
  my $foo;
  do_stuff;
  b();
  {
    local $foo;
    c();
  }
  ...
}




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

Date: 02 Jul 1998 10:25:18 +0200
From: Calle Dybedahl <qdtcall@esb.ericsson.se>
Subject: Re: setting directory permissions...
Message-Id: <islnqcek29.fsf@godzilla.kiere.ericsson.se>

"Ric Alcazar" <alcazar@netcomp.net> writes:

> sometimes I try to set $permissions = '0700', but that doesn't seem
> to work... instead... I get a different permissions assigned... can
> anyone help?

Say "man umask" to a shell prompt near you.
-- 
		    Calle Dybedahl, UNIX Sysadmin
       qdtcall@esavionics.se  http://www.lysator.liu.se/~calle/


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

Date: Fri, 03 Jul 1998 11:36:16 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Silly things to do in Perl (or: is that Laptop waterproof?)
Message-Id: <359CB420.962213D@nortel.co.uk>

$marker = shift;
$what = $marker eq "morse" ? "morse_to_alphabet" : "alphabet_to_morse"; 

$morse{a} = ".-";  $morse{q} = "--.-";$morse{6} = "--...";
$morse{b} = "-...";$morse{r} = ".-."; $morse{7} = "---..";
$morse{c} = "-.-.";$morse{s} = "..."; $morse{8} = "----.";
$morse{d} = "-.."; $morse{t} = "-";   $morse{9} = "----.";
$morse{e} = ".";   $morse{u} = "..-"; $morse{' '} = "*";
$morse{f} = "..-.";$morse{v} = "...-";
$morse{g} = "--."; $morse{w} = ".--";
$morse{h} = "....";$morse{x} = "-..-";
$morse{i} = "..";  $morse{y} = "-.--";
$morse{j} = ".---";$morse{z} = "--..";
$morse{k} = "-.-"; $morse{0} = "-----";
$morse{l} = ".-..";$morse{1} = ".----";
$morse{m} = "--";  $morse{2} = "..---";
$morse{n} = "-.";  $morse{3} = "....-";
$morse{o} = "---"; $morse{4} = ".....";
$morse{p} = ".--.";$morse{5} = "-....";

open FILE, "< /somefile.txt" or die "Can't: $!";

&$what;

close FILE;

sub alphabet_to_morse {
  while (<FILE>) { 
    s/(.?)/$morse{$1} /g;
    print $_;
  }   
  print "\n --- End of message ---\n";
}

sub morse_to_alphabet {
  %alphabet = reverse %morse; 
  while (<FILE>) {
    s/(.+?)\s/$alphabet{$1}/g;
    print "$_\n";
  }
  print "\n --- End of message ---\n";
}

You can see which characters are recognised. The morse to alphabet regexp isn't
quite clean, but works!
use 'script.pl' to translate alphabet to morse, and 'script.pl morse' to do the
other thing. 
Enjoy your holiday at sea! (I know, it's Friday, madness is slowly gripping
me...)

-- 
____________________________________________________________
Frank Quednau               
http://www.surrey.ac.uk/~me51fq
________________________________________________


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

Date: Thu, 2 Jul 1998 20:07:22 -0500
From: Randy Schultz <schultz@cray.com>
Subject: slurping when it's not supposed to?
Message-Id: <Pine.SGI.3.96.980702192331.1813A-100000@tdream>

I've got a small program running on an SGI Indy with 32 MB ram.  Perl -v shows

     This is perl, version 5.004_04 built for IP25-irix

I'm cranking through a 26MB/400K line file one line at a time(see code below).
The problem I'm running into is it appears perl is slurping up the file even
though I only read 1 line at a time, maybe or maybe not use some of the data
out of the line, then read the next line.  When the program run, with nothing
else going on with the system, I watch the free memory drop to nothing and 
the system starts paging like crazy.  When I run it on a system with 64 MB,
again with nothing else going on, I watch the free memory drop 30MB in about
a minute, all of it coming back when the program exits.

If I understand what I found digging around on dejanews perl doesn't free any
memory until it exits.  My question then is why does it grab(or appear to grab)
more memory for every line read?  Why doesn't it re-use memory for $_? 

If it helps, here's the section of code soaking up all the memory:
while (<BG>)
{
   chomp;
   ($mo, $da, $ti, $pro, $slog, $id, $rc, $act, $rest) = split /\s+/, $_, 9;

   if ($rc == 999)
   {
      $bh{$id}{$nine}++;               # this q-id got a 999 code
   }

   elsif (($rc == 220) && ($act =~ /\[Connect\]/o))
   {
      $bh{$id}{$c220}{$rest}++;
   }

   elsif (($rc == 250) && ($act =~ /helo/io))
   {
      $bh{$id}{$h250}{$rest}++;
   }

   elsif (($rc == 250) && ($act =~ /rcpt/io))
   {
      $rest =~ s/^to://i;          # strip out leading To:, case insensitive
      $rest =~ s/\<|\>//gi;        # strip out all "<" and ">"
      $bh{$id}{$t250}{$rest}++;
   }
}

close BG;


--
Randy    (schultz@cray.com)  715-726-2832          <*>

Experience may be the best teacher but sometimes it would be good to know
the tuition up front.



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

Date: Thu, 02 Jul 1998 23:28:36 -0700
From: Jim Bowlin <bowlin@sirius.com>
To: Randy Schultz <schultz@cray.com>
Subject: Re: slurping when it's not supposed to?
Message-Id: <359C7A14.291560F1@sirius.com>

Randy Schultz wrote:
> 
> I've got a small program running on an SGI Indy with 32 MB ram.  Perl -v shows
> 
>      This is perl, version 5.004_04 built for IP25-irix
> 
> I'm cranking through a 26MB/400K line file one line at a time(see code below).
> The problem I'm running into is it appears perl is slurping up the file even
> though I only read 1 line at a time, maybe or maybe not use some of the data
> out of the line, then read the next line.  When the program run, with nothing
> else going on with the system, I watch the free memory drop to nothing and
> the system starts paging like crazy.  When I run it on a system with 64 MB,
> again with nothing else going on, I watch the free memory drop 30MB in about
> a minute, all of it coming back when the program exits.
> 
> If I understand what I found digging around on dejanews perl doesn't free any
> memory until it exits.  My question then is why does it grab(or appear to grab)
> more memory for every line read?  Why doesn't it re-use memory for $_?
> 
> If it helps, here's the section of code soaking up all the memory:
> while (<BG>)
> {
>    chomp;
>    ($mo, $da, $ti, $pro, $slog, $id, $rc, $act, $rest) = split /\s+/, $_, 9;
> 
>    if ($rc == 999)
>    {
>       $bh{$id}{$nine}++;               # this q-id got a 999 code
>    }
> 
>    elsif (($rc == 220) && ($act =~ /\[Connect\]/o))
>    {
>       $bh{$id}{$c220}{$rest}++;
>    }
> 
>    elsif (($rc == 250) && ($act =~ /helo/io))
>    {
>       $bh{$id}{$h250}{$rest}++;
>    }
> 
>    elsif (($rc == 250) && ($act =~ /rcpt/io))
>    {
>       $rest =~ s/^to://i;          # strip out leading To:, case insensitive
>       $rest =~ s/\<|\>//gi;        # strip out all "<" and ">"
>       $bh{$id}{$t250}{$rest}++;
>    }
> }
> 
> close BG;

The amount of memory used by this program will depend on the contents of
the file you are reading.  It's not $_ thats slurping up the memory,
it is the %bh hash that you are creating.  Unless there is a lot of
redundency in the file you are reading, %bh could end up using more
memory than the entire file. For example, if your program just said

while (<BG>) {
    $bh{$_}++;
}

The %bh hash will consume more memory than the entire file being
read unless there are a lot of repeated lines.

HTH -- Jim Bowlin


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

Date: Fri, 03 Jul 1998 09:56:33 -0600
From: Jeffery Cann <jc_cann@ix.netcom.com>
Subject: Re: So, what's wrong with JAVA?
Message-Id: <359CFF31.A1D87CD8@ix.netcom.com>

k y n n wrote:
> 
> I've been muddling along with C and Perl for years, but now I find
> myself under a strong and mysterious pressure to LEARN JAVA.  Perhaps
> this weird sense of being under pressure comes from seeing how books
> on Java are slowly taking over my local bookstore (I managed to resist
> when C++ books started displacing C books in said bookstore, but that
> was just limited to C stuff; Java books are overrunning everything
> these days).  Or perhaps it comes from the recent frontpage NYT
> article to the effect that nowadays merely announcing one knows Java
> sets off a stampede of people intent on giving one all their money...
> 
> So, I ask myself, is this all just hype du jour?  Is it really worth
> it to jump on this bandwagon?

Kynn-
I saw this same message in comp.lang.c the other day.  I find the responses so more harsh
in that newsgroup compared to here.  Just an observation.  After reading c.l.c for about a
year, I think that _some_ of the posters (a small minority) seem to want to use C for
everything, think structured programming is the only rational way to solve problems (as
opposed to object-oriented design).  To me this indicates a lack of understanding of what
the Java language is intended to do.

For example, a dear friend of mine (15 year programmer, now owner of own company) wrote in
C for years, mostly in the client-server environment.  His new company writes
client-server (point-of-sale) solutions.  They use java on both the client and server.

Recently, I asked how it was going with Java development (he has been working with the
language for over a year).  He said 'it's still client-server' but it's so much easier to
get things done.'  Meaning the the class libraries enable him to not worry about the
details of protocols and transport across the network layer. 

My point is that there is not one language that can 'do everything' (although I think perl
comes as close as anything for an interpreted language).  The goal of the programmer is to
use the language that solves your particular problem most easily.  :-0

Jeff
-- 
+--------------------------+-------------------------+
| Jeffery Cann             | This message sent from  | 
| JCDS Managing Developer  | a Linux Workstation     | 
+--------------------------+-------------------------+
http://www.netcom.com/~jcds


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

Date: Fri, 03 Jul 1998 04:42:46 GMT
From: joker@inlink.com (John Hocking)
Subject: Re: Sorting Database Entries
Message-Id: <359d5be6.45082677@news.inlink.com>

On Wed, 01 Jul 1998 22:27:14 GMT, sdreyer@writeme.com wrote:

>Hi.
>
>I4m running a flat-file ASCII-Database with a "|"-Delimiter.
>Here4s an example from the file:
>---
>04|July|98|Bndname|ID|Location|21|City
>---
>
>Now, I4d like to sort the results by date, which will be put out of the
>Perl-Script after a keyword-search.
>(First by year, then by month, then by day.)
>
>I4m messing up with the "Sort"-function, but I get no further.
>Does anybody have an idea, how or where to get such a script-snippet ?
>

The "Sort" function works from left to right.
If you want to sort first by year, then by month, then by day,  you
should store your data like 98|July|04|Bndname|ID|Location|21|City.

If that is not an option, you could break the line up after reading it
in and form an new line like this:

$num=0;
open(datafile,"<../data/mydata.txt:);
while (!eof(datafile))
{
  $dataline=<datafile>;
  chomp($dataline);

($day,$month,$year,$Bndname,$D,$Location,$somenumber,$city)=split("\t",$dataline,8);
@newarray[$num]=$year."\t".$month."\t".$day."\t".$Bndname."\t".$D."\t".$Location."\t".$somenumber."\t".$city;
$num++;
}
@newarray=sort(@newarray);

The @newarray would be sorted as you requested.  You could then split
the lines on tabs again to retrieve your data.

This is not the most efficient method but it should work.

John













John Hocking
Sr. Programmer
StudioPointe Incorporated
http://www.studiopointe.com
mailto:johnh@studiopointe.com


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

Date: Fri, 03 Jul 1998 04:51:43 GMT
From: joker@inlink.com (John Hocking)
Subject: Re: Sorting Database Entries
Message-Id: <35a162d3.46855185@news.inlink.com>



>$num=0;
>open(datafile,"<../data/mydata.txt:);
>while (!eof(datafile))
>{
>  $dataline=<datafile>;
>  chomp($dataline);
>
>($day,$month,$year,$Bndname,$D,$Location,$somenumber,$city)=split("\t",$dataline,8);
>@newarray[$num]=$year."\t".$month."\t".$day."\t".$Bndname."\t".$D."\t".$Location."\t".$somenumber."\t".$city;
>$num++;
>}
>@newarray=sort(@newarray);
>
should have ended with 

close(datafile);
}

sorry if I left out anthing else

That is what I get for working into the wee hours of the morning :)
John Hocking
Sr. Programmer
StudioPointe Incorporated
http://www.studiopointe.com
mailto:johnh@studiopointe.com


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

Date: Thu, 02 Jul 1998 11:50:58 GMT
From: arielk@amdocs.com (Ariel Kornberg)
Subject: SWAP and memory problem.
Message-Id: <359b68a1.8958708@speedy>

Hi,

       I have a problem with swap. I have to read data from a very
larg logfile . My swap is limmeted . How can i read the lines from the
log , save only the relevent data in hash tables so that the program 
doesn't load all the file to the swap memory and only then prossess
it.
          Thenks 
                   Ariel Kornberg.


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

Date: Thu, 2 Jul 1998 13:46:47 +0100
From: "Simon Fairey" <simonf@conduit.co.uk>
Subject: Re: SWAP and memory problem.
Message-Id: <359b807a.0@nnrp1.news.uk.psi.net>

I assume you mean swap space?

How are you reading in the file, are you doing something like:
  @whole_file = <FILE>;

Why not just read the file, line by line, saving the stuff you need.
If the amount of data you have to save is part of what is causing the
problem then how about printing it out to a file as you go..
Is there a reason for storing the info in hash tables?

If I've lost the plot somewhere here then let me know :-)

Simon

Ariel Kornberg wrote in message <359b68a1.8958708@speedy>...
>Hi,
>
>       I have a problem with swap. I have to read data from a very
>larg logfile . My swap is limmeted . How can i read the lines from the
>log , save only the relevent data in hash tables so that the program
>doesn't load all the file to the swap memory and only then prossess
>it.
>          Thenks
>                   Ariel Kornberg.




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

Date: Thu, 02 Jul 1998 13:59:53 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: SWAP and memory problem.
Message-Id: <359B8449.67F1DF1@nortel.co.uk>

Ariel Kornberg wrote:
> 
> Hi,
> ... How can i read the lines from the
> log , save only the relevent data in hash tables so that the program
> doesn't load all the file to the swap memory and only then prossess
> it.

I don't think there is some general answer. You'll just have to give some
thought to how you could scan and pre-select your data 'while' you are reading
the file.


-- 
____________________________________________________________
Frank Quednau               
http://www.surrey.ac.uk/~me51fq
________________________________________________


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

Date: Thu, 02 Jul 1998 08:18:40 GMT
From: Marc.Haber-usenet@gmx.de (Marc Haber)
Subject: Re: system() and security again
Message-Id: <6nffq1$8rr$6@nz12.rz.uni-karlsruhe.de>

david+usenet@unico.com.au (David Goh) wrote:
>And ! ... don't forget bang.  And \, and tab and and and... Well yeah.
>Way too many. :) 

I don't have the perl source ready [1], but I suppose that there is
some code that identifies metachars and invokes a shell. Can anyone
please take a look at the source?

>If you're thinking about security of system() calls,
>you're probably best off forcing it into using a list, as other people
>have said. 

How about open FH, "|someprogram"? Is that invariably done via shell
or can I avoid the shell?

>Either that, or providing a *very* limited list of legal
>characters (alphanumerics, underscores, maybe slashes and a few others).

That could be a way to go. Thanks!

Greetings
Marc


[1] I would have to download it
-- 
-------------------------------------- !! No courtesy copies, please !! -----
Marc Haber          |   " Questions are the         | Mailadresse im Header
Karlsruhe, Germany  |     Beginning of Wisdom "     | Fon: *49 721 966 32 15
Nordisch by Nature  | Lt. Worf, TNG "Rightful Heir" | Fax: *49 721 966 31 29


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

Date: 02 Jul 1998 01:36:19 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: system() and security again
Message-Id: <m3ww9wmyyk.fsf@windlord.Stanford.EDU>

Marc Haber <Marc.Haber-usenet@gmx.de> writes:

> I don't have the perl source ready [1], but I suppose that there is some
> code that identifies metachars and invokes a shell. Can anyone please
> take a look at the source?

>From doio.c, around line 987:

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

/* see if there are shell metacharacters in it */

if (*cmd == '.' && isSPACE(cmd[1]))
    goto doshell;

if (strnEQ(cmd,"exec",4) && isSPACE(cmd[4]))
    goto doshell;

for (s = cmd; *s && isALPHA(*s); s++) ;     /* catch VAR=val gizmo */
if (*s == '=')
    goto doshell;

for (s = cmd; *s; s++) {
    if (*s != ' ' && !isALPHA(*s) && strchr("$&*(){}[]'\";\\|?<>~`\n",*s)) {
        if (*s == '\n' && !s[1]) {
            *s = '\0';
            break;
        }
      doshell:
        execl(sh_path, "sh", "-c", cmd, (char*)0);
        return FALSE;
    }
}

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

So the answer appears to be anything starting with ". ", anything staring
with "exec ", anything starting with all alphas and then an equal sign,
and anything containing one of the following special characters:

        $ & * ( ) { } [ ] ' " ; \ | ? < > ~ ` \n

Note that there is at least one more special character that *is* given
special meaning by some shells but that Perl doesn't catch specifically,
namely ^ (which some version of Bourne shell treat the same as |).

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Thu, 02 Jul 1998 09:41:31 GMT
From: Marc.Haber-usenet@gmx.de (Marc Haber)
Subject: Re: system() and security again
Message-Id: <6nfklc$9gq$1@nz12.rz.uni-karlsruhe.de>

Russ Allbery <rra@stanford.edu> wrote:
>So the answer appears to be anything starting with ". ", anything staring
>with "exec ", anything starting with all alphas and then an equal sign,
>and anything containing one of the following special characters:
>
>        $ & * ( ) { } [ ] ' " ; \ | ? < > ~ ` \n

Thanks!

Greetings
Marc

-- 
-------------------------------------- !! No courtesy copies, please !! -----
Marc Haber          |   " Questions are the         | Mailadresse im Header
Karlsruhe, Germany  |     Beginning of Wisdom "     | Fon: *49 721 966 32 15
Nordisch by Nature  | Lt. Worf, TNG "Rightful Heir" | Fax: *49 721 966 31 29


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

Date: Thu, 02 Jul 1998 08:25:37 GMT
From: magweb@my-dejanews.com
Subject: Text/plain --> URL/Encoded
Message-Id: <6nfg5v$vf4$1@nnrp1.dejanews.com>

Hi!

I've searched many FAQs and Dejanews but I haven't found a solution to my
problem. How do I encode a text/plain string into an URL encoded string? The
other way around is greatly documented but I can't seem to find this way. I
have tried some myself but I'm not that good at Perl yet.

Please help me, and yes, I help others when I can!

Regards Magnus

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Thu, 02 Jul 1998 07:33:18 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Text/plain --> URL/Encoded
Message-Id: <comdog-ya02408000R0207980733180001@news.panix.com>
Keywords: from just another new york perl hacker

In article <6nfg5v$vf4$1@nnrp1.dejanews.com>, magweb@my-dejanews.com posted:

>I've searched many FAQs and Dejanews but I haven't found a solution to my
>problem. How do I encode a text/plain string into an URL encoded string?

use URI::Escape;

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers T-shirts! <URL:http://www.pm.org/tshirts.html>


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

Date: 2 Jul 1998 21:37:16 GMT
From: kortbein@iastate.edu (Josh Kortbein)
Subject: Re: Text/plain --> URL/Encoded
Message-Id: <6nguic$q72$4@news.iastate.edu>

magweb@my-dejanews.com wrote:
: Hi!

: I've searched many FAQs and Dejanews but I haven't found a solution to my
: problem. How do I encode a text/plain string into an URL encoded string? The
: other way around is greatly documented but I can't seem to find this way. I
: have tried some myself but I'm not that good at Perl yet.

The CGI FAQ [1] suggests that URL-encoding should be a function provided
by every CGI library, then declines to explain the details. Perhaps that's
a good sign that you should use a CGI library, like CGI.pm [2].

If you would really rather do it yourself, though, the information [3] is
out there, and very easy to find.

BTW, your question is not a perl question, even though you're using
perl. It's a CGI question. The CGI newsgroups would serve you much better
until you're actually coding in perl.

Josh

[1]: http://www3.pair.com/webthing/docs/cgi/faqs/cgifaq.shtml
[2]: http://www.perl.com/CPAN-local/modules/by-module/CGI
[3]: http://www.cgi-resources.com/Documentation/CGI_Specification/

--

________________________________________________________________________
Interviewer: "So Frank, you have long hair. Does that make you a woman?"
Frank Zappa: "You have a wooden leg. Does that make you a table?"



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

Date: 3 Jul 1998 16:04:12 GMT
From: macintsh@cs.bu.edu (John Siracusa)
Subject: The vagaries of read()ing
Message-Id: <6nivds$7nc$1@news1.bu.edu>

I've been experimenting with various ways to do non-blocking reads from
a socket created with IO::Socket::INET.  The blocking part wasn't a
problem (since it's implemented in IO::Socket), it's the actual process
of reading from the filehandle that's bugging me.

At first I tried using sysread(), being careful to catch EINTR and
EWOULDBLOCK.  The problem I ran into was determining when I was "hung up
on" (when the socket connection closed suddenly).  In those cases,
sysread() would sometimes return 0 and sometimes return undef (I'm
trying to get this to work in both MacPerl as well as "regular" Perl,
BTW, which adds another wrinkle).  According to the docs, sysread() is
supposed to return the "number of bytes actually read, or undef if there
was an error.  I just assumed there were some E(whatever) error values I
wasn't checking for and moved on to regular read()

Well, the docs for read() seem to say the same thing as sysread():
returns the number of bytes actually read, or undef if there was an
error.  I'm assuming that I no longer have to check for interrupted
system calls like I did with sysread() (although I did try that; does it
hurt anything?), but do I still have to make multiple calls to read() to
make sure I "get it all"? (I tried that as well, BTW.  Again, does it
hurt?)

I guess I'm hung up on the "number of bytes *actually* read" part.  What
does that mean?  Is it just meant to apply to cases where you try to
read 100 bytes from a 50 byte file?  Or does it mean that it's possible
to use read() to read 100 bytes from a 200 byte file and only end up
getting 27 bytes on your first try (like sysread)?

I decided to go with read() since it seemed to have less gotchas, but I
still get a very strange error where I attempt to read some large(?)
number of bytes (say, 20,000) from the socket: I get a defined return
value of 0 *and* $! gets set to EWOULDBLOCK.  From then on, no matter
how many times I try to read() from the filehandle, I get the same
thing: 0 and EWOULDBLOCK.  These tests are being done with a known peer
that *does* send those bytes.  And about 80% of the time, the read()
works fine, so I'm baffled by the 0/EWOULDBLOCK thing.

To sum up, here's my understanding of how things *should* work with a
non-blocking filehandle:

sysread()

	* May need to be called multiple times to read X bytes.

	* Must check for EINTR and redo if caught.

	* If it returns undef and $! is EWOULDBLOCK, the connection
	  is still open but there's nothing ready to be read from
	  from the filehandle.

	* If it returns any defined value (even 0) then $! is not
	  meaningful, and filehandle is still connected.

	* If it returns undef and $! is anything other than EINTR and
	  EWOULDBLOCK, filehandle has been disconnected.

read()

	* Only need to call once to read X bytes (may call the real read()
	  several times to accomplish this)

	* If it returns undef and $! is EWOULDBLOCK, the connection
	  is still open but there's nothing ready to be read from
	  from the filehandle.

	* If it returns any defined value (even 0) then $! is not
	  meaningful, and filehandle is still connected.

	* If it returns undef and $! is anything other than EWOULDBLOCK,
	  filehandle has been disconnected.

I think some of the above is wrong, though, since I'm getting strange
bahevior that doesn't fall within that set of rules.  Perhaps it has to
do with the fact that "filehandle" is a socket connection rather than an
actual disk file...but hey, aren't they supposed to be indistinguishable
as far as Perl (well, Unix) is concerned?  And doesn't MacPerl attempt
to emulate this behavior?  Puzzling.

So, all you socket/[sys]read()/Perl gurus out there, where have I
gone wrong?  What "should" I be using to read?  When would I
ever want to use sysread() over read(), and is this one of those
situations?  And why can't I get consistent behavior from either
of them?  Any help is greatly appreciated...

-----------------+----------------------------------------
  John Siracusa  | If you only have a hammer, you tend to
 macintsh@bu.edu | see every problem as a nail. -- Maslow


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

Date: Thu, 02 Jul 1998 13:41:10 GMT
From: Mike Cariaso <mcariaso@genelogic.com>
Subject: threads, perl5.004_68, and perlTk
Message-Id: <359B8CE6.85B09081@genelogic.com>

I'm writing an application with an embeded perl5.004_68 interpreter.
Because of the communication mechanism with the rest of the application
tk's MainLoop is too restictive. Since the application and perl is
already heavily threaded I just put the MainLoop in a thread by itself.
Now during shutdown I need a way to tell MainLoop to quit. But an exit
will kill the whole process, not just the thread, plus there isn't any
good mechanism for telling MainLoop its time to execute the exit. So
here's my solution. Please tell me there is a better way. And please
tell me what it is.


When creating the object in perl I let one of the instance variables be
the thread holding the MainLoop.
ie
$self->{threadTk} = new Thread \&MainLoop;

then I can do all the Tk stuff I want, and everything is happy.

when its time to shutdown I need to have the thread shutdown.
As I said, no mechanism seemed obvious, so I thought I'd just kill the
thread. Some of you will cringe at that, I welcome alternative
solutions. 

to kill the thread I've done this.

eval "kill 9, $self->{threadTk};";

which seems to be working. presumably the kill is killing the thread,
but the eval keeps it from killing the process. Now thats not quite
sane, but its my best explanation.


Additionally I've tried making a small subroutine that creates a signal
handler that is set up to die on a given signal then runs MainLoop, but
thats had no real effect. 


Explanations on what exactly is happening here, and hopefully a better
way would be greatly appreciated.



Please respond via email (as well as the group, I'm sure somebody would
find this of interest).
-- 
Mike Cariaso                     (301) 987-1834
Software Engineer        mcariaso@genelogic.com         
Gene Logic, Inc.       http://www.genelogic.com


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

Date: 2 Jul 1998 16:51:44 GMT
From: ada@fc.hp.com (Andrew Allen)
Subject: Re: threads, perl5.004_68, and perlTk
Message-Id: <6ngdr0$b94@fcnews.fc.hp.com>

Mike Cariaso (mcariaso@genelogic.com) wrote:
: I'm writing an application with an embeded perl5.004_68 interpreter.
: Because of the communication mechanism with the rest of the application
: tk's MainLoop is too restictive.

This is often how people not used to event-based programming feel. Be
sure to explore and understand all of perl/Tk's event mechanisms.
Between fileevent and after/repeat, you can do an awful lot.

: Since the application and perl is 
: already heavily threaded I just put the MainLoop in a thread by itself.

Good. Just be sure not to spawn threads _in_ MainLoop. perl/Tk isn't
threadsafe. Check out:

  http://www.rosat.mpe-garching.mpg.de/mailing-lists//ptk/1998-04/msg00223.html

and

  http://www.rosat.mpe-garching.mpg.de/mailing-lists/ptk/1998-01/msg00088.html

: Now during shutdown I need a way to tell MainLoop to quit. But an exit
: will kill the whole process, not just the thread, plus there isn't any
: good mechanism for telling MainLoop its time to execute the exit.

Just destroy all the MainWindows. That's always been how you exit the
MainLoop.

Andrew


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

Date: Thu, 02 Jul 1998 15:15:24 +0100
From: Norman Paterson <norman@dcs.st-and.ac.uk>
Subject: tie and NDBM_File
Message-Id: <359B95FC.BD846145@dcs.st-and.ac.uk>

I'm having trouble getting tie to work with an NDBM_file.  All I can get
is the following message:


     Can't locate object method "TIEHASH" via package "NDBM_File"
     at upload line 144.


The system is Perl 5.004_04 on a SunOS 4.1.3 host.

I believe NDBM_File is an optional feature.  How can I tell if it is
installed?  I used the default installation for Perl, so if NDBM_File is
not installed, does that mean it is missing from the OS?  And if so,
where can I get it?

So many hypotheses, so little time.
--
Norman Paterson
http://www.dcs.st-and.ac.uk/~norman/
"Come from" considered "go to."
When you click on a web link, you ask for a page to *come from* a remote
site to your computer.  This is called "going to" the remote site.


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

Date: 02 Jul 1998 12:50:48 -0400
From: Jay Rogers <jay@rgrs.com>
To: Blake Mitchell <mitchell@ilog.com>
Subject: Re: time out for IO::Socket::accept()
Message-Id: <824sx019jr.fsf@shell2.shore.net>

Blake Mitchell <mitchell@ilog.com> writes:
> Is it possible to set a time out for a $socketref->accept call. Perhaps
> someone knows some sort of hack to set a timer or something that I could
> use to break ot of the function after a specified time. Or even better,
> if there were some way to poll the listener to see if there were any
> pending connections to be accepted.

Yes, "even better" will work.  After you do the listen() to allow
incoming connections, you can then select() on that socket for
reading.  When select indicates "ready" (i.e. a connection is waiting
to be accepted) you can then accept().

--
Jay Rogers
jay@rgrs.com


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

Date: Fri, 03 Jul 1998 11:51:38 +0800
From: Teoh Cy Boon <cyboon@sns.com.sg>
Subject: Re: Timeouts on receiving from a socket
Message-Id: <359C554A.ADF7464B@sns.com.sg>

Paul wrote:
> 
> I wrote a program that connects to a remote machine, sends a little
> data, and waits for a response. However, if no response comes back,
> the socket stays open and the program sits doing nothing. Is there any
> way to force a timeout on receiving data from a socket? I've tried
> using read(), recv(), while (<SOCK>) (which of course wouldn't work),
> I've read section 8 of the FAQ, tried using Comm.pl, tried using
> setsockopt using the SO_RCVTIMEO flag.
> 
> Is there any simple way to say "send this to the socket. If nothing
> comes back within 5 seconds, exit."?
> 
> Regards,
> 
> Paul.

Hi!

 You could try 'select'. 'man perlfunc' for more details. The basic
idea is to use select() to monitor your socket handle and only reading
data when select() indicates that the socket is ready. Otherwise, the
read operation on the socket will just block. The select() function
has a built-in timeout that you can use to implement minor/major
timeouts
if you're really optimistic :-)

And, the select() function you want is the one that looks like:

   select RBITS,WBITS,EBITS,TIMEOUT (taken from perlfunc manpage)

as perl has 2 select() functions that do radically different things.

Hope that helps!

-- 
Teoh Cy Boon              
Singapore Network Services   Phone: (65) 8716570
31 Science Park Road         Fax  : (65) 7785277
SNS hub, Singapore 117611    Email: cyboon@sns.com.sg


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

Date: Fri, 3 Jul 1998 11:17:54 -0400
From: "Teflon" <indy@NOSPAMdemobuilder.com>
Subject: Re: TIP: How to post good questions
Message-Id: <6nis30$jiu$1@nntp2.uunet.ca>

>I love it. I may even name my first child
"Yik-Jim-Su-Eyuhtick-Tim-Kwimmer".

People like you should not be allowed to have children.  In most countries
they sterilize retards to prevent unwanted children.


Bob Trieger wrote in message <6n6u91$k9q$1@ligarius.ultra.net>...
>Jonathan Feinberg <jdf@pobox.com> wrote:
>-> mjd@op.net (Mark-Jason Dominus) suggests:
>->
>-> > YOU CAN'T JUST MAKE SHIT UP AND EXPECT THE COMPUTER TO MAGICALLY
>-> > KNOW WHAT YOU MEAN, RETARDO!
>->
>-> Or, as we say in c.l.p.m., YCJMSUAETCTMKWYMR.  Has a nice ring to it,
>-> somewhat like TMTOWTDI, only bigger.  Say along with me,
>->
>->             "Yik-Jim-Su-Eyuhtick-Tim-Kwimmer"
>
>I love it. I may even name my first child
"Yik-Jim-Su-Eyuhtick-Tim-Kwimmer".
>
>
>Bob Trieger
>sowmaster@juicepigs.com
>" Cost a spammer some cash: Call 1-800-286-0591
>  and let the jerk that answers know that his
>  toll free number was sent as spam. "




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

Date: Fri, 03 Jul 1998 17:28:29 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: TIP: How to post good questions
Message-Id: <6nj4fr$en4$3@ligarius.ultra.net>

"Teflon" <indy@demobuilder.com> wrote:
-> >I love it. I may even name my first child
-> "Yik-Jim-Su-Eyuhtick-Tim-Kwimmer".
-> 
-> People like you should not be allowed to have children.  In most countries
-> they sterilize retards to prevent unwanted children.
-> 

I've got no rebut, just wanted a chance to post your address without the 
NOSPAM in there so the big bad spam monsters will get you. :)

Bob Trieger
sowmaster@juicepigs.com
" Cost a spammer some cash: Call 1-800-286-0591
  and let the jerk that answers know that his
  toll free number was sent as spam. "


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.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 3053
**************************************

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