[17837] in Perl-Users-Digest
Perl-Users Digest, Issue: 5257 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 5 04:06:09 2001
Date: Fri, 5 Jan 2001 01:05:39 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <978685538-v9-i5257@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 5 Jan 2001 Volume: 9 Number: 5257
Today's topics:
Re: Question regarding directory handles <ddunham@redwood.taos.com>
Read first line of a file <flynhi@gte.net>
Re: Read first line of a file (Tad McClellan)
Re: Read first line of a file (Abigail)
Re: Read first line of a file <mischief@velma.motion.net>
Re: Read first line of a file (Richard Zilavec)
Re: Read first line of a file <johnlin@chttl.com.tw>
recursive directory copy?!? <genie.us@@home.com>
Re: recursive directory copy?!? egwong@netcom.com
Reposting - Pattern match in an array of strings <rrocky@bigfoot.com>
Re: Search Engine - matching file from list of files (Tad McClellan)
Re: Segmented Mac OS X dev tools (was: Yet another gcc (Peter Seebach)
Re: Segmented Mac OS X dev tools (Peter Seebach)
Re: Segmented Mac OS X dev tools (Ilya Zakharevich)
sendmail on Exchange 5.5 mail server? <pdmos23@geocities.com>
Re: sendmail on Exchange 5.5 mail server? (Chris Fedde)
Set IE5 default homepage WITHOUT JavaScript foopah@my-deja.com
Re: Set IE5 default homepage WITHOUT JavaScript <brondsem@my-deja.com>
Re: Set IE5 default homepage WITHOUT JavaScript foopah@my-deja.com
socket in perl, help!! <b0l4549@cs.tamu.edu>
Sockets using threads, not forks <steve@see-signature.com>
Re: Sockets using threads, not forks (Chris Fedde)
Re: Sorting a Text file Database with perl jamesdandy@my-deja.com
Re: Troubleshooting flock failure (Chris Fedde)
Re: Unitialised value error. <johngros@Spam.bigpond.net.au>
Re: Unitialised value error. <johngros@Spam.bigpond.net.au>
Re: Unitialised value error. <johngros@Spam.bigpond.net.au>
Re: what does this mean? (Tad McClellan)
Re: What's the Best Approach to this? (BUCK NAKED1)
Re: What's the Best Approach to this? (Tad McClellan)
Re: What's the Best Approach to this? <peter.sundstrom@eds.com>
Re: What's wrong with this 2-child fork/wait? <davesisk@ipass.net>
Re: window NT and perl <harrisr@bignet.net>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 04 Jan 2001 17:57:59 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: Question regarding directory handles
Message-Id: <HQ256.39$Tw5.25891@news.pacbell.net>
Cartland Chiu <cchiu@credit.erin.utoronto.ca> wrote:
> I took at look at the File::Find module but it doesn't do quite what I
> want. I can't do any "post-recursion" stuff using this module (i.e. the
> 'delete current directory if empty' part in the code above).
File::Find has two functions. find() and finddepth()
find() always returns a directory before any children...
/a
/a/b
/a/c
finddepth() always returns a directory after any children...
/a/b
/a/c
/a
The second version is probably more helpful for your intended purpose.
The term 'depth-first search' apparantly means different things to
different people.
--
Darren Dunham ddunham@taos.com
Unix System Administrator Taos - The SysAdmin Company
Got some Dr Pepper? San Francisco, CA bay area
< Please move on, ...nothing to see here, please disperse >
------------------------------
Date: Thu, 04 Jan 2001 19:50:17 GMT
From: "flynhi" <flynhi@gte.net>
Subject: Read first line of a file
Message-Id: <Tt456.1784$h51.192159@dfiatx1-snr1.gtei.net>
Is there a simple way to read just the first line of a file?
TIA
------------------------------
Date: Thu, 4 Jan 2001 13:02:08 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Read first line of a file
Message-Id: <slrn959el0.ngp.tadmc@magna.metronet.com>
flynhi <flynhi@gte.net> wrote:
>Is there a simple way to read just the first line of a file?
my $first_line = <FILE>;
close FILE;
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 4 Jan 2001 20:24:57 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Read first line of a file
Message-Id: <slrn959n0p.3co.abigail@tsathoggua.rlyeh.net>
flynhi (flynhi@gte.net) wrote on MMDCLXXXIII September MCMXCIII in
<URL:news:Tt456.1784$h51.192159@dfiatx1-snr1.gtei.net>:
;; Is there a simple way to read just the first line of a file?
$ perl -pelast}{ /path/to/file
First line
$
Abigail
--
perl -wle'print"Κυστ αξοτθες Πεςμ Θαγλες"^"\x80"x24'
------------------------------
Date: Thu, 04 Jan 2001 20:33:42 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Read first line of a file
Message-Id: <t59nh6ff8g2402@corp.supernews.com>
flynhi <flynhi@gte.net> wrote:
> Is there a simple way to read just the first line of a file?
> TIA
open(filehandle, "filename");
$data = <filehandle>;
close(filehandle);
Chris
--
Christopher E. Stith
Try not. Do, or do not. The Force is binary. -- Yoda,
The Empire Strikes Back (paraphrased)
------------------------------
Date: Thu, 04 Jan 2001 20:57:53 GMT
From: rzilavec@tcn.net (Richard Zilavec)
Subject: Re: Read first line of a file
Message-Id: <3a54e1fa.110326069@news.tcn.net>
On Thu, 04 Jan 2001 19:50:17 GMT, "flynhi" <flynhi@gte.net> wrote:
>Is there a simple way to read just the first line of a file?
>TIA
perldoc IO::File
use IO::File;
my ($fh, $line);
$fh = new IO::File;
$fh->open("< file");
$line = <$fh>;
$fh->close;
$line = `head -1 /tmp/file`;
open(IN, "< file");
$line = <IN>;
close(IN);
--
Richard Zilavec
rzilavec@tcn.net
------------------------------
Date: Fri, 5 Jan 2001 08:33:29 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: Read first line of a file
Message-Id: <9334sn$67l@netnews.hinet.net>
Abigail wrote
> flynhi wrote
> ;; Is there a simple way to read just the first line of a file?
>
> $ perl -pelast}{ /path/to/file
> First line
Use 'last' for the 'first' line.
John Lin
------------------------------
Date: Fri, 05 Jan 2001 05:53:45 GMT
From: "djinni" <genie.us@@home.com>
Subject: recursive directory copy?!?
Message-Id: <Jjd56.942965$8u4.19010825@news1.rdc1.bc.home.com>
Does anyone know how to recursively copy a directory?
thanks,
-dj
------------------------------
Date: Fri, 05 Jan 2001 06:16:57 GMT
From: egwong@netcom.com
Subject: Re: recursive directory copy?!?
Message-Id: <tFd56.36543$bw.2337308@news.flash.net>
djinni <genie.us@@home.com> wrote:
> Does anyone know how to recursively copy a directory?
> thanks,
> -dj
Yes. First I'd start by reading the "File::Copy" and
"File::Find" perldocs. They should be included in your
perl distribution.
------------------------------
Date: Thu, 04 Jan 2001 16:39:28 -0800
From: Rocky Raccoon <rrocky@bigfoot.com>
Subject: Reposting - Pattern match in an array of strings
Message-Id: <3A5517C0.7CDA0F30@bigfoot.com>
If I have an array of strings, say
@x = ("Hello\n", "World\n", "Hello to\n", "World");
I want to search for the string "Hello World".
I should get found for @x[0], @x[1], but not found for @[2] , @[3]
(because World doesn't follow to immediately).
What's the best way to do it ?
chomp each line, concatenate everything & then search for the pattern
(/Hello\s+World/) or someother easier way.
I am not really interested in where it occurs, just whether it occurs
or not.
--
Rocky
RSC - http://www.slack.net/~shiva/rsc.html
------------------------------
Date: Thu, 4 Jan 2001 11:43:43 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Search Engine - matching file from list of files
Message-Id: <slrn959a1v.n9e.tadmc@magna.metronet.com>
Renegade Master <renegade.master@dial.pipex.com> wrote:
>
>I've got a search engine script running in Perl. What I'm trying to do is
>add the capability to have a list of "excluded" files.
>I guess it would have something to do with regular expressions or something,
No, but a "hash" would be useful here.
Load up a hash with the to-be-skipped filenames as hash keys
(hash values don't matter at all), then use exists() to
see if the current dir is a key in the hash:
# or read from file and load hash
my %skip = (
dir1 => 1,
dir2 => 1,
};
>while (@dirs) {
> $dir = shift (@dirs);
next if exists $skip{$dir};
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 05 Jan 2001 03:41:26 GMT
From: seebs@plethora.net (Peter Seebach)
Subject: Re: Segmented Mac OS X dev tools (was: Yet another gcc on Mac OS X posting)
Message-Id: <3a554266$0$16022$3c090ad1@news.plethora.net>
In article <iowa88_song88.remove_eights-0201011913140001@70.salt-lake-city-05-10rs.ut.dial-access.att.net>,
Weston Cann <iowa88_song88.remove_eights@hotmail.com> wrote:
>Oh yes, the one other funny thing: the fact that the original, unsegmented
>gzipped archive somehow becomes unreadable by gzip after I pass it through
>this perl script, despite the fact that as far as I can tell, I'm opening
>the .gz for read only.
My guess is that, in that case, it's really that the "original" archive is
*also* a short read. Look at the "master" copy you started with and make
sure it's the same size.
Drop me a line with the URL you were getting the original from, and I'll see
if it looks like a complete archive to me.
-s
--
Copyright 2001, All rights reserved. Peter Seebach / seebs@plethora.net
C/Unix wizard, Pro-commerce radical, Spam fighter. Boycott Spamazon!
Consulting & Computers: http://www.plethora.net/
------------------------------
Date: 05 Jan 2001 03:43:22 GMT
From: seebs@plethora.net (Peter Seebach)
Subject: Re: Segmented Mac OS X dev tools
Message-Id: <3a5542da$0$12802$3c090ad1@news.plethora.net>
In article <930d7s$21v$1@charm.magnus.acs.ohio-state.edu>,
Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
>[A complimentary Cc of this posting was NOT sent to Martien Verbruggen
><mgjv@tradingpost.com.au>],
>who wrote in article <slrn9553mc.edk.mgjv@martien.heliotrope.home>:
>> >> Assuming your perl script is not broken, I would assume that it's
>> >> because .gz files are binary, but cat is treating them as text.
>> cat shouldn't care.
>Of course it would. Remember C-z?
"cat" is a Unix program, and on Unix, ^Z is just another character that
can be part of any file, at any point in the file. (Or at least, the OP
was talking about using it on Unix.)
>Yes. AFAIK, binmode/textmode (=newline translation) is orthogonal to
>(non)buffering (which is what read() is about) *on all the Perl platforms*.
I don't know that canonical Unix perl does any "newline translation". There's
no native reason to.
-s
--
Copyright 2001, All rights reserved. Peter Seebach / seebs@plethora.net
C/Unix wizard, Pro-commerce radical, Spam fighter. Boycott Spamazon!
Consulting & Computers: http://www.plethora.net/
------------------------------
Date: 5 Jan 2001 04:45:48 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Segmented Mac OS X dev tools
Message-Id: <933jhs$8e2$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Peter Seebach
<seebs@plethora.net>],
who wrote in article <3a5542da$0$12802$3c090ad1@news.plethora.net>:
> >> >> Assuming your perl script is not broken, I would assume that it's
> >> >> because .gz files are binary, but cat is treating them as text.
>
> >> cat shouldn't care.
>
> >Of course it would. Remember C-z?
>
> "cat" is a Unix program
??? What makes a program a "Unix program"?
, and on Unix, ^Z is just another character that
> can be part of any file, at any point in the file. (Or at least, the OP
> was talking about using it on Unix.)
If latter is true, then binmode is a NOP, so the whole discussion
would be void.
Ilya
------------------------------
Date: Fri, 05 Jan 2001 03:49:27 GMT
From: Pasquale <pdmos23@geocities.com>
Subject: sendmail on Exchange 5.5 mail server?
Message-Id: <3A55453C.8F78B9AD@geocities.com>
After a form is filled in and submitted, I would like a confirmation
e-mail sent to the person who filled out the form. I have no problem
doing this with '/usr/sbin/sendmail' on servers other than Windows
platform. However, for this occassion I am doing this for someone who
has MSSQL 7, Windows NT/2000 & an Exchange 5.5 mail server. My first
question is, can I use sendmail or is there some other command? Second,
would the Mail::Sendmail module be a better option or Net::SMTP?
Thanks,
Pasquale
------------------------------
Date: Fri, 05 Jan 2001 04:31:16 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: sendmail on Exchange 5.5 mail server?
Message-Id: <o6c56.677$B9.188499968@news.frii.net>
In article <3A55453C.8F78B9AD@geocities.com>,
Pasquale <pdmos23@geocities.com> wrote:
>After a form is filled in and submitted, I would like a confirmation
>e-mail sent to the person who filled out the form. I have no problem
>doing this with '/usr/sbin/sendmail' on servers other than Windows
>platform. However, for this occassion I am doing this for someone who
>has MSSQL 7, Windows NT/2000 & an Exchange 5.5 mail server. My first
>question is, can I use sendmail or is there some other command? Second,
>would the Mail::Sendmail module be a better option or Net::SMTP?
>Thanks,
I've used Net::SMTP to queue mail to an Exchange server (from a unix box).
It works fine. I suspect that it would also work from a win32
platform to the exchange box.
Good Luck
chris
--
This space intentionally left blank
------------------------------
Date: Fri, 05 Jan 2001 01:06:57 GMT
From: foopah@my-deja.com
Subject: Set IE5 default homepage WITHOUT JavaScript
Message-Id: <9336nc$d3o$1@nnrp1.deja.com>
I'm looking to find a way to set the default homepage for a browser
without using javascript.. or at least w/o displaying a page.
For example:
http://www.yahoo.com/bin/set
Click on that link with IE5, and you'll see that it automatically asks
to set your homepage and then kicks you to their site. I'm trying to
replicate this.
Ideas?
..jamie
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Fri, 05 Jan 2001 02:18:30 GMT
From: Dave Brondsema <brondsem@my-deja.com>
Subject: Re: Set IE5 default homepage WITHOUT JavaScript
Message-Id: <933ath$gdp$1@nnrp1.deja.com>
In article <9336nc$d3o$1@nnrp1.deja.com>,
foopah@my-deja.com wrote:
> I'm looking to find a way to set the default homepage for a browser
> without using javascript.. or at least w/o displaying a page.
>
> For example:
>
> http://www.yahoo.com/bin/set
>
> Click on that link with IE5, and you'll see that it automatically asks
> to set your homepage and then kicks you to their site. I'm trying to
> replicate this.
>
> Ideas?
No. This is a perl newsgroup. This question would be better asked in
comp.lang.javascript and/or comp.infosystems.www.authoring.html.
Secondly, why do you think that yahoo doesn't use javascript? I think
they do.
>
> ..jamie
>
> Sent via Deja.com
> http://www.deja.com/
>
--
Dave Brondsema
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Fri, 05 Jan 2001 05:26:10 GMT
From: foopah@my-deja.com
Subject: Re: Set IE5 default homepage WITHOUT JavaScript
Message-Id: <933ltd$pbb$1@nnrp1.deja.com>
I posted it here because I want to do it without javascript. Posting to
a javascript newsgroup won't do much good.
My CGI is in perl, and I'm thinking there is something I can do when
printing the document header via CGI.pm routines.
I don't think yahoo is using javascript, because they never
return/display a page... so something has to be done before they print
the "Location: http://www.yahoo.com\n\n" thing. Similar to how you
would set a cookie.
..jamie
In article <933ath$gdp$1@nnrp1.deja.com>,
Dave Brondsema <brondsem@my-deja.com> wrote:
> In article <9336nc$d3o$1@nnrp1.deja.com>,
> foopah@my-deja.com wrote:
> > I'm looking to find a way to set the default homepage for a browser
> > without using javascript.. or at least w/o displaying a page.
> >
> > For example:
> >
> > http://www.yahoo.com/bin/set
> >
> > Click on that link with IE5, and you'll see that it automatically
asks
> > to set your homepage and then kicks you to their site. I'm trying
to
> > replicate this.
> >
> > Ideas?
>
> No. This is a perl newsgroup. This question would be better asked in
> comp.lang.javascript and/or comp.infosystems.www.authoring.html.
> Secondly, why do you think that yahoo doesn't use javascript? I think
> they do.
>
> >
> > ..jamie
> >
> > Sent via Deja.com
> > http://www.deja.com/
> >
>
> --
> Dave Brondsema
>
> Sent via Deja.com
> http://www.deja.com/
>
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 4 Jan 2001 23:33:53 -0600
From: Bin - Lu <b0l4549@cs.tamu.edu>
Subject: socket in perl, help!!
Message-Id: <Pine.SOL.4.10.10101042323480.21362-100000@robert>
I'm having a hard time with the socket stuff in perl. I try to exchange
blocks of data via socket at client (in Perl) to another socket at server
(in C language). The data type in perl socket is an array(named
'sendbuf'). My code is as follows:
$sendbuf[0]=1;
$sendbuf[1]=1;
$sendbuf[2]=0;
$sendbuf[3]=36;
send(SOCK, @sendbuf, 4, 0);
But at the server end it displays it only gets 1 byte of data. What's the
problem?? Is the 'send' line correct?
Another question is that: How can I write data into a block in byte
format? Say, the first byte I want to put a number, and for the second and
third combined I want to put another number, and a character in the fourth
byte... All the bytes together are a block data, just like a buffer. Does
Perl allow me to do so?
I'd really appreciate it if someone can give me a hint.
Bin
------------------------------
Date: Thu, 4 Jan 2001 11:04:50 -0700
From: "Steve Wolfe" <steve@see-signature.com>
Subject: Sockets using threads, not forks
Message-Id: <muh239.4ac.ln@helix>
I'm trying to make an addition to my (meager) bag of tricks, but having a
hard time doing it.
I'm attempting to create a database query-caching engine, and things have
gone well so far except for one large hurdle - sharing the data between
multiple instances. I originally planned on forking off a child after
receiving a connection, but using shared memory to share the cache was (a)
being a pain in the butt, and (b) a potential bottleneck. Serializing and
de-serializing the complex data structure (of hundreds of megabytes) many
times per second didn't seem like the most efficient way of doing things.
So, I'm investigating simply spawning a thread for each connection,
instead of forking another instance. The part that's giving me fits is
getting each thread to take the socket and free up the master thread to
listen for new connections. Any pointers, tips, code, examples, or
suggestions would be more than welcome.
steve
--
------------------
domain for replies is "codon"
------------------------------
Date: Fri, 05 Jan 2001 04:54:35 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Sockets using threads, not forks
Message-Id: <fsc56.679$B9.190376960@news.frii.net>
In article <muh239.4ac.ln@helix>, Steve Wolfe <steve@see-signature.com> wrote:
>
> I'm trying to make an addition to my (meager) bag of tricks, but having a
>hard time doing it.
>
> I'm attempting to create a database query-caching engine, and things have
>gone well so far except for one large hurdle - sharing the data between
>multiple instances. I originally planned on forking off a child after
>receiving a connection, but using shared memory to share the cache was (a)
>being a pain in the butt, and (b) a potential bottleneck. Serializing and
>de-serializing the complex data structure (of hundreds of megabytes) many
>times per second didn't seem like the most efficient way of doing things.
>
> So, I'm investigating simply spawning a thread for each connection,
>instead of forking another instance. The part that's giving me fits is
>getting each thread to take the socket and free up the master thread to
>listen for new connections. Any pointers, tips, code, examples, or
>suggestions would be more than welcome.
>
This uses select looping rather than threads but there might be some hints
in it. It is from the manual page for IO::Select.
EXAMPLE
Here is a short example which shows how `IO::Select' could
be used to write a server which communicates with several
sockets while also listening for more connections on a
listen socket
use IO::Select;
use IO::Socket;
$lsn = new IO::Socket::INET(Listen => 1, LocalPort => 8080);
$sel = new IO::Select( $lsn );
while(@ready = $sel->can_read) {
foreach $fh (@ready) {
if($fh == $lsn) {
# Create a new socket
$new = $lsn->accept;
$sel->add($new);
}
else {
# Process socket
# Maybe we have finished with the socket
$sel->remove($fh);
$fh->close;
}
}
}
chris
--
This space intentionally left blank
------------------------------
Date: Thu, 04 Jan 2001 19:33:29 GMT
From: jamesdandy@my-deja.com
Subject: Re: Sorting a Text file Database with perl
Message-Id: <932j69$qo8$1@nnrp1.deja.com>
Thanks for the in depth reply. I think the key thing I was missing was
the array slices. That alone will cut the code down greatly.
Apparently from the replys written in half of the threads in this
forum, I will have to track down perldoc somewhere.
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Fri, 05 Jan 2001 05:00:54 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Troubleshooting flock failure
Message-Id: <ayc56.680$B9.192165888@news.frii.net>
In article <932654$7va$1@panix3.panix.com>, kj0 <kj0@mailcity.com> wrote:
>
>
>I'm having problems with a hanging flock call requesting an exclusive
>lock on a certain file. I can't see any obvious reason for this lock
>request to hang, since to my knowledge, there's no other process
>locking the file. How can I find out what is causing this flock call
>to hang?
>
The best thing to do here is to develop a small sample of code that
exhbits the problem and post it for review. It is even better if
the code works correctly except for the specific problem you are
having.
chris
--
This space intentionally left blank
------------------------------
Date: Fri, 05 Jan 2001 02:04:43 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: Re: Unitialised value error.
Message-Id: <%Y956.45565$xW4.364595@news-server.bigpond.net.au>
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:92v7up$eru$1@mamenchi.zrz.TU-Berlin.DE...
> PS: It would have been helpful if you had shown a little more of
> your code. Note how I had to guess things and offer alternatives
> to cover the possibilities. It is frustrating to you have to
> consider and explain various solutions of which only one will be
> useful.
I have managed to rewrite it down to 2.7k.
Still getting the same errors as I got in my full size.
(at least in one version).
Use of uninitialized value in numeric eq (==) at minefield.pl line 84
Use of uninitialized value in string ne at minefield.pl line 83.
The code is as follows.
#!f:/millenium programs/perl/bin/perl -w
use strict;
my (@cells, @mask, $xaxis, $yaxis, @xaxis, @yaxis, $i, $game, $pocket);
$cells[0][0] = 0;
$cells[0][1] = 0;
$cells[0][2] = 0;
$cells[0][3] = 1;
$cells[0][4] = 'B';
$cells[1][0] = 0;
$cells[1][1] = 0;
$cells[1][2] = 0;
$cells[1][3] = 1;
$cells[1][4] = 1;
$game = 'started';
do
{
$pocket = 'unopened';
do
{
$xaxis = int(rand(5));
$yaxis = int(rand(2));
if ($cells[$xaxis][$yaxis] eq 'B')
{
$mask[$xaxis][$yaxis] = $cells[$xaxis][$yaxis];
&printout;
print 'Bombed out';
$game = 'completed';
exit;
}elsif ($cells[$xaxis][$yaxis] > 0 && $cells[$xaxis][$yaxis] < 9){
$mask[$xaxis][$yaxis] = $cells[$xaxis][$yaxis];
&printout;
}elsif ($cells[$xaxis][$yaxis] == 0){
&expand_neighbours($xaxis,$yaxis);
&printout;
$pocket = 'opened';
}
}until $pocket eq 'opened';
}until $game eq 'completed';
sub printout
{
print "\n\n";
for($yaxis = 0; $yaxis < 2; $yaxis++)
{
for ($xaxis = 0; $xaxis < 5; $xaxis++)
{
print "$mask[$xaxis][$yaxis]";
}
print "\n";
}
}
sub expand_neighbours
{
$xaxis = $_[0];
$yaxis = $_[1];
# each cell with a zero automatically 'expands' its neighbours
# flush then start the list.
while (<@xaxis>){
pop(@xaxis);
pop(@yaxis);
}
push(@xaxis,$xaxis);
push(@yaxis,$yaxis);
# loop through the list and add neighbours that have a value of 0
for ($i = 0; $i < @xaxis; $i++)
{
# testing the cells on either side
# if the cell is not on the right hand side test the right hand neighbour
if ($xaxis[$i] != 5){
if ($cells[$xaxis[$i] + 1][$yaxis[$i]] ne 'B'){
if ($cells[$xaxis[$i] + 1][$yaxis[$i]] == 0){
push(@xaxis, $xaxis[$i] + 1);
push(@yaxis, $yaxis[$i]);
}
}
}
# if the cell is not on the left hand side test the left hand neighbour
if ($xaxis[$i] != 0){
if ($cells[$xaxis[$i] - 1][$yaxis[$i]] ne 'B'){
if ($cells[$xaxis[$i] - 1][$yaxis[$i]] == 0){
push(@xaxis, $xaxis[$i] - 1);
push(@yaxis, $yaxis[$i]);
}
}
}
}
# loop through the list and add neighbours that have a value of 1..8
for ($i = 0; $i < @xaxis; $i++)
{
# testing the cells on either side
# if the cell is not on the right hand side test the right hand neighbour
if ($xaxis[$i] != 5){
if ($cells[$xaxis[$i] + 1][$yaxis[$i]] ne 'B'){
if ($cells[$xaxis[$i] + 1][$yaxis[$i]] >=1 && $cells[$xaxis[$i] +
1][$yaxis[$i]] <= 8){
push(@xaxis, $xaxis[$i] + 1);
push(@yaxis, $yaxis[$i]);
}
}
}
# if the cell is not on the left hand side test the left hand neighbour
if ($xaxis[$i] != 0){
if ($cells[$xaxis[$i] - 1][$yaxis[$i]] ne 'B'){
if ($cells[$xaxis[$i] - 1][$yaxis[$i]] >= 1 && $cells[$xaxis[$i] -
1][$yaxis[$i]] <= 8){
push(@xaxis, $xaxis[$i] - 1);
push(@yaxis, $yaxis[$i]);
}
}
}
}
for ($i = 0; $i < @xaxis; $i++)
{
$mask[$xaxis[$i]][$yaxis[$i]] = $cells[$xaxis[$i]][$yaxis[$i]];
}
}
------------------------------
Date: Fri, 05 Jan 2001 06:47:11 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: Re: Unitialised value error.
Message-Id: <P5e56.45959$xW4.366618@news-server.bigpond.net.au>
"John Boy Walton" <johngros@Spam.bigpond.net.au> wrote in message
news:%Y956.45565$xW4.364595@news-server.bigpond.net.au...
> I have managed to rewrite it down to 2.7k.
> Still getting the same errors as I got in my full size.
> (at least in one version).
> Use of uninitialized value in numeric eq (==) at minefield.pl line 84
> Use of uninitialized value in string ne at minefield.pl line 83.
Typical I have been going cross eyed at this code for five days I post it
and see it a couple of hours later.
I am inverting the values at the start of the code for the array indices.
------------------------------
Date: Fri, 05 Jan 2001 07:01:10 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: Re: Unitialised value error.
Message-Id: <Wie56.45976$xW4.366988@news-server.bigpond.net.au>
"John Boy Walton" <johngros@Spam.bigpond.net.au> wrote in message
news:P5e56.45959$xW4.366618@news-server.bigpond.net.au...
> Typical I have been going cross eyed at this code for five days I post it
> and see it a couple of hours later.
> I am inverting the values at the start of the code for the array indices.
Bah! while I did have the xaxis and yaxis confused it has not fixed it.
------------------------------
Date: Thu, 4 Jan 2001 11:21:57 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: what does this mean?
Message-Id: <slrn9598p5.n5r.tadmc@magna.metronet.com>
Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote:
>Igor Aptekar wrote in comp.lang.perl.misc:
>> on the line where i do this $cat_list=split("=",$line)
Pattern matches should _look like_ pattern matches:
$cat_list=split(/=/,$line)
Whitespace is not a scarce resource, feel free to use as many as
you like to make your code easier to read:
$cat_list = split( /=/, $line ) # split() in scalar context
That is an awfully funny name. Makes it sound like it contains
a list, but it can't. It is a scalar.
What is it that you _want_ to get?
The number of fields is what you are getting in $cat_list with that code.
If you want to capture the list from split (the fields) into an array, then:
@cat_list = split( /=/, $line ) # split() in list context
>> I get the following warning
>>
>> [Thu Jan 4 12:51:06 2001]
>> D:\Documents\Projects\DrugDev\CategoryAdmin\Main.pl: Use of implicit split
>> to @_ is deprecated at D:\Documents\Projects\DrugDev\CategoryAdmin\Main.pl
>> line 55.
>
>split returns an array,
split() NEVER returns an array!
(you probably know that, but you did not say that...)
*None* of Perl's functions return arrays.
Perl FAQ, part 4:
"What is the difference between a list and an array?"
split() returns a _list_ in list context...
>not a scalar.
... and the "number of fields found" in a scalar context.
>See the documentation for split in
>the perlfunc manpage;
See the documentation for split in the perlfunc manpage :-)
---------------------
If not in list context, returns the number of fields found and splits into
the C<@_> array. (In list context, you can force the split into C<@_> by
using C<??> as the pattern delimiters, but it still returns the list
value.) The use of implicit split to C<@_> is deprecated, however, because
it clobbers your subroutine arguments.
---------------------
>see also perldiag for the diagnostic message
>you're getting.
or put
use diagnostics;
near the top of your program and run it again.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 4 Jan 2001 14:44:47 -0600 (CST)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: What's the Best Approach to this?
Message-Id: <9860-3A54E0BF-54@storefull-247.iap.bryant.webtv.net>
C'mon people! It took me a week to get this posted. I posted this 2
times before and it never showed. I'd really appreciate a response.
Thanks in advance,
Denni
------------------------------
Date: Thu, 4 Jan 2001 15:01:57 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: What's the Best Approach to this?
Message-Id: <slrn959lll.no8.tadmc@magna.metronet.com>
BUCK NAKED1 <dennis100@webtv.net> wrote:
>C'mon people!
What?
You are not owed any response. You make a post and merely hope
that someone helps you.
You cannot make demands of a newsgroup as you would of a help desk.
>It took me a week to get this posted.
And that is _our_ problem somehow?
>I posted this 2
>times before and it never showed.
We all saw it. It was not "lost".
>I'd really appreciate a response.
Sometimes you get one, sometimes you don't. That's how Usenet is.
"Why Questions go Unanswered":
http://perl.plover.com/Questions.html
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 5 Jan 2001 11:35:12 +1300
From: "Peter Sundstrom" <peter.sundstrom@eds.com>
Subject: Re: What's the Best Approach to this?
Message-Id: <932tr1$412$1@hermes.nz.eds.com>
BUCK NAKED1 <dennis100@webtv.net> wrote in message
news:9860-3A54E0BF-54@storefull-247.iap.bryant.webtv.net...
> C'mon people! It took me a week to get this posted. I posted this 2
> times before and it never showed. I'd really appreciate a response.
What is your Perl question?
------------------------------
Date: Fri, 05 Jan 2001 03:30:23 GMT
From: "David Sisk" <davesisk@ipass.net>
Subject: Re: What's wrong with this 2-child fork/wait?
Message-Id: <jdb56.529$7B.447688@typhoon.southeast.rr.com>
Thanks to everyone for the answers. The conceptual error is very clear once
it's explained so well!
What I want to do is have one parent process fork X number of child
processes and wait for all the children to complete. In other words, I want
to parallelize a portion of a job, then resynchronize after the parallel
part is done. Do I just need to loop on the wait until I get a -1 returned?
Or do I need to use some other structure, like a signal handler, or
something else? If I just loop on the wait until I get a -1, I'd guess that
a "hung" child would cause the parent process to wait forever. Is this
correct?
Please point me in the right direction?
Best regards,
Dave
David Sisk <davesisk@ipass.net> wrote in message
news:O3L46.76576$sr6.13539144@typhoon.southeast.rr.com...
> #!/usr/bin/perl -w
>
> # fork 1st child process
> if (!defined($kidpid = fork())) {
> # fork returned undef, so failed
> die "cannot fork: $!";
> }
>
> # fork 2nd child process
> if (!defined($kidpid = fork())) {
> # fork returned undef, so failed
> die "cannot fork: $!";
> }
>
> # if I'm a child, do this, otherwise, I must be the parent.
> if ($kidpid == 0) {
> # fork returned 0, so this branch is the child
> sleep 1;
> exec("echo I'm the child process");
> # if the exec fails, fall through to the next statement
> die "can't exec echo: $!";
> } else {
> print "I'm the parent process waiting\n";
> wait;
> print "I'm the parent process finished waiting\n";
> }
>
>
> The output that I get is:
> I'm the parent process waiting
> I'm the parent process waiting
> I'm the child process
> I'm the child process
> I'm the parent process finished waiting
> I'm the parent process finished waiting
>
> What I expected to get was:
> I'm the parent process waiting
> I'm the child process
> I'm the child process
> I'm the parent process finished waiting
>
> What am I doing wrong here?
>
> Best regards,
> Dave
>
>
>
------------------------------
Date: Thu, 4 Jan 2001 18:16:15 -0500
From: "Randy Harris" <harrisr@bignet.net>
Subject: Re: window NT and perl
Message-Id: <t5a10tcm1nf849@corp.supernews.com>
lvon <lvon5150@hotmail.com> wrote in message
news:ueX46.132113$I5.3339896@news1.rdc1.sdca.home.com...
> Win98 & WinNT are different, ie: C:\windows\system vs.
C:\winnt\system32.
> Because Perl has an install procedure, you'll need to 'install' on
WinNT,
> which
> is no big deal [unless it's someone elses' server]...
> You may copy your script, but just copying the Perl directory is
doomed for
> failure.
Not so. There are advantages to installing Perl, but it is not
necessary. I've had success running Perl programs on NT, by simply
copying the perl directory structure to systems on which I couldn't do a
real install.
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 5257
**************************************