[7650] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1276 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 5 20:08:05 1997

Date: Wed, 5 Nov 97 17:00:22 -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           Wed, 5 Nov 1997     Volume: 8 Number: 1276

Today's topics:
     Re: 'sort'ing umlauts (Toutatis)
     Re: 'sort'ing umlauts <rra@stanford.edu>
     Re: AUTOLOAD and sort (Brandon S. Allbery KF8NH; to reply, change "void" to "kf8nh")
     Re: Best way to test for decimal values that may contai (Sandy Herring)
     Re: binary file output (textual hex to binary stream -  <rootbeer@teleport.com>
     Re: cgi module in perl on apache server <libeson@pdb.pdb.bnl.gov>
     Re: Dbase and Fox Pro (Jonathan Stowe)
     Re: Did an open for append create the file? <justin@nectar.com.au>
     Re: Grabbing Pixels (Martien Verbruggen)
     Help Setting Up Perl 5.0 On Win95 ?? (Greg Teets)
     IRIX (5.3/6.2), PERL, APACHE problem!!!! HELP !!!! <libeson@pdb.pdb.bnl.gov>
     Re: Is this possible? (Brandon S. Allbery KF8NH; to reply, change "void" to "kf8nh")
     Re: Making script wait <justin@nectar.com.au>
     memory leak in POP3Client or something else? schadsey@coralsys.com
     Re: PERL->ADO->SQL (Mike Heins)
     Re: problem programming daemon with perl <justin@nectar.com.au>
     Re: Q: locking and re-writing file <rootbeer@teleport.com>
     Re: Sorting and Counting with PERL (brian d foy)
     Re: Sorting and Counting with PERL (Tad McClellan)
     unset an array <knguyen@ab.bluecross.ca>
     Re: unset an array (Tad McClellan)
     Re: unset an array <rra@stanford.edu>
     Re: waiting for forks <rootbeer@teleport.com>
     Re: why (and when) does undef == 0? (brian d foy)
     Win32 Perl and O'Reilly Website problems <rickmacc@mindspring.com>
     Re: Win32 Perl and O'Reilly Website problems <rootbeer@teleport.com>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 6 Nov 1997 00:30:54 GMT
From: toutatis@_SPAMTRAP_toutatis.net (Toutatis)
Subject: Re: 'sort'ing umlauts
Message-Id: <toutatis-ya023180000611970130470001@news.euro.net>

Randy Jay Yarger <randy@hs1.hst.msu.edu> wrote:

> I'm trying to figure out a way to sort a list of names which contain some
> characters with umlauts. The character with the umlaut should appear after
> the corresponding character without. So with the list:
> 
> @words = qw#Food
>         Fudge
>         F(oe)o
>         #;
> (To stick to 7-bit ascii I'll write umlaut-o as (oe).)
[...]
> But what I want is:
> Food
> F(oe)o
> Fudge
[...]
> (I though of turning the string into an array of the decimal character
> values, remapping 246 (oe) to 111.5 (111 is 'o'), and then sorting
> comparing the numerical values of the arrays. But maybe there is an easier
> way?)

Nice puzzle!
You could double each character in every word, and translate only the first
one. Then compare.

my @strings = qw(Food Fudge f(oe)o);
print "",(join "\n",sort clever @strings),"\n";

sub clever {
    my($one,$two)=($a,$b);
    for($one,$two){
        $_ =~ s/(.)/&translate($1).$1/ge;
    }
    lc($one) cmp lc($two);
}

sub translate {
    my $char = shift;
    $char =~ tr|funny_characters_here|plain_characters_here|;
    $char;
}

prints what you want :-)

-- 
Toutatis


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

Date: 05 Nov 1997 16:40:31 -0800
From: Russ Allbery <rra@stanford.edu>
To: Randy Jay Yarger <randy@hs1.hst.msu.edu>
Subject: Re: 'sort'ing umlauts
Message-Id: <m3hg9q26tc.fsf@windlord.Stanford.EDU>

[ Posted and mailed. ]

Randy Jay Yarger <randy@hs1.hst.msu.edu> writes:

> I'm trying to figure out a way to sort a list of names which contain
> some characters with umlauts. The character with the umlaut should
> appear after the corresponding character without.

man perllocale has details on these issues.  The short version is that you
need to do something along the lines of the following in your script:

             # This functionality not usable prior to Perl 5.004
             require 5.004;

             # Import locale-handling tool set from POSIX module.
             # This example uses: setlocale -- the function call
             #                    LC_CTYPE -- explained below
             use POSIX qw(locale_h);

             # query and save the old locale
             $old_locale = setlocale(LC_CTYPE);

             setlocale(LC_CTYPE, "fr_CA.ISO8859-1");
             # LC_CTYPE now in locale "French, Canada, codeset ISO 8859-1"

but using a locale appropriate to the data that you're sorting.  All of
the standard string operations will be affected by the change in locales,
so once you get the locale correctly sort should just do what you want.

There are a *lot* of other issues involved, though, so I'd highly
recommend reading the man page.  Note that you'll need Perl 5.004 or later
to use the locale functionality.

-- 
#!/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: Wed, 05 Nov 97 18:18:32 -0500
From: bsa@void.apk.net (Brandon S. Allbery KF8NH; to reply, change "void" to "kf8nh")
Subject: Re: AUTOLOAD and sort
Message-Id: <3460ff48$4$ofn$mr2ice@speaker>

In <ispvofo8ep.fsf@godzilla.kiere.ericsson.se>, on 11/05/97 at 01:02 PM,
   Calle Dybedahl <qdtcall@esb.ericsson.se> said:
+-----
| > perl -e 'print join "\n", sort { print $a } 1..5;'
| Refinement:
|     perl -e '@a = sort {1} 1..2;'
| also dumps. As fas as I can see with the debugger, sort somehow messes up
| the low-level array stuff.
+--->8

Solaris qsort goes haywire if the sort comparison function isn't
self-consistent.   sub { print $a } and sub {1} are both inconsistent, since
they return constant values for all elements to be sorted.

-- 
brandon s. allbery              [Team OS/2][Linux]          bsa@void.apk.net
cleveland, ohio              mr/2 ice's "rfc guru" :-)                 KF8NH



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

Date: 6 Nov 1997 00:23:41 GMT
From: sandy@herring.org (Sandy Herring)
Subject: Re: Best way to test for decimal values that may contain commas
Message-Id: <63r2md$nh8$1@www.structured.net>

On 4 Nov 1997 02:48:04 GMT, I wrote:
>I've written a script that converts data to comma separated value
>format. One requirement is that non-numerics (alpha or alphanumeric) are
>quoted and numerics are not quoted. Unfortunately, the numerics I
>encounter _may_ have commas.

[my original lamebrained solution snipped]

>BTW, this script must work under Perl5 as well as *sigh* Perl4 (please,
>no flames - that's not *my* choice). Anyone have a slicker way to
>accomplish this task?

I did get one emailed response to this, but haven't seen any USENET
followups - so I'll assume the person who responded via email wanted to
remain anonymous. I've incorporated his suggestion and tweaked it a bit
to come up with the following method...

	# numerics are not quoted, non-numerics are quoted
	if ((/^[\-\+\$]?\d*(\.\d*)?$/ ||
	     /^[\-\+\$]?\d{1,3}(\,\d{3})*(\.\d*)?$/) &&
	   !(/^[\-\+\.\$]$/)) {
		s/,//g;
		s/^\+//;
	} else {
		$_ = '"'.$_.'"'
	}

I guess I should ask Santa for "Mastering Regular Expressions" (by
Jeffrey E. F. Friedl), as was recommended by Tom and Randal in the
Stonehenge Perl class I just took from them :)

Sandy
-- 
Sandy Herring            finger for Geek Code        Peck of Pickled Pisces
sandy@herring.org       bigfish@sns-access.com       http://www.herring.org/


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

Date: Wed, 5 Nov 1997 16:30:15 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Nick Holmes <nick@bluewave.com>
Subject: Re: binary file output (textual hex to binary stream - wmf image file)
Message-Id: <Pine.GSO.3.96.971105162913.6157F-100000@usertest.teleport.com>

On Wed, 5 Nov 1997, Nick Holmes wrote:

> I am encountering some problems converting a textual hex file - embedded
> in an rtf file into binary stream - the sort of thing you get in a gif
> or other image file.
> 
> I have tried unpack and so-on, but that's still giving me text stuff,
> and not the full binary rendition of the data.

Maybe you should be using pack. In any case, you want to use the
transformation needed to get the output you want, and since you haven't
told us what that is, it's hard to guess from here. :-)

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



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

Date: Wed, 05 Nov 1997 16:49:52 -0500
From: libeson <libeson@pdb.pdb.bnl.gov>
Subject: Re: cgi module in perl on apache server
Message-Id: <3460EA00.794B@pdb.pdb.bnl.gov>

Lachlan Dunlop wrote:
> 
> Here is the error log:
> 
> Undefined subroutine &main::header called at
> /home/httpd/cgi-bin/upsship.pl line 7.
> 
> access to /home/httpd/cgi-bin/upsship.pl failed for abc.xyz.com, reason
> Premeture end of script headers
> 
> Thanks
> 
> Lach

You probably have one of the following in upsship.pl:

&header;
header();
&header();

and without the following in upsship.pl:

sub header {
}

Also look for variables in expressions that could be interpreted as
&header, possibly from some form of input.

-- 
libeson


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

Date: 6 Nov 1997 00:16:15 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: Dbase and Fox Pro
Message-Id: <63r28f$kta@argon.btinternet.com>

In article <01bce958$c09ade20$078054c7@lorenz>, Martin.Bolduc@riq.qc.ca 
says...
>
>Help,
>
>I want help for using Dbase III and Fox Pro database's on a Unix system
>with Perl 5.
>
Hmm,  First thing is to get the file format and if you look at

http://www.wotsit.demon.co.uk/database.htm

you will find some good stuff.  

For myself I havent actually tried anything along this way but now
you mention it could be interesting ;-}

PS Anyone tried a Lotus Organizer .OR2 file in perl ahem.....

Jonathan



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

Date: Thu, 06 Nov 1997 10:54:28 +1100
From: Justin Wills <justin@nectar.com.au>
To: fred@no.spam.leeds.ac.uk
Subject: Re: Did an open for append create the file?
Message-Id: <34610734.30A2F277@nectar.com.au>


--------------6185E0F4253B34893752F18F
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

fred@no.spam.leeds.ac.uk wrote:

> Is there an easy way to find out if the call to open() with a
> filename starting ">>... actually created the target file.
>
> Ben.



yeah, before you open it, say

(! -f $file ) && open(FILE, ">>$file);


--
Regards,

Justin Wills
justin@nectar.com.au



--------------6185E0F4253B34893752F18F
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<HTML>
fred@no.spam.leeds.ac.uk wrote:
<BLOCKQUOTE TYPE=CITE>Is there an easy way to find out if the call to open()
with a
<BR>filename starting ">>... actually created the target file.

<P>Ben.</BLOCKQUOTE>
&nbsp;

<P>yeah, before you open it, say

<P>(! -f $file ) &amp;&amp; open(FILE, ">>$file);
<BR>&nbsp;
<PRE>--&nbsp;
Regards,

Justin Wills
justin@nectar.com.au</PRE>
&nbsp;</HTML>

--------------6185E0F4253B34893752F18F--



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

Date: 5 Nov 1997 22:08:12 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Grabbing Pixels
Message-Id: <63qqoc$8o1$1@comdyn.comdyn.com.au>

In article <345EA37B.D8CAD2E9@poolpros.com>,
	Ryan Rose <ryanr@poolpros.com> writes:

>> Yes. You may find some helpful modules on CPAN, or you may use Perl to
>> work directly with binary files. Good luck!
>>
> Are there any packages out theer that I can do this with...  I'm sorry.. I'm
> going to need a little more help to get me started on accomplishing this..

CPAN stands for Comprehensive Perl Archive Network.
(http://www.perl.com/CPAN/CPAN.html). It basically is a repository of
a big load of modules/packages/scripts etc. for Perl. Go to
http://www.perl.com/CPAN/modules/00modlist.long.html, and look for the
'Images, Pixmap and Bitmap Manipulation, Drawing and Graphing'.  If
the module you need is there, download it, and install it. Also look
at some of the other links that will help you to understand what
modules are. Try perldoc perlmod from your command line.

HTH,
Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | Little girls, like butterflies, need no
Commercial Dynamics Pty. Ltd.       | excuse - Lazarus Long
NSW, Australia                      | 


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

Date: Thu, 06 Nov 1997 00:25:10 GMT
From: teetshd@email.uc.edu (Greg Teets)
Subject: Help Setting Up Perl 5.0 On Win95 ??
Message-Id: <34610da4.463490@news.ececs.uc.edu>

I have just unzipped the Perl 5.0 kit that came on a CD with the book
CGI Programming with Perl5.  Unzipping the .GZ file gave me many files
of different file types.

What do I do next?  Do I need to compile this with my c++ compiler?  I
use Perl at work on UNIX but I have no idea how to get going on my
Win95 machine at home.

Thanks in advance for any help you can give me.

Thanks,
Greg in Cincinnati


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

Date: Wed, 05 Nov 1997 18:08:43 -0500
From: libeson <libeson@pdb.pdb.bnl.gov>
Subject: IRIX (5.3/6.2), PERL, APACHE problem!!!! HELP !!!!
Message-Id: <3460FC7B.15FB@pdb.pdb.bnl.gov>

Can anyone help me with the following problem:

I have installed PERL5 for my group a few times as well as
APACHE. My group has designed a web-based submission tool for
molecular structure information. For the initial release, we
were running NCSA on a 5.2 system. What was happening is that
the programs that generated the forms for submission are written
in perl and every so often a 500 server error would occur, but
if you clicked the reload button it was OK. We were able to
get around this in a very funny way( I do not wish to mention ).
The version of perl at the time was a mixture of 5.002 and 4.036.
At a later date we heavily modified the look for easier and quicker
access to the multiple forms. We also tried to resolve the 500 server
error by reducing the possibilities, due to the fact that rld errors
were showing up we converted all of our perl4 scripts to perl5 under
the perl5.002 version. We still had the problem. I then made several
attempts to solve this problem. At this time we are running our web
services with the apache 1.2.0 server and a statically linked version
of perl5.00393. The problem is not occuring at this time; however,
we have statically linked the sybase package into the perl5 binary,
but it seems that the libraries are dynamically linked. We have resolved
the missing library path issue by supplying it to the server and to all
of our users, since all of our users are constantly using perl. This
caused another problem. Any perl script started from a non-login shell
does not contain the library path needed for perl5.00393 to work. So
when a machine reboots and starts our server, the perl scripts do not
work because the environment variable LD_LIBRARY_PATH is not set and
so the server can not pass the information to the process running the
perl script and the perl script fails.

I have recently tried to install a new version of perl5.00401. I built
it statically and even forced the sybase package to be completely
built statically. It works fine everywhere accept when being used for
our web services. It has the same old problem again with the 500
server error showing up whenever it feels like it. And YES I DO HAVE
the BUFFER TURNED OFF, so that the STDOUT goes directly to the page.
The rld problems do not exist anymore and there are no diagnostic
error messages pointing to any kind of problem, like I stated earlier,
if you click reload it is OK and it doen't happen all the time, but
often enough. The input does not seem to make a difference either. It
seems to be a timing issue, but it shouldn't be. We have our TIMEOUT
set to 1200. All pages are displayed within 30 seconds to a minute.
If the 500 server error occurs, it seems to happen very quickly.

The new web service is running on a 6.2 IRIX64 machine r8000, with
4 90 mhz processors. Could the machine be to fast sometimes?

Any insight would be appreciated. Thank You.


-- 
libeson


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

Date: Wed, 05 Nov 97 18:27:28 -0500
From: bsa@void.apk.net (Brandon S. Allbery KF8NH; to reply, change "void" to "kf8nh")
Subject: Re: Is this possible?
Message-Id: <3461025b$6$ofn$mr2ice@speaker>

In <345FC107.FE800C33@nortel.com>, on 11/04/97 at 06:42 PM,
   Kirk Herlitz <kherlitz@nortel.com> said:
+-----
| Declared like this:
| %users={@automgr,@autoreg,@decoder,@decoder2,@toolbar,@trapid,@vsosui};
+--->8

That "unfolds" the lists and uses the result as a list of key/value pairs.

You should take a look at references.  You store a reference to a list in the
hash, then use the -> operator to follow the reference:

    %users = (automgr => \@automgr, autoreg => \@autoreg, decoder =>
\@decoder, ... );
    $kv = 'decoder';
    $el = 2;
    print $users{$kv}->[$el];

I didn't see any keys in your hash, BTW.  Do you really want a hash, or
another list?

-- 
brandon s. allbery              [Team OS/2][Linux]          bsa@void.apk.net
cleveland, ohio              mr/2 ice's "rfc guru" :-)                 KF8NH



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

Date: Thu, 06 Nov 1997 11:00:29 +1100
From: Justin Wills <justin@nectar.com.au>
Subject: Re: Making script wait
Message-Id: <3461089C.E7C19E7B@nectar.com.au>


--------------F26FD39153355FBD631D1E11
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Andrew D. Arenson wrote:

>         I'd like to make my script wait for 5 minutes at a certain
> point. What's the best way to do this?
>
> --
> Andrew D. Arenson            | http://gc.bcm.tmc.edu:8088/cgi-bin/andy/andy
> Baylor College of Medicine   | arenson@bcm.tmc.edu        (713)  H 520-7392
> Genome Sequencing Center, Molecular & Human Genetics Dept.     | W 798-4689
> One Baylor Plaza, Room S903, Houston, TX 77030                 | F 798-5386

 sleep(300);

--
Regards,

Justin Wills
justin@nectar.com.au



--------------F26FD39153355FBD631D1E11
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<HTML>
Andrew D. Arenson wrote:
<BLOCKQUOTE TYPE=CITE>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I'd like
to make my script wait for 5 minutes at a certain
<BR>point. What's the best way to do this?

<P>--
<BR>Andrew D. Arenson&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
| <A HREF="http://gc.bcm.tmc.edu:8088/cgi-bin/andy/andy">http://gc.bcm.tmc.edu:8088/cgi-bin/andy/andy</A>
<BR>Baylor College of Medicine&nbsp;&nbsp; | arenson@bcm.tmc.edu&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
(713)&nbsp; H 520-7392
<BR>Genome Sequencing Center, Molecular &amp; Human Genetics Dept.&nbsp;&nbsp;&nbsp;&nbsp;
| W 798-4689
<BR>One Baylor Plaza, Room S903, Houston, TX 77030&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
| F 798-5386</BLOCKQUOTE>
&nbsp;sleep(300);
<PRE>--&nbsp;
Regards,

Justin Wills
justin@nectar.com.au</PRE>
&nbsp;</HTML>

--------------F26FD39153355FBD631D1E11--



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

Date: Wed, 05 Nov 1997 17:36:23 -0600
From: schadsey@coralsys.com
Subject: memory leak in POP3Client or something else?
Message-Id: <878771928.10160@dejanews.com>

Can someone help explain why the following program:
--
#!/usr/local/bin/perl -w

use Mail::POP3Client;
use strict;

for(;;) {
        my $pop = Mail::POP3Client->new("user","password","server",110);
        print "Found ".$pop->Count()." messages\n";
        $pop->Close;
        undef($pop);
}
--
adds about 4K to its main memory image size every 5-10 seconds?  this
happens both with and without the undef line.

this is with perl version 5.003_02 on a solaris 2.5.1 machine

Thanks!

^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~
Steve Chadsey                   <>               schadsey@coralsys.com
I think about closing the door  <>       and lately I think of it more
I'm living well out of my time  <>      I feel like i'm losing my mind
--Black Sabbath                 <> "Falling off the Edge of the World"
^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

Date: 5 Nov 1997 22:11:01 GMT
From: mheins@prairienet.org (Mike Heins)
Subject: Re: PERL->ADO->SQL
Message-Id: <63qqtl$hli$1@vixen.cso.uiuc.edu>

Jack (NoSPAMa-jackg@microsoft.com) wrote:
: Using PERL WIN32, does anyone have any sample code using the ADO command
: object to execute SQL code (preferably an MS SQL stored procedure)?
: 


Let's see.

You want attention.  So you post this message multiple times,
separately, to multiple newsgroups. You figure this will get
you attention.

You are right -- it did.

<*plonk*>

-- 
Regards,
Mike Heins

This post reflects the
opinion of my employer.


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

Date: Thu, 06 Nov 1997 11:06:06 +1100
From: Justin Wills <justin@nectar.com.au>
Subject: Re: problem programming daemon with perl
Message-Id: <346109EE.75FEE934@nectar.com.au>


--------------823DE3AB2452631056CE36BD
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Richard McGahey wrote:


you have to put 2 forks in front of it, otherwise it'll only run once.




> Hi there,
>         I hope someone could help me out about this. I tried to program a
> simple server program that will run in background as a daemon process,
> but now my problem is after it runs - it only response back to client
> only once then it dies. It didn't stay. Here is my simple program ->
>
> #!/usr/bin/perl
>
> require 'sys/socket.ph';
>
> $sockaddr = 'S n a4 x8';
>
> $port = 5000;
>
> $hostname = `hostname`;
> chop($hostname);
>
> ($name, $aliases, $protocol) = getprotobyname('tcp');
> ($name, $aliases, $type, $len, $rawaddr) = gethostbyname($hostname);
> $serveraddr = pack($sockaddr, &AF_INET, $port, $rawaddr);
> socket(MASTER, &PF_INET, &SOCK_STREAM, $protocol) || die("\nNo
> socket!\n");
> bind(MASTER, $serveraddr) || die("\nCan't bind\n");
> listen(MASTER, 1) || die("\nCan't listen\n");
> ($clientaddr = accept(SLAVE, MASTER)) || die("\ncan't listen\n");
>
> select(SLAVE);
> $| = 1;
>
> $line = "Test Socket, it's working!";
> print SLAVE ("$line\n");
> close(SLAVE);
> close(MASTER);
>
> please help!..
> thanks
> pe'



--
Regards,

Justin Wills
justin@nectar.com.au



--------------823DE3AB2452631056CE36BD
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<HTML>
Richard McGahey wrote:
<BR>&nbsp;

<P>you have to put 2 forks in front of it, otherwise it'll only run once.
<BR>&nbsp;
<BR>&nbsp;
<BR>&nbsp;
<BLOCKQUOTE TYPE=CITE>Hi there,
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I hope someone could help
me out about this. I tried to program a
<BR>simple server program that will run in background as a daemon process,
<BR>but now my problem is after it runs - it only response back to client
<BR>only once then it dies. It didn't stay. Here is my simple program ->

<P>#!/usr/bin/perl

<P>require 'sys/socket.ph';

<P>$sockaddr = 'S n a4 x8';

<P>$port = 5000;

<P>$hostname = `hostname`;
<BR>chop($hostname);

<P>($name, $aliases, $protocol) = getprotobyname('tcp');
<BR>($name, $aliases, $type, $len, $rawaddr) = gethostbyname($hostname);
<BR>$serveraddr = pack($sockaddr, &amp;AF_INET, $port, $rawaddr);
<BR>socket(MASTER, &amp;PF_INET, &amp;SOCK_STREAM, $protocol) || die("\nNo
<BR>socket!\n");
<BR>bind(MASTER, $serveraddr) || die("\nCan't bind\n");
<BR>listen(MASTER, 1) || die("\nCan't listen\n");
<BR>($clientaddr = accept(SLAVE, MASTER)) || die("\ncan't listen\n");

<P>select(SLAVE);
<BR>$| = 1;

<P>$line = "Test Socket, it's working!";
<BR>print SLAVE ("$line\n");
<BR>close(SLAVE);
<BR>close(MASTER);

<P>please help!..
<BR>thanks
<BR>pe'</BLOCKQUOTE>
&nbsp;
<PRE>--&nbsp;
Regards,

Justin Wills
justin@nectar.com.au</PRE>
&nbsp;</HTML>

--------------823DE3AB2452631056CE36BD--



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

Date: Wed, 5 Nov 1997 16:44:09 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Henry Gabryjelski <henryg@ernie.WPI.EDU>
Subject: Re: Q: locking and re-writing file
Message-Id: <Pine.GSO.3.96.971105163222.6157G-100000@usertest.teleport.com>

On 5 Nov 1997, Henry Gabryjelski wrote:

> My question is:
>    Will the following code set the new size correctly?
>    Are there any gotcha's I should watch for?

> my $fh = IO::File->new( $file, O_WRONLY );  # need fh for flock
> flock( $fh, LOCK_EX );                      # exclusive to write
> seek( $fh, 0, SEEK_SET );                   # reset to start of file
> 
> my $value;
> foreach $value (@list) { print $fh $value } # Whatever...
> 
> flock( $fh, LOCK_UN );                      # Play nicely

You seem to be assuming that opening the file succeeded. Even when your
script is "just an example" (and perhaps especially in that case!) you
should _always_ check the return value after opening a file.

You shouldn't explicitly unlock a file (unless you understand this rule
completely). 

In this case, I believe a call to truncate would be in order, probably at
the end of printing. (Use tell to find out where to truncate.) Then simply
close the file, and the lock will take care of itself.

Also, are you assuming that the file is unchanged since it was last read?
That may be an unwise assumption. 

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



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

Date: Wed, 05 Nov 1997 18:29:14 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Sorting and Counting with PERL
Message-Id: <comdog-ya02408000R0511971829140001@news.panix.com>

In article <3460E69B.6EA1BB92@troweprice.com>, app6042 <mgalbreath@troweprice.com> wrote:

>I can't fathom a solution for this.  I have a list of about 80,000
>timestamps, e.g.,
>
>03/Jun/1997:13:34:13
>03/Jun/1997:13:34:13
>03/Jun/1997:13:36:13
>03/Jun/1997:13:36:13


Tad and I both answered this question earlier this week, so you might
want to use Dejanews to see that thread. 

good luck :)

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Wed, 5 Nov 1997 18:01:59 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Sorting and Counting with PERL
Message-Id: <nd1r36.fr.ln@localhost>

app6042 (mgalbreath@troweprice.com) wrote:
: This is a multi-part message in MIME format.
                               ^^^^^^^^^^^^^^
                               ^^^^^^^^^^^^^^

How come?

Were you planning to attach a binary or something?



: I can't fathom a solution for this.  I have a list of about 80,000
: timestamps, e.g.,

: I need to use PERL to count the number of instances each unique
: timestamp occurs.  Can someone please help me on this?


while (<>) {
   $h{$_}++;
}
foreach (sort keys %h) {printf "%6d  %s\n", $h{$_}, $_;


--
    Tad McClellan                          SGML Consulting
    tadmc@flash.net                        Perl programming
    Fort Worth, Texas


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

Date: Wed, 05 Nov 1997 15:58:09 -0700
From: Ky Nguyen <knguyen@ab.bluecross.ca>
Subject: unset an array
Message-Id: <3460FA01.4258@ab.bluecross.ca>

hi all

i have a challenge in my program that i need some helps:
i need to define # of lists, combine the information fr the list
and print the report (just like a inner join in RDMS world). i
then repeat the same process again with the same lists but diff
source. the problem: the old lists grow and i'd like to reinitialize
them for each iteration.

i tried unset $VAR but perl didnt detect my intention!!
i guess i can pop all items in the lists but that's pretty bad method 
i'd say).
or ... is there a proper way to make your array or your list empty.

thanks in advance.
-- 
        ''~``
       ( o o )
+-.oooO--(_)--Oooo.-----------------------------------+
| Light travels faster than sound. This is why some   |
|  people appear bright until you hear them speak.    |
|   .oooO                                             |
|   (   )   Oooo.                                     |
+----\ (----(   )-------------------------------------+
      \_)    ) /
            (_/


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

Date: Wed, 5 Nov 1997 17:12:58 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: unset an array
Message-Id: <qhuq36.2m.ln@localhost>

Ky Nguyen (knguyen@ab.bluecross.ca) wrote:

: the problem: the old lists grow and i'd like to reinitialize
: them for each iteration.

: i tried unset $VAR but perl didnt detect my intention!!
: i guess i can pop all items in the lists but that's pretty bad method 
: i'd say).
: or ... is there a proper way to make your array or your list empty.
                  ^^^^^^^^^^^^

I would go with the way described in the Fine Manuals that are
included with the perl distribution.

>From the perldata man page under the heading 'Scalar values':

------------------------
You can truncate an array down to nothing by assigning the null list ()
to it.  The following are equivalent:

    @whatever = ();
    $#whatever = -1;
------------------------


Is that what you mean?



--
    Tad McClellan                          SGML Consulting
    tadmc@flash.net                        Perl programming
    Fort Worth, Texas


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

Date: 05 Nov 1997 16:41:15 -0800
From: Russ Allbery <rra@stanford.edu>
To: Ky Nguyen <knguyen@ab.bluecross.ca>
Subject: Re: unset an array
Message-Id: <m3d8ke26s4.fsf@windlord.Stanford.EDU>

[ Posted and mailed. ]

Ky Nguyen <knguyen@ab.bluecross.ca> writes:

> is there a proper way to make your array or your list empty.

undef @array;

-- 
#!/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: Wed, 5 Nov 1997 16:51:19 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: matthew rinella <mrinella@earthlink.net>
Subject: Re: waiting for forks
Message-Id: <Pine.GSO.3.96.971105164713.6157I-100000@usertest.teleport.com>

On Tue, 4 Nov 1997, matthew rinella wrote:

>     I want my perl script to run a large list of child processes, but
> only have  2 running at any given time.
> 
> any advice?

I think you should write your script so that it will run the child
processes a maximum of two at a time. :-) 

If you have troubles doing this, write again to let us know how far you've
gotten and what part of the problem has you stuck.

Hints: You'll probably want to use fork and exec. wait has a useful return
value. $SIG{CHLD} should probably be set to 'DEFAULT'. Since you might
want to move this script to another (presumably more capable) machine at a
later date, it would be good to define MAX_CHILDREN as a constant (see
'perldoc constant'). 

Good luck!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



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

Date: Wed, 05 Nov 1997 17:18:11 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: why (and when) does undef == 0?
Message-Id: <comdog-ya02408000R0511971718110001@news.panix.com>

In article <3460E35F.3057@santafe.edu>, "Timothy H. Keitt" <tkeitt@santafe.edu> wrote:

>O.K.  You answered the "when" question, but not what I was really
>after.  The problem with undef() being equivalent to zero in algebraic
>expressions is that you can't then use undef() as a return value to

do you want be be able to multiply by strings as well?  why should

   '' * 7

return a result different than

   'cats and dogs' * 7

?  it's not that undef is equivalent to zero - it's non-numbers, which is 
an entirely different perspective.  that's why i included those
demonstrations in my earlier example.

>indicate an error in a subroutine, so
>
>        $corr = &cov($ar1, $ar2) / (&std($ar1)*&std($ar2));
>
>causes a divide by zero runtime error if &std returns undef() and
>assigns zero as the result if &cov returns undef().  If the entire
>expression returned undef() when any of the operands were undefined,
>then you only need to check $corr to see if it is defined.  Otherwise,
>you have to check the return value of each function seperately. 

or trap the error in an eval{} - which you should be doing anyway.

but this begs a couple of questions questions:

   * why would a function to be used in the demoninator be allowed
   to return undef or 0?

   * why aren't you doing more extensive data checking?  it's not
   enough to know when something fails - you need to know where it
   failed and why (for instance, &std($ar1) did not return a number,
   or some such)

just because you are using Perl doesn't mean you can forget good
programming practices :)

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Wed, 5 Nov 1997 17:54:09 -0500
From: "Rick MacConnell" <rickmacc@mindspring.com>
Subject: Win32 Perl and O'Reilly Website problems
Message-Id: <63qthe$76e@camel15.mindspring.com>

I am trying to get the Win32 Perl 5.0 port to work with O'Reilly Website
(not the Professional version). I have the associations installed in the 95
explorer and the scripts will run, albeit with wacky responses. Whenever I
try to access a script through a browser however, I get a 550 message:
Unable to start CGI process. The self-test stuff with the VB CGI examples
works fine. I'm just having problems getting perl to operate properly!?
Anyone have any ideas?




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

Date: Wed, 5 Nov 1997 16:46:49 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Rick MacConnell <rickmacc@mindspring.com>
Subject: Re: Win32 Perl and O'Reilly Website problems
Message-Id: <Pine.GSO.3.96.971105164543.6157H-100000@usertest.teleport.com>

On Wed, 5 Nov 1997, Rick MacConnell wrote:

> I am trying to get the Win32 Perl 5.0 port to work with O'Reilly Website
> (not the Professional version). I have the associations installed in the 95
> explorer and the scripts will run, albeit with wacky responses. Whenever I
> try to access a script through a browser however, I get a 550 message:
> Unable to start CGI process. The self-test stuff with the VB CGI examples
> works fine. I'm just having problems getting perl to operate properly!?
> Anyone have any ideas?

Sounds as if you can't get the server to start Perl. You should check with
the docs and FAQs about servers. If you still can't find what you need,
the folks in a newsgroup about servers should be able to help. Good luck!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



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

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

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