[17904] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 64 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jan 15 14:05:50 2001

Date: Mon, 15 Jan 2001 11:05:13 -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: <979585512-v10-i64@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 15 Jan 2001     Volume: 10 Number: 64

Today's topics:
    Re: 8 letters (Tad McClellan)
    Re: Can't associate .PL files in Win98 <glburton@mindspring.com>
        exit sandywadkins123@my-deja.com
        exit sandywadkins123@my-deja.com
    Re: FAQ 8.44:   How do I open a file without blocking? (Chris Fedde)
    Re: Jobs: Senior Software Engineer <mischief@velma.motion.net>
    Re: Limits on array and hash storage nobull@mail.com
    Re: LWP::UserAgent with HTTP::Cookies not keeping cooki shiloam@pacbell.net
    Re: moving files from directories (Anno Siegel)
    Re: moving files from directories <chrekh@chello.se>
        Passing a parameter to a "sort" sub? (Mary Ellen Foster)
    Re: Passing a parameter to a "sort" sub? (Tad McClellan)
    Re: Random Numbers with a Twist (Duncan Murdoch)
    Re: Random Numbers with a Twist (Anno Siegel)
    Re: Random Numbers with a Twist <joe+usenet@sunstarsys.com>
    Re: Random Numbers with a Twist <joe+usenet@sunstarsys.com>
    Re: Random Numbers with a Twist (Craig Berry)
    Re: Regular Expression Question (Mike Stok)
    Re: Regular Expression Question (Tad McClellan)
    Re: Regular Expression Question nobull@mail.com
    Re: Regular Expression Question (Craig Berry)
        Remember variables through a form <jwcarlton@worldnet.att.net>
    Re: sed (unix) <Per-fredrik.Pollnow@epk.ericsson.se>
    Re: Split problem - great lesson (BUCK NAKED1)
    Re: Split problem - great lesson (Tad McClellan)
    Re: Split problem... a bit horsey (BUCK NAKED1)
    Re: Troubleshooting flock failure [CODE] (Anno Siegel)
    Re: What do you call the => operator? (Villy Kruse)
    Re: What do you call the => operator? <lwebbee@britcomtele.comnotreal>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Mon, 15 Jan 2001 10:24:51 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: 8 letters
Message-Id: <slrn9665i3.cm7.tadmc@tadmc26.august.net>

Per- Fredrik Pollnow <Per-fredrik.Pollnow@epk.ericsson.se> wrote:

>I was wondering if you guy's could help me out. 


If you show us your code, maybe we could.


>This is my mini scipt:
      ^^^^^      ^^^^^

No it isn't.


>user strict;
>my = ($name);


It does not compile.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Mon, 15 Jan 2001 10:05:14 -0800
From: Gary Burton <glburton@mindspring.com>
To: John Roth <johnroth@ameritech.net>
Subject: Re: Can't associate .PL files in Win98
Message-Id: <3A633BDA.A541401A@mindspring.com>


John Roth wrote:

> If it isn't finding the executable, the directory with the Perl executable
> isn't in your path, or the .lnk file for the DOS session doesn't specify the
> correct command - it must specify executing Perl from the proper directory
> with the .pl as it's object.
> 

	.lnk files are shortcuts.  I don't think they have any function in an association.  Do you perhaps mean a .PIF file?  If so, what would the name of the file be before the extension?  Is this file you are talking about it stored on disk, or just in RAM.

	I associated perl.exe using the browse window, so the path isn't wrong.
> 
> I'm going to have to try this! As you've figured out by now, the real
> problem is controlling whether the window closes when the program ends.
> Micro$oft doesn't seem to have given us quite enough control there. Pity,
> but then, we're talking about Micro$oft.
> 
	Please let me know how your experiment comes out.

	I know it isn't running the script because I now have a <stdin> in the script and it stops for input.  It must be running perl.  On my first launch after booting the computer, the disk rattles for a second or so before the DOS window opens.  Once it opens, it just flashes some error message about 6 words long, then closes.  

> >
> > Related questions:
> >     *   Have you ever actually SEEN the association work in Windows 98?
> If so, I will continue to fight the battle.  By the way, I have the first
> edition of Win98; but I don't think that matters.
> 
> It does work. The problem is with the DOS box, not with the association.
> BTW - there's no way of making an association
> work inside of the DOS box - it's just not part of the Windows
> specification. DOS only looks for .BAT, .EXE and so forth when it's looking
> for executables on the path. It completely ignores any associations.
> 
	
	That's what the other guy said, but I didn't want to accept it easily because the FAQ I referenced from the ActiveState website says specifically that it will work.  It sounds like you are telling me that you agree with the other guy, that the FAQ is wrong, and that I can never make the association do what I want.  Is that what you are saying?

> >     *   My c:\Perl\bin folder contains both Perl.exe and perl5.6.0.exe.
> Is there a difference?  If so, what is it?
> 
> Did you install it twice without uninstalling?

	No.  I only installed once.
> 
> >     *   "Learning Perl on Win32 Systems" recommends assigning a .PLX
> extension to the scripts as opposed to the .PL extension to avoid confusion
> with the Perl libraries.  Yet, the FAQ "How do I associate Perl scripts with
> Perl?" and all the examples show the .PL extension.  What do you think?
> 
> ActiveState could do a better job. The PL extension is for "Perl Libraries,"
> and shouldn't be overloaded for executables. Again, it doesn't really matter
> if you keep things separated.

	Thanks.  I guess I will continue to use the .PLX just for my own clarity.
> 
> To put all of this together so it makes sense: What happens when you
> double-click on a .pl file
> in Windows 9x is as follows.
> 
> 1. Windows looks up the .pl extension in the registry, and finds the
> command, which is "perl %1".
> 2. Since perl is a DOS program, Windows builds a .lnk file for the .pl file.
> This .lnk contains default parameters for DOS
> 3. Windows launches DOS, using the expanded "perl %1" command as the initial
> command to execute.
> 4. The DOS box attempts to find perl.exe, either on the path or in the
> working directory
> 5. If it finds it, it runs it.
> 6. When the command completes, the DOS box shuts down, preventing you from
> seeing anything you've written to STDOUT.
> 

	Now I'm even more confused.  This seems to say that you believe it is running my script.  If that's the case, a <stdin> or sleep 10 would have stopped it.  It also seems to contradict what you said above.  Maybe I am just having a hard time following.  Please explain, if you haven't lost patience with me yet.

	Thanks.


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

Date: Mon, 15 Jan 2001 18:46:01 GMT
From: sandywadkins123@my-deja.com
Subject: exit
Message-Id: <93vgh7$s3b$1@nnrp1.deja.com>

Perl 5, HTML, little java script.

Ok I wrote scripts making each user have a temp. file (xxx.dat). When
they sumit it updates a file, then gets deleted.

Question: if they don't submit and close it the file is hanging out
there. So how can I capture when they exit?

thanks sandy


Sent via Deja.com
http://www.deja.com/


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

Date: Mon, 15 Jan 2001 18:46:12 GMT
From: sandywadkins123@my-deja.com
Subject: exit
Message-Id: <93vghh$s3k$1@nnrp1.deja.com>

Perl 5, HTML, little java script.

Ok I wrote scripts making each user have a temp. file (xxx.dat). When
they sumit it updates a file, then gets deleted.

Question: if they don't submit and close it the file is hanging out
there. So how can I capture when they exit?

thanks sandy


Sent via Deja.com
http://www.deja.com/


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

Date: Mon, 15 Jan 2001 18:20:02 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: FAQ 8.44:   How do I open a file without blocking?
Message-Id: <mbH86.969$B9.192940544@news.frii.net>

In article <Xns902AA9AA1fightagainstspamcuth@195.141.200.222>,
Reto Hersiczky <fight_against_spam_cut_here_retoh@dplanet.ch> wrote:
>
>Could pls. somebody explain any sense for reading a file without blocking
>besides a real-time application? As far as I can imagine, this mode makes
>no sense in a CGI/modperl-based application. Tell me, if I'm wrong.
>--Reto
>
>

I think that you lack creativity.  What if the cgi checks to
see if there is data avaialble on some serial port?  

chris
-- 
    This space intentionally left blank


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

Date: Mon, 15 Jan 2001 16:09:22 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Jobs: Senior Software Engineer
Message-Id: <t6685il8a73qa0@corp.supernews.com>

Abigail <abigail@foad.org> wrote:
> Chris Stith (mischief@velma.motion.net) wrote on MMDCXCII September
> MCMXCIII in <URL:news:t5vp3gdb1d4obc@corp.supernews.com>:
> || 
> || On the other hand, Tom C., Randal S., Ilya Z., Mark Jason D., and
> || others do post here. I couldn't offer any of them enough money,
> || either, but they do participate in the group and therefore
> || could be considered part of the target market for recruiting
> || from this group. I'd say they each have plenty of Perl experience.


> I post here as well. But I won't let myself be hired by someone who is
> clueless. Posting job ads here shows cluelessness.

Yes, it does. My posts in this thread have been almost entirely about
how a technical group could be used for recruiting WITHOUT posting a
job ad.

I never claimed using a group such as this was a good idea. I only
mentioned ways a recruiter might be able to use a technical group
that are more constructive than posting ads, if said recruiter was
so inclined.

Another poster mentioned lurkers, and the fact that since they
don't post you can't tell what they know. Again, this is the same
issue I've responded to before. Just because someone who does
know something about Perl doesn't post doesn't subtract experience
or knowledge from people who do post. The only way to reach lurkers
is to post something they can read, which as we've already discussed
is bad form and just plain rude to boot when that means an ad.

I have seen a FAQ for this newsgroup. Perhaps we need more frequent
postings about how to find the FAQ, and a section in the FAQ on
more appropriate places to look for employment/employees. This will
not eliminate the traffic of this sort, since this is usually done
by rude people who don't even read the group and just post to
anything with 'perl' in the name of the group. It might help a little,
though.

Anyway, this is the sort of thread that always outlasts any actual
technical threads. Perhaps we should call this a political/procedural
newsgroup instead of a technical one. ;)

Chris

-- 
Christopher E. Stith

Programming is a tool. A tool is neither good nor evil. It is
the user who determines how it is used and to what ends.



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

Date: 15 Jan 2001 17:49:46 +0000
From: nobull@mail.com
Subject: Re: Limits on array and hash storage
Message-Id: <u9d7do4sed.fsf@wcl-l.bham.ac.uk>

William Cardwell <EUSWMCL@am1.ericsson.se> writes:

> I notice that large arrays and hashes are commonly used in Perl. I do
> the same and have not yet hit limits. Am I really using only ram?

We can only really guess, but it seems unlikely to me that you are
using an operating system that doesn't have some sort of virtual memory
mecahnism in use.

This doesn't really have anything to do with Perl.

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


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

Date: Mon, 15 Jan 2001 18:51:48 GMT
From: shiloam@pacbell.net
Subject: Re: LWP::UserAgent with HTTP::Cookies not keeping cookies ???
Message-Id: <93vgs0$sa5$1@nnrp1.deja.com>

In article <93tsv9$igh$1@nnrp1.deja.com>,
  snakedjip@yahoo.com wrote:
> Hello,
>
> Straight to the point, here's my code :
>
> use LWP::UserAgent;
> use LWP::Debug qw(+conns +trace +debug);
> use HTTP::Cookies;
> my $ua = new LWP::UserAgent;
> my $req = new HTTP::Request 'GET','http://<MyIp>:8081/default.asp';
> my $res = $ua->request($req);
> my $cookie_jar = new HTTP::Cookies;
> $cookie_jar->extract_cookies($res);
> print "\n\nCookies: " . $cookie_jar->as_string . "\n\n";
>
> print header;
> if ($res->is_success) {
>     my $req = new HTTP::Request 'GET'
> => 'http://<MyIp>:8081/default.asp';
>     $cookie_jar->add_cookie_header($req);
>     $res = $ua->request($req);
>     if ($res->is_success){
> 	$response = $res->as_string;
> 	print $response;
>     }
> } else {
>     print $res->status_line;
> }
>
> THE PROBLEM :
> -------------
>
> When I access this default page with a browser for the first time,
> since this is a Microsoft ASP page, a cookie is sent to my browser to
> identify the session id.  If I "reload" the page in the browser, that
> cookie is sent to the server upon its request for it...  I verified in
> the server's log, and the cookie appears in it (with the W3C extended
> logging enabled in IIS, this is possible...)
>
> So far so good.
>
> Now, I want to reproduce this behaviour with LWP::UserAgent and
> HTTP::Cookies.
>
> So (commenting my code here...), I "GET" the url a first time, I
create
> the HTTP::Cookies object to store the received session id, and when I
> try to re-GET the page, for some reason, $cookie_jar-
>add_cookie_header
> ($req) doesn't do the job.  The cookie is never sent to the server.
In
> fact, the $cookie_jar->as_string method returns NOTHING !
>
> WHY ?
>
> I tried the same code on another site and it works just fine...
>
> Is it because my URL is constructed with a numeric IP instead of a
> domain name ?
>
> Is it because my server is on port 8081 ?
>
> Any help would be greatly appreciated.  Thank you for your time.
>
> Sent via Deja.com
> http://www.deja.com/
>

Cookies are the domain of the Browser as such are client objects under
the clients control. When a browser 'visits' a site, in other words, it
issues a GET request on a URL, it looks at it's cookie table to see if
it has any matching cookies for that particular 'domain'. However since
the only way for the browser to determine the domain is to look at the
URL, then it is dependent upon it. So yes, therefor, it is that you are
using the IP address and not the name, if you change the GET to use the
server's name it will work, because the browser will name and set the
cookie accordingly. If you don't have a resolvable route on that
machine, just use the 'hosts' file and add that particular server.

There are other dependencies, such as path, but I don't think this is
your particular issue. Good luck.


Sent via Deja.com
http://www.deja.com/


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

Date: 15 Jan 2001 17:19:08 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: moving files from directories
Message-Id: <93vbec$ekd$1@mamenchi.zrz.TU-Berlin.DE>

Michael Schlueter <Michael.Schlueter@philips.com> wrote in comp.lang.perl.misc:
>For the first part of your question check out the Unix find command (man
>find). From Perl you envoke it by the backticks, e.g:
>
>    `find * -exec mv {} dir \;` ;

Since you don't need the output of "find", why do you recommend backticks?
Use system(), if you must, though I don't think the OP wants to recurse
through directories.  As I understand the problem, a simple readdir()
would suffice.  On the other hand, you don't even attempt to account
for file age in your solution.

>Second part: there are many ways to find out the first letter of the file
>name, like using a regular expression or returning a substring.

Your "second part" must be considered along with the first part.
The find-command in your proposal has already moved all the files
into one single directory (dir), thereby destroying files with equal
names in different subdirectories.  

Summary: Your solution is badly written, doesn't solve the problem,
and is destructive.  Please invest a little more thought in future
replies.

Anno


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

Date: Mon, 15 Jan 2001 17:59:50 GMT
From: Christer Ekholm <chrekh@chello.se>
Subject: Re: moving files from directories
Message-Id: <864rz08zrz.fsf@jane.localdomain>

Blossom Coryat <bac2@duke.edu> writes:

> hi everyone, another newbie here.
> How would i move files that are 2weeks old in a directory into a 
> sub-directory within that same directory according to the first letter 
> of the file name?
> 
> thanks, 
> Blossom
> bac2@duke.edu



use warnings;
use strict;
use constant ONE_WEEK => 60*60*24*7;

opendir(DIR,".") || die "opendir . failed: $!";

while (my $file = readdir(DIR)) {
    next if ( $file =~ /^\.{1,2}$/ );
    if ( (stat($file))[9] + ONE_WEEK < time ) {
	my $dir = substr($file,0,1);
	unless ( -d $dir ) {
	    mkdir($dir) || warn "mkdir $dir failed: $!\n";
	}
	rename($file,"$dir/$file") || warn "mv $file to $dir failed: $!\n";
    }
}
				 


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

Date: 15 Jan 2001 17:27:51 GMT
From: mef@cogsci.ed.ac.uk (Mary Ellen Foster)
Subject: Passing a parameter to a "sort" sub?
Message-Id: <93vbun$2j8b$1@pc-news.cogsci.ed.ac.uk>

Is it possible to pass parameters to a sort subroutine? Here's an example
of what I was thinking of -- here, %results is a hash that contains (among
other things) four fields with times represented as strings in "H:MM:SS"
format (triathlon results I'm fooling around with, if you care). I wanted
to be able to sort them by each of those fields, and I'd hoped that I could
reuse the same sort sub for all of them.

Non-compiling code below:

    # The next line is line 31:
    foreach my $key ( sort bytime('total') ( keys %results )) {
        print $key . ': ' . $results{$key}->{name} . "\n";
    }

    sub bytime {
        my $field = shift;
        @afields = split /:/, $results{$a}->{$field};
        @bfields = split /:/, $results{$b}->{$field};
        return $afields[0] <=> $bfields[0]
            || $afields[1] <=> $bfields[1]
            || $afields[2] <=> $bfields[2];
    }

Result of trying to run the above:
    syntax error at ./process-results.pl line 31, near ") ("
    Execution of ./process-results.pl aborted due to compilation errors.

Given what it says in "perldoc -f sort" about the subroutine-calling
mechanism being munged for use in sort, I suspect that something like the
above isn't possible. But just in case I'm doing something stupid, I
figured I'd ask...

Thanks!

MEF

-- 
Mary Ellen Foster  /  ICCS  /  Informatics  /  University of Edinburgh
M.E.Foster@ed.ac.uk         http://www.iccs.informatics.ed.ac.uk/~mef/
-------------------- Law of Software Envelopment: --------------------
        Every program attempts to expand until it can read mail. 


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

Date: Mon, 15 Jan 2001 11:24:18 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Passing a parameter to a "sort" sub?
Message-Id: <slrn96691i.crn.tadmc@tadmc26.august.net>

Mary Ellen Foster <mef@cogsci.ed.ac.uk> wrote:
>Is it possible to pass parameters to a sort subroutine?

Nope.

>Given what it says in "perldoc -f sort" 


You could adapt the Schwartzian Transform given there
(the "# same thing, but without any temps" part) to
do what you want.

I think.

If you had provided a data structure to test it with, I would
be giving code to do it here, but you didn't, so I'm not  :-(

Load up a _small_ data structure, use Data::Dumper to show
it to us, show an example of the output it should make,
and code can be yours.


>But just in case I'm doing something stupid, I
>figured I'd ask...


What you want is possible.

Using args for the sort() subroutine is not a way of getting
there though.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Mon, 15 Jan 2001 11:40:54 -0500
From: murdoch@fisher.stats.uwo.ca (Duncan Murdoch)
Subject: Re: Random Numbers with a Twist
Message-Id: <3a6327dd.244523064@newshost.uwo.ca>

On Mon, 15 Jan 2001 10:53:08 -0800, "Shawn Coppock"
<coppocks@bellsouth.net> wrote in message
<RZE86.288$zc4.21022@news2.mco>:

>I can yank random numbers from ranges etc. all day. But now, I need a little
>more and I am tripping to solve this one.
>
>#Problem:
>
>Lets say I need to generate 60 random pairs of numbers ($x,$y) ... where $x
>is from a range of 1..1200 and $y is from a range of 1..800. Consider these
>pairs as a random point or coordinate on a grid of 1200x800.
>
>In addition to this, each pair must be unique, in that
>1. no pair can be the same
>2. no pair can be within 30 of another
>
 ...
>I don't want the pairs/coordinates to be perfectly spaced by 30. There's no
>need because at 1200x800 there are 960k available points... and if no two
>are within 30 of another, there are still 320k possibilities.

You might want to narrow down your requirements a little more, and
then ask this question in sci.stat.math.

Explain how many points you want in your sample.

Explain why choosing one point completely at random, then as many as
desired from a grid with a spacing of 30 would not be acceptable.

More generally, explain what you hope to do with the numbers, because
there are lots of "random" distributions with different properties;
maybe some are okay and some aren't.

If you aren't very picky about the exact distributional properties,
then one way to get a random looking sample is to maintain an array of
legal positions, and a count of how many there are.  Generate a number
from 1 to the count; put your sampled pair at the corresponding
position, and mark all the neighbours as illegal, reducing the count.
Keep going until your sample is big enough, or there are no more legal
positions.  This *does not* generate a sample that's drawn uniformly
from all possible samples, but for most purposes it would be good
enough.

Followups to sci.stat.math.

Duncan Murdoch


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

Date: 15 Jan 2001 16:47:15 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Random Numbers with a Twist
Message-Id: <93v9ij$d0d$1@mamenchi.zrz.TU-Berlin.DE>

Shawn Coppock <coppocks@bellsouth.net> wrote in comp.lang.perl.misc:
>I can yank random numbers from ranges etc. all day. But now, I need a little
>more and I am tripping to solve this one.
>
>#Problem:
>
>Lets say I need to generate 60 random pairs of numbers ($x,$y) ... where $x
>is from a range of 1..1200 and $y is from a range of 1..800. Consider these
>pairs as a random point or coordinate on a grid of 1200x800.
>
>In addition to this, each pair must be unique, in that
>1. no pair can be the same
>2. no pair can be within 30 of another

The second condition implies the first one, so you'll just have to worry
about condition 2.

>#Example:
>
>Pair 1: 50,100
>Pair 2: 32,135
>Pair 3: 31,130
>etc..
>
>Assuming that the pair numbers are checked before being added to a final
>list...
>
>Pair 2 is ok because only one number is within 30 of Pair 1. But, Pair 3 is
>NOT ok, because both numbers are within 30 of another pair (Pair 2).
>
>
>I don't want the pairs/coordinates to be perfectly spaced by 30. There's no
>need because at 1200x800 there are 960k available points... and if no two
>are within 30 of another, there are still 320k possibilities.

Well, you could conceptually tile your rectangle with 30x30 squares,
and select 60 of those at random. Then, in a second step, select a
random point in each preselected square.

I don't know what statistical properties to expect from a distribution
generated this way.  Nor am I sure what to do with the partial squares
that turn up along the edges.  You will probably have to select a
"square" with a probability proportional to its area.

Anno


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

Date: 15 Jan 2001 12:14:22 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Random Numbers with a Twist
Message-Id: <m3g0ikzqj5.fsf@mumonkan.sunstarsys.com>

"Shawn Coppock" <coppocks@bellsouth.net> writes:

> #Problem:
> 
> Lets say I need to generate 60 random pairs of numbers ($x,$y) ... 
> where $x is from a range of 1..1200 and $y is from a range of 1..800. 
> Consider these pairs as a random point or coordinate on a grid of 
> 1200x800.
> 
> In addition to this, each pair must be unique, in that
> 1. no pair can be the same

Ignoring (2), why not try to solve this problem first? Explicitly, can 
you write a perl sub that grabs 60 unique, arbitrarily chosen points 
from your grid?

> 2. no pair can be within 30 of another

To solve (2), a minor perturbation of the solution to (1) should work
(it's the same class of problem since 60 15x15-squares is only about 
1% of the total area of your grid).

> I don't want the pairs/coordinates to be perfectly spaced by 30. There's 
> no need because at 1200x800 there are 960k available points... and if no 
> two are within 30 of another, there are still 320k possibilities.

Not sure your figures make much sense- if you are talking about 60 points,
there are considerably more possibilities than that (think binomial
coefficients); if you're only talking about one point, spacing between 
points is not an issue.


HTH
-- 
Joe Schaefer


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

Date: 15 Jan 2001 12:27:08 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Random Numbers with a Twist
Message-Id: <m3bst8zpxv.fsf@mumonkan.sunstarsys.com>

Joe Schaefer <joe+usenet@sunstarsys.com> writes:

> > 2. no pair can be within 30 of another
> 
> To solve (2), a minor perturbation of the solution to (1) should work
> (it's the same class of problem since 60 15x15-squares is only about 
                                           ^^^^^

Looks like my math's pretty fuzzy, too. You need 60 30x30-squares,
which amounts to about 5% of the total area.  Same difference :)

-- 
Joe Schaefer



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

Date: Mon, 15 Jan 2001 18:40:52 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Random Numbers with a Twist
Message-Id: <t66h1ki1035vce@corp.supernews.com>

Shawn Coppock (coppocks@bellsouth.net) wrote:
: Lets say I need to generate 60 random pairs of numbers ($x,$y) ... where $x
: is from a range of 1..1200 and $y is from a range of 1..800. Consider these
: pairs as a random point or coordinate on a grid of 1200x800.
: 
: In addition to this, each pair must be unique, in that
: 1. no pair can be the same
: 2. no pair can be within 30 of another

The following doesn't do much error checking, and will loop infinitely if
presented with an impossible task (80 point on a 10 by 10 grid, separated
by 3, for example).

#!/usr/bin/perl -w
# scatter - generate separated pairs of cartesian coords (for clpm)
# Useage: scatter <width> <height> <count> <minsep>
#   Where...
#      width and height are the dimensions of the 'field'
#      count is the number of points to be generated
#      minsetp is the minimum horizontal and vertical separation between points
# Output:  List of coordinate pairs on stdout
# Craig Berry (20010115)

use strict;

die "Useage: scatter width height count minsep\n" unless @ARGV == 4;

my ($width, $height, $count, $minsep) = @ARGV;
my @points;

POINT:
while (@points < $count) {
  my $p1 = [ int rand $width, int rand $height ];

  foreach my $p0 (@points) {
    next POINT if abs($p1->[0] - $p0->[0]) <= $minsep &&
                  abs($p1->[1] - $p0->[1]) <= $minsep;
  }

  push @points, $p1;
}

print "$_->[0], $_->[1]\n" foreach @points;


-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "The hills are burning, and the wind is raging; and the clock
   |   strikes midnight in the Garden of Allah." - Don Henley


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

Date: Mon, 15 Jan 2001 15:52:04 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Regular Expression Question
Message-Id: <E0F86.3996$nb4.239731@typhoon.austin.rr.com>

In article <93v2s7$f9c$1@nnrp1.deja.com>,
Bob Simon  <bob_simon@my-deja.com> wrote:
>In article <slrn96403g.acl.tadmc@tadmc26.august.net>,
>  tadmc@augustmail.com wrote:
>> Bob Simon <bob_simon@my-deja.com> wrote:
>>
>> >b) [A-Za-z]* means zero or more occurrences of any capital
>> >or small letter and appears to match the null string.
>> >
>> >For consistency, it seems like [A-Za-z]* should match the
>> >first n letters in a line, up to the first space, or
>> >non-alphabetic char.  Where is the error in this logic?
>>
>> It matches at the first opportunity.
>
>You realize, of course, that .* does NOT match at the first
>opportunity -- it matches the longest string possible.  My
>only issue here is one of inconsistency.

It matches the leftmost longest string, so if the first character of the 
string doesn't match the "atom" quantified by the * you'll get a zero 
length match:

  DB<1> $s = "\nfoo bar baz"

  DB<2> print "matched" if ($match) = $s =~ /(.*)/
matched
  DB<3> print length $match
0

so the match succeeds in matching 0 times.  If the first character matches 
the atom * will greedily consume as much as it can e.g.

  DB<4> $s = '123abc'

  DB<5> print "matched" if ($match) = $s =~ /([A-Za-z]*)/
matched
  DB<6> print length $match
0
  DB<7> $s = 'abc 123'

  DB<8> print "matched" if ($match) = $s =~ /([A-Za-z]*)/
matched
  DB<9> print length $match
3

Hope this helps,

Mike
-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |
GPG PGP Key 1024D/059913DA         | Fingerprint      0570 71CD 6790 7C28 3D60
stok@colltech.com (CT - work)      |                  75D2 9EC4 C1C0 0599 13DA


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

Date: Mon, 15 Jan 2001 10:21:31 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Regular Expression Question
Message-Id: <slrn9665br.cm7.tadmc@tadmc26.august.net>


[ Please do NOT send stealth Cc's. It is not nice. 

  Please do not quote an entire article.

  Please do not quote .sigs.

  Please see:    http://www.geocities.com/nnqweb/nquote.html

  Thank you.
]


Bob Simon <bob_simon@my-deja.com> wrote:
>In article <slrn96403g.acl.tadmc@tadmc26.august.net>,
>  tadmc@augustmail.com wrote:
>> Bob Simon <bob_simon@my-deja.com> wrote:
>>
>> >b) [A-Za-z]* means zero or more occurrences of any capital
>> >or small letter and appears to match the null string.
>> >
>> >For consistency, it seems like [A-Za-z]* should match the
>> >first n letters in a line, up to the first space, or
>> >non-alphabetic char.  Where is the error in this logic?
>>
>> It matches at the first opportunity.
>
>You realize, of course, that .* does NOT match at the first
>opportunity 


I do not realize that. In fact, the point I was trying to make
was that it does NOT match as you seem to think it does!


>-- it matches the longest string possible.  


No, it matches at the first opportunity, as I said:

---------------------
#!/usr/bin/perl -w
use strict;

$_ = '123abc';
if ( /[A-Za-z]*/ ) {
   print "matched '$&'\n";
}
---------------------

output:

matched ''



You did not test my assertion with a Perl program, it appears...

Replace the if() with while() and m//g for yet more insights:

   while ( /[A-Za-z]*/g ) {


>My
>only issue here is one of inconsistency.


My point was that you have issues that you are unaware of.
I was trying to make you aware of them  :-)


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 15 Jan 2001 17:48:43 +0000
From: nobull@mail.com
Subject: Re: Regular Expression Question
Message-Id: <u9g0ik4sg4.fsf@wcl-l.bham.ac.uk>

Bob Simon <bob_simon@my-deja.com> writes:

> I'm told that the experts on regular expressions can be
> found here so I hope one of you folks can answer a question
> for me.  I'm teaching myself unix (RH7) and cannot reconcile
> the following behavior:
> 
> a) .* means zero or more occurrences of any character and
> matches everything between ^ and $ (the entire line).
>
> b) [A-Za-z]* means zero or more occurrences of any capital
> or small letter and appears to match the null string.
> 
> For consistency, it seems like [A-Za-z]* should match the
> first n letters in a line, up to the first space, or
> non-alphabetic char.  Where is the error in this logic?

There is none.  

Assuming the above REs are being used as complete search patterns then
everything above is self-consistant and implies that n=0.

You are probably making some further observations and drawing some
further inferrences beyond what you've stated here and the error is in
_that_ logic.  Obviously we can't find an error in your logic without
seeing the logic in question.

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


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

Date: Mon, 15 Jan 2001 18:08:56 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Regular Expression Question
Message-Id: <t66f5o74l08jb1@corp.supernews.com>

Bob Simon (bob_simon@my-deja.com) wrote:
: In article <slrn96403g.acl.tadmc@tadmc26.august.net>,
:   tadmc@augustmail.com wrote:
: > Bob Simon <bob_simon@my-deja.com> wrote:
: > >For consistency, it seems like [A-Za-z]* should match the
: > >first n letters in a line, up to the first space, or
: > >non-alphabetic char.  Where is the error in this logic?
: >
: > It matches at the first opportunity.
: 
: You realize, of course, that .* does NOT match at the first
: opportunity -- it matches the longest string possible.  My
: only issue here is one of inconsistency.

Well, it starts at the leftmost opportunity, matching as much as possible.
"Leftmost" and "first" can be seen as equivalent.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "The hills are burning, and the wind is raging; and the clock
   |   strikes midnight in the Garden of Allah." - Don Henley


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

Date: Mon, 15 Jan 2001 17:58:59 GMT
From: "Eric Baird" <jwcarlton@worldnet.att.net>
Subject: Remember variables through a form
Message-Id: <DTG86.4615$LZ1.330784@bgtnsc05-news.ops.worldnet.att.net>

Hey, guys, this might seem pretty basic, but for some reason my CGI is
giving me a lot of stress today. I'm hoping maybe a fresh mind will see the
obvious mistake I'm making.

Imagine a simple form in a CGI, using checkboxes. When I check off something
and click Submit, I'm going to need to print off the item that I checked
off. Here's a simplified version of what's written:

# Original HTML print screen

<form action=$form method="POST">    # $form is the url of the script
<input type="hidden" name="action" value="process1">    # where "process1"
is the first subdirectory
<input type=text name=variable1 size=20>
</form>

# 1st Process

$cookielog = "$contents{'variable1'}";
&SetCookies('variable',$cookielog);

print "<form action=$form method="POST">\n";
print "<input type="hidden" name="action" value="process2">\n";    # where
"process2" is the 2nd subdirectory
print "<table><tr>\n";
print "<td valign=middle>$contents{'variable1'}</td><td valign=middle><input
type=checkbox name=item1></td>\n";
print "</tr></table>\n";
print "<input type=submit value=Continue></form>\n";

# Processing subdirectory

&GetCookies('variable');

$viewcookie = "$Cookies{'variable'}";
@nvpairs = split(/\|/, $viewcookie);

foreach $pair (@nvpairs) { ($variable) = split(/:/, $pair); }

print "Content-type: text/html\n";

if ($contents{'item1'}) {
    print "Variable: $variable1\n";
 }

Of course, this is a very simplified version of what I'm doing, I realize
that if this was all I wanted then there are easier ways around it. But all
of this is going somewhere in a much larger script, and it's really starting
to make me ill that this little part isn't working! Talk about
brain-fried...

FWIW, the hope is that when an item is checked off, it will either be
written or deleted from a data file, but the script isn't keeping the
variable long enough to get to the write script.

Thanks for any help, all. If you need more information about the exact code,
please feel free to ask.

Thanks again,

Jason




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

Date: Mon, 15 Jan 2001 18:45:20 +0100
From: "Per- Fredrik Pollnow" <Per-fredrik.Pollnow@epk.ericsson.se>
Subject: Re: sed (unix)
Message-Id: <93vd6r$7c8$1@newstoo.ericsson.se>

Thanx
"Per- Fredrik Pollnow" <Per-fredrik.Pollnow@epk.ericsson.se> wrote in
message news:93n9ko$5be$1@newstoo.ericsson.se...
> Thanks...
>  It workt :=)
>
> "Rafael Garcia-Suarez" <rgarciasuarez@free.fr> wrote in message
> news:slrn95u10a.ho.rgarciasuarez@rafael.kazibao.net...
> > Per- Fredrik Pollnow wrote in comp.lang.perl.misc:
> > > Hi,
> > > (OS/UNIX)
> > > I was wondering, how do I do this in perl:
> > >
> > > sed -e '/^gunde:/s/\*LK\*/tada/' < shadow >shadow.new
> >
> > There's a program that comes with Perl that translates sed scripts to
> > perl. Its name is s2p.
> >
> > But, if you want a Perl one-liner :
> >
> >   perl -pe '/^gunde:/&&s/\*LK\*/tada/' < shadow > shadow.new
> >
> > The difference is in only three characters.
> >
> > --
> > # Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
>
>




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

Date: Mon, 15 Jan 2001 10:41:13 -0600 (CST)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: Split problem - great lesson
Message-Id: <21910-3A632829-11@storefull-244.iap.bryant.webtv.net>

Sorry about another post. I just saw Tad's great examples. What a great
lesson on splitting! I printed it out and saved it. I really liked that
last example and ended up using it in my code as such:

@list = `unzip -qol $file -d $dir`; @lis = split( ' ', $list[2] ); 
print $lis[3];

--Regards,
Dennis



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

Date: Mon, 15 Jan 2001 10:41:17 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Split problem - great lesson
Message-Id: <slrn9666gt.coh.tadmc@tadmc26.august.net>

BUCK NAKED1 <dennis100@webtv.net> wrote:

>Sorry about another post. I just saw Tad's great examples. What a great
>lesson on splitting!


All it was was a translation of what the docs said into Perl code.

So it is the docs that are a Great Lesson, not what some guy
on Usenet says.

You should have been able to make code corresponding to the
things described in "perldoc -f split" too.

Try stuff. Experiment. See. Learn. (post only after all of that)

:-)


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Mon, 15 Jan 2001 10:15:40 -0600 (CST)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: Split problem... a bit horsey
Message-Id: <21909-3A63222C-30@storefull-244.iap.bryant.webtv.net>

Thanks all. From your examples, I was able to go back and study perlfunc
split, and get my script to work. There must've been something wrong
with that first array that I was trying to use because when I used a
different array I was able to extract just the directory name. Here's
the code I ended up with... probably a better way, I know.

@list = `unzip -qol $file -d $dir`; 
$_ = "$list[2]";
@lis = split();
print "file unzipped  to directory 
<a href=http://www.vc.net/temp/$dir/$lis[3]>
http://www.vc.net/temp/$dir/$lis[3]</a>";

OR...

$_ = "$list[2]";
@lis = split();
print "<BR>$lis[3]";

Regards,
Dennis



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

Date: 15 Jan 2001 16:24:09 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Troubleshooting flock failure [CODE]
Message-Id: <93v879$bo4$1@mamenchi.zrz.TU-Berlin.DE>

kj0  <kj0@mailcity.com> wrote in comp.lang.perl.misc:
>
>
>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.  Here's the relevant code snippet:

[snip code]

Very well... runnable code.  Running it, I get exactly the expected
response:  A single run acquires the lock, a second one times out
(when you make the first job hang around long enough).

It seems your code is fine.  Either there *is* a second process
with a lock on the file (fuser can help determining this, if you
have fuser), or flock doesn't work as advertised on your system.

Anno


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

Date: 15 Jan 2001 16:36:44 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: What do you call the => operator?
Message-Id: <slrn9669os.6nt.vek@pharmnl.ohout.pharmapartners.nl>

On 15 Jan 2001 10:40:52 GMT, Abigail <abigail@foad.org> wrote:

>
>
>IDO.
>

Care to expand?  Don't know what IDO is.

Villy


>
>Abigail
>-- 
>``infix dereference operator'' (from man perlop)


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

Date: Mon, 15 Jan 2001 18:53:54 +0000
From: Lee Webb <lwebbee@britcomtele.comnotreal>
Subject: Re: What do you call the => operator?
Message-Id: <93vh05$64u$1@uranium.btinternet.com>

Programming Perl (3rd Edition): P108

"The => digraph is mostly just a synonym for the comma operator."

Personally, I believe Larry et al ;-)

Lee.

Ben Okopnik wrote:
> 
> "Perl 4 used the comma to separate the key and value items; Perl5 uses => 
> (digraph symbol)."
> 
> She proceeds to refer to it as 'the digraph symbol' further on in the 
> book. ACK! A perfect example of just reading the documentation (perlop)
> without understanding it...
> 
> Does anyone know the actual name for this thing, though? _Is_ there one?



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

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 V10 Issue 64
*************************************


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