[19497] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1692 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 4 18:06:51 2001

Date: Tue, 4 Sep 2001 15:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <999641109-v10-i1692@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 4 Sep 2001     Volume: 10 Number: 1692

Today's topics:
        abs(MININT) != -MININT <iw@spameater.contexo.de>
    Re: Accessing Microsoft SQL Server (version 6+) from Ac <Bradl@AAAcostbook.com>
        adduser in a script <jtournier@nerim.net>
    Re: Black Perl <somewhere@in.paradise.net>
    Re: capture output from all pages of top? <gnarinn@hotmail.com>
    Re: D'oh!  It does what I said, not what I want <lmoran@wtsg.com>
    Re: Godzilla DOS Environmental Variables Utility (Malcolm Dew-Jones)
    Re: How can I find the PID's of my children? (Sean McAfee)
    Re: How can I find the PID's of my children? (Stan Brown)
    Re: Match starting from the nth occurrence of a charact <rsherman@ce.gatech.edu>
        Match starting from the nth occurrence of a character t (Marc Schaefer)
    Re: OT: urgent reponse <somewhere@in.paradise.net>
        perl hashe tables <Mark.Pennington@sdrc.com>
    Re: perl hashe tables <tony_curtis32@yahoo.com>
    Re: Perl2EXE for Windows (Chas Friedman)
    Re: Perl2EXE for Windows <bart.lateur@skynet.be>
        Problems writing to a file that already exists! <Pcmann1@btinternet.com>
    Re: Problems writing to a file that already exists! <jurgenex@hotmail.com>
    Re: Recommendations for a PERL editor <bart.lateur@skynet.be>
    Re: Recommendations for a PERL editor (Tad McClellan)
    Re: references, slices, voodoo <gnarinn@hotmail.com>
    Re: references, slices, voodoo ctcgag@hotmail.com
        Regular Express (Stefan Adams)
    Re: Regular Express <jurgenex@hotmail.com>
    Re: Regular Express <ren@tivoli.com>
    Re: Regular Express <bart.lateur@skynet.be>
    Re: Why doesn't this regex work? <bart.lateur@skynet.be>
    Re: Why doesn't this regex work? (Benoit Gauthier)
    Re: Why doesn't this regex work? (Benoit Gauthier)
        Win32 process list <lhswartw@ichips.intel.com>
    Re: win32 rmdir questions <krahnj@acm.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 4 Sep 2001 21:11:59 +0200
From: "Ingo Wechsung" <iw@spameater.contexo.de>
Subject: abs(MININT) != -MININT
Message-Id: <9n3939$fgn$1@news.seicom.net>

Hi,

I noticed recently that with "use integer" abs($i) != -$i when $i is MININT.
(Perl version is 5.6.1)
I know why it happens. In the negate op, the native C unary - is used on an
IV.
In the abs op, if it is MININT it  converts the IV to a NV first and negates
that. This, of course, returns a NV with the value MAXINT+1 (provided the
mantissa is long enough, which happens to be true at least on my machine.
But what if sizeof int >= sizeof double? The +1 would get lost, woudn't it?)

Does anybody know why this is implemented that way? I think the bahviour is
a bit surprising at least. If somebody said it was irritating or just plain
wrong, I wouldn't object either.
After all, when I say "use integer" I really mean integer. And in 2's
complemt integers abs(MININT) == MININT == -MININT == 0-MININT == 1-MININT-1
== .. == MAXINT-MINIT-MAXINT. Or it should be so.

Greetings form rainy germany
Ingo





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

Date: Tue, 4 Sep 2001 12:00:00 -0700
From: "Brad" <Bradl@AAAcostbook.com>
Subject: Re: Accessing Microsoft SQL Server (version 6+) from ActiveState Perl?
Message-Id: <3b9524fd$0$41816$e2e8da3@nntp.cts.com>

Thanks Folks!

Brad

"Brad" <Bradl@AAAcostbook.com> wrote in message
news:3b86e9a4$0$23793$e2e8da3@nntp.cts.com...
> Is this possible?  If so, can someone point me to the modules?
>
> Thanks
> Brad
>
>
>




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

Date: Tue, 4 Sep 2001 21:57:07 +0200
From: Tournier <jtournier@nerim.net>
Subject: adduser in a script
Message-Id: <9n3bmm$2tva$2@norfair.nerim.net>

Hello, 
I'd like to write a script that read couple of name and password in a file.
This script must also add a user. I tried the crypt function, but all the 
crypt passwords are short, and the authentification is then bad.
Any idea ?
Thanks
--
Jérôme


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

Date: Wed, 5 Sep 2001 07:53:29 +1000
From: "Tintin" <somewhere@in.paradise.net>
Subject: Re: Black Perl
Message-Id: <i5cl7.2$Vw6.41001@news.interact.net.au>


"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news:slrn9p9meq.7k6.mgjv@martien.heliotrope.home...
> The only source (on a site that was actually responding) that I could
> find was this one:
>
> http://internet.ls-la.net/comppoems/black-perl.html
>
> It attributes it to Sharon Hopkins, and states that it has been used
> with permission.

What version of perl is it supposed to compile under?




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

Date: Tue, 4 Sep 2001 20:51:44 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: capture output from all pages of top?
Message-Id: <999636704.886150201316923.gnarinn@hotmail.com>

In article <7d3dfb10.0109040635.2a260da4@posting.google.com>,
Ron Hartikka <ronh@iainc.com> wrote:
>Hi Group,
>
>I'd like to run top from perl and capture all the output. This...
>
>print `top -d 1`; 
>
>...gives me (HPUX, perl 5.6) only page 1 of top's output.
>
>Any ideas on how to get the contents of the subsequent pages into perl?

first: are you sure that top on HPUX does do more that one page, when not
outputting to terminal?
you should try for the command line:
  top -d 1 > top.out

on linux this works as you expect, with top.out growing endlessly.

second: even if top behaved that way, your 
  print `top -d 1`;
would probably not work as you expect, i expect :-)
consider what happens:
  a) perl executes shell command 'top -d 1' and grabs all output
  b) perl waits for command to exit
  c) perl prints grabbed output

if you expect top to continue, how long will b) take?

if you want perl to process the output as it comes, you
probably want to open() with a pipe
see
  perldoc -f open
  perldoc  perlopentut
  perldoc perlipc
  

one thought just occurred to me: you *are* terminating  the
'top' command by pressing 'q', and wonder why the print only prints
one page. in that case the answer is that it prints all the pages,
but form-feeding in between, and doing it so fast that you see only
the last page
this can be demonstrated by just waiting an obscenely long time before
pressing 'q', or changing the command to 'top -d 0.1', or both

hope this helped
gnari


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

Date: Tue, 04 Sep 2001 15:39:56 -0400
From: Lou Moran <lmoran@wtsg.com>
Subject: Re: D'oh!  It does what I said, not what I want
Message-Id: <gbbaptg9ubq78pi8n27kj4vtv60ni3sthe@4ax.com>

On Mon, 03 Sep 2001 02:30:52 -0400, Benjamin Goldberg
<goldbb2@earthlink.net> wrote wonderful things about sparkplugs:

SNIP
>
>PS, where did you get the number 18501 from?

<hangs head in shame> I needed it to run over two hours... when I had
written the pings outside the loop it would run very fast (surprise)
and 18501 took about an hour and a a half. </hangs head in shame>

Oh yea I was worried that someone might think that I was DDoSer.  I
only need to run it about 55 times now.  I ran it, made the report,
let us never speak of this again.... ;)


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

Date: 4 Sep 2001 12:43:26 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Godzilla DOS Environmental Variables Utility
Message-Id: <3b952ede@news.victoria.tc.ca>

Simon Flack (news@simonflack.com) wrote:
: Hello Godzilla.

: Nice script.

: > For years it has been said it is impossible to set
: > parent DOS environmental variables via a Perl script.

: I've never heard that.

: > Extensive and exhaustive testing of various methods
: > reveals his simple binary executable is the best
: > choice for this task. His method is extremely fast.
: > This applies to Win9.x and Win.me systems.

: I don't know. I only did a few hours research into this, but I thought that
: Win32::AdminMisc was pretty good for this task.

: http://www.roth.net/perl/adminmisc/#SetEnvVar
: http://www.roth.net/perl/adminmisc/#DelEnvVar

Nice routines, but they don't work on NT for the intended purpose.


E.g.

	::testing.bat
	set TRY1=value before perl runs
	echo %TRY1%
	perl -MWin32::AdminMisc -e "Win32::AdminMisc::SetEnvVar(
		'TRY1' , 'a new value' );
	echo %TRY1%


(manually unwrap one long long line in the above)


The value of TRY1 is *not* updated for the batch script in which the
command appears, which was the point of the excercise.



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

Date: 4 Sep 2001 11:42:54 -0700
From: mcafee@artemis.transmeta.com (Sean McAfee)
Subject: Re: How can I find the PID's of my children?
Message-Id: <9n37be$m9n$1@artemis.transmeta.com>

In article <9n335p$9hv$1@panix1.panix.com>, Stan Brown <stanb@panix.com> wrote:
>I'm writing a perlTK script, which will spawn at least one child task to do
>some long runing processing.

>However, I'm going to leave the user the option of canceling from an "exit"
>button on the main window. So I need to be able to send a kill() signal to
>my children.

>Short of making these PID's global variables, when they are spwned, how can
>I detrmine what children, my runing perl process is the parent of?

What's wrong with keeping track of the PIDs yourself?

my @children;

sub fork_child {
    defined(my $pid = fork()) or die "Can't fork: $!\n";
    if ($pid == 0) {
        # child stuff
        exit;
    }
    push @children, $pid;
}

sub terminate_program {
    kill TERM => @children;
}

If some of the children could terminate before the end of your main
program, you could get a little fancier:

my %children;

$SIG{CHLD} = sub { my $pid = wait; delete $children{$pid} };

sub fork_child {
    defined(my $pid = fork()) or die "Can't fork: $!\n";
    if ($pid == 0) {
        # child stuff
        exit;
    }
    $children{$pid} = 1;
}

sub terminate_program {
    kill TERM => keys %children;
}

If you're morally opposed to this approach for some reason, you'll have to
use some kind of OS-supplied feature to find your children, like parsing
the output of ps:

open PS, 'ps -ef |' or die "Can't fork: $!\n";
while (<PS>) {
    my @field = split;
    if ($field[2] == $$) {
        kill TERM => $field[1];
    }
}

Of course, the appropriate switches to ps are highly OS-dependent.

-- 
Sean McAfee                                                mcafee@umich.edu
print eval eval eval eval eval eval eval eval eval eval eval eval eval eval
q!q@q#q$q%q^q&q*q-q=q+q|q~q:q? Just Another Perl Hacker ?:~|+=-*&^%$#@!


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

Date: 4 Sep 2001 15:17:28 -0400
From: stanb@panix.com (Stan Brown)
Subject: Re: How can I find the PID's of my children?
Message-Id: <9n39c8$imf$1@panix2.panix.com>

In <9n37be$m9n$1@artemis.transmeta.com> mcafee@artemis.transmeta.com (Sean McAfee) writes:

>In article <9n335p$9hv$1@panix1.panix.com>, Stan Brown <stanb@panix.com> wrote:
>>I'm writing a perlTK script, which will spawn at least one child task to do
>>some long runing processing.

>>However, I'm going to leave the user the option of canceling from an "exit"
>>button on the main window. So I need to be able to send a kill() signal to
>>my children.

>>Short of making these PID's global variables, when they are spwned, how can
>>I detrmine what children, my runing perl process is the parent of?

>What's wrong with keeping track of the PIDs yourself?

Thanks for the example code, but I would prefer not to have to clutter
global variable space with yet another array, because of callbacks etc. I
already have _way_ more global data than I normally like.

So I was hoping for a function that would allow a perl script to look at
the process table, and determine from there what tasks it is the parrent
of.



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

Date: Tue, 04 Sep 2001 17:49:37 +0500
From: Robert Sherman <rsherman@ce.gatech.edu>
Subject: Re: Match starting from the nth occurrence of a character to the nth+1  occurrence
Message-Id: <3B94CDE1.7A9B252C@ce.gatech.edu>

Marc Schaefer wrote:
> 
> Hello folks,
> i've read the faq and some docs but apparently i need a function to do
> this or i'm to stupid to read.
> 
> So here's my problem:
> 
> I have a line
> 
> eeeeeeeeee,adfgadvad,asdfvadfv,adfvadfva,advadvdav,advadfvdaffvadv
> 
> and i need a RE that matches all between the 3th and 4th comma.
> 

a bit clumsy, but functional:

$string =
"eeeeeeeeee,adfgadvad,asdfvadfv,adfvadfva,advadvdav,advadfvdaffvadv";
$string =~ /\w+,\w+,\w+,(\w+),.+/;
print $1;

-- 
robert sherman
css, cee
georgia institute of technology
atlanta, ga, usa


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

Date: 4 Sep 2001 14:33:27 -0700
From: schaefer@pdtec.de (Marc Schaefer)
Subject: Match starting from the nth occurrence of a character to the nth+1 occurrence
Message-Id: <388a211a.0109041333.7700a3d4@posting.google.com>

Hello folks,
i've read the faq and some docs but apparently i need a function to do
this or i'm to stupid to read.

So here's my problem:

I have a line

eeeeeeeeee,adfgadvad,asdfvadfv,adfvadfva,advadvdav,advadfvdaffvadv

and i need a RE that matches all between the 3th and 4th comma. 

Does anybody knows how that works?

Thank you in advance!

Marc


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

Date: Wed, 5 Sep 2001 07:58:59 +1000
From: "Tintin" <somewhere@in.paradise.net>
Subject: Re: OT: urgent reponse
Message-Id: <sacl7.3$cx6.60476@news.interact.net.au>


"peter pilsl" <pilsl_@goldfisch.at> wrote in message
news:3b94b6c0@e-post.inode.at...
> Ilmari Karonen wrote:
>
> And - the last one -it must also be a place where I can ask urgent
> questions and hopefully get a quick answer with a hint.

Usenet is the last place to go for urgent questions and fast answers.  Much
quicker to read the supplied documentation, or do a google search.






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

Date: Tue, 04 Sep 2001 14:45:34 -0400
From: Mark Pennington <Mark.Pennington@sdrc.com>
Subject: perl hashe tables
Message-Id: <3B95214E.487AF787@sdrc.com>


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

I need to enter some information in a table in perl.  The information is
to be called within a perl script.  It would be helpful to be able to
update the table in future references.  I have been told that a hashe
table is the best way to do this in perl.

Does anyone have any information or websites that would have info for
perl hashe tables??

--
Mark Pennington                                 | Office: (513) 576-3675
Product Development                             | Fax:    (513) 576-2654
Structural Dynamics Research Corporation        | http://www.sdrc.com
2000 Eastman Dr.  Milford, OH 45150             | mark.pennington@sdrc.com



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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
I need to enter some information in a table in perl.&nbsp; The information
is to be called within a perl script.&nbsp; It would be helpful to be able
to update the table in future references.&nbsp; I have been told that a
hashe table is the best way to do this in perl.
<P>Does anyone have any information or websites that would have info for
perl hashe tables??
<PRE>--&nbsp;
Mark Pennington&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Office: (513) 576-3675&nbsp;&nbsp;&nbsp;&nbsp;
Product Development&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Fax:&nbsp;&nbsp;&nbsp; (513) 576-2654&nbsp;&nbsp;&nbsp;&nbsp;
Structural Dynamics Research Corporation&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | <A HREF="http://www.sdrc.com">http://www.sdrc.com</A>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
2000 Eastman Dr.&nbsp; Milford, OH 45150&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | mark.pennington@sdrc.com</PRE>
&nbsp;</HTML>

--------------48C6FFF1D9477F3FE9AA4119--



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

Date: Tue, 04 Sep 2001 14:11:49 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: perl hashe tables
Message-Id: <87d756srd6.fsf@limey.hpcc.uh.edu>

>> On Tue, 04 Sep 2001 14:45:34 -0400,
>> Mark Pennington <Mark.Pennington@sdrc.com> said:

> I need to enter some information in a table in perl. 
> The information is to be called within a perl script. 
> It would be helpful to be able to update the table in
> future references.  I have been told that a hashe table

"future references" to *what*?

> is the best way to do this in perl.

All would be pointless speculation without some clue as to
what data you're trying to store and what you want to do
with it.  And what the overall problem is.

(And it's "hash" BTW.)

hth
t
-- 
Yes way!  Mmmmkay?


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

Date: Tue, 04 Sep 2001 19:21:31 GMT
From: friedman@math.utexas.edu (Chas Friedman)
Subject: Re: Perl2EXE for Windows
Message-Id: <3b9527e7.2247576406@news.cc.utexas.edu>

On Tue, 04 Sep 2001 18:39:48 +0200, Crazydj <Crazydj@web.de> wrote:

>Hi @ll!!! =)
>Does anyone know the program perl2exe? I have got a problem in
>converting scripts that use modules. The perl2exe program always tells
>me that he cant find the modules, but my scripts work so the modules can
>be found in the @INC paths...
>How can I tell perl2exe were those modules are? I have tried to just
>copy them to the perl2exe directory but this doesnt work...
>Thanx and greets
>
>Bastian Ballmann
>
>--
>Djz rule the world! ...and some other staff ;-p Find out at http://www.crazydj.de
>
>
>
I tried perl2exe and had the same problem. Acording to the docs, you
should insert some statements of the form: use module;
This didn't seem to work for me, so I added a bunch of: 
use lib 'path-to-lib'; statements. This eliminated some of the
problems but not others. In some cases, I could actually get
the perl2exe program to run with no complaints, but then running
the .exe crashed my (Windows) machine. I was just trying
the evaluation (unregistered) version, so I called Indigo
to ask them about the problems. I talked to a very nice guy
who suggested that the binary port of Perl (Siemens Perl) I
am using (got it from CPAN ports directory) may be the problem
He suggested using Activestate product. I may try that, but
in fact, the Perl I am using has been very satisfactory, so I'm
reluctant to change. I was just curious about the perl2exe,really.
I'd be interested to hear how others have fared. 
                             chas f


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

Date: Tue, 04 Sep 2001 19:41:45 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Perl2EXE for Windows
Message-Id: <gcbapts48honcdbrrmsa1o7acpgrcj0i36@4ax.com>

Crazydj wrote:

>Does anyone know the program perl2exe? I have got a problem in
>converting scripts that use modules. The perl2exe program always tells
>me that he cant find the modules, but my scripts work so the modules can
>be found in the @INC paths...
>How can I tell perl2exe were those modules are? I have tried to just
>copy them to the perl2exe directory but this doesnt work...

Exactly when do you get that error? Is it when creating the EXE, or when
trying to run it?

If it's the former: just make sure that the modules can all be found in
the default @INC when creating the EXE. That should be enough.

If it's the latter, this means that some modules weren't included, and
that can be because they're normally loaded in an awkward way, for
example the DBD::* modules when using DBI. Solution is to add explicit
lines like "require DBD::mysql;", possibly in a "if(0){...}" block.

-- 
	Bart.


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

Date: Tue, 4 Sep 2001 19:09:12 +0100
From: "Peter Mann" <Pcmann1@btinternet.com>
Subject: Problems writing to a file that already exists!
Message-Id: <9n35gq$f7r$1@neptunium.btinternet.com>

Dear all,
I am having difficulties writing to a file that already exists. From the
books I have read relating to this problem, I can't determine the most
suitable option to specifiy in the code extract below.
For instance, I have opened the file for write only, and if it doesn't exist
then create it. However, when the file does already exist (i.e. report.htm),
it should delete it and create a new one. But there doesn't appear to be a
suitable 'option' to delete if already exists. Can someone please advise me
if there is a simple option to do this. The only other way I can think of is
to check if the file exists, and if it does delete it before creating a new
one. But this appears clumsy coding style.
Any suggestions would be much appreciated.
Thanks in advance,
  - Pete

  my $filename = "report.htm";
  $fh = IO::File->new($filename, O_WRONLY|O_CREAT);




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

Date: Tue, 4 Sep 2001 11:31:22 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Problems writing to a file that already exists!
Message-Id: <3b951e06$1@news.microsoft.com>

"Peter Mann" <Pcmann1@btinternet.com> wrote in message
news:9n35gq$f7r$1@neptunium.btinternet.com...
> I am having difficulties writing to a file that already exists. From the
> books I have read relating to this problem, I can't determine the most
> suitable option to specifiy in the code extract below.
[...]
>   my $filename = "report.htm";
>   $fh = IO::File->new($filename, O_WRONLY|O_CREAT);


Gosh, why that? Can't you simply use

    open fh, ">$filename" or die "Can't open $filename: $!\n";

jue




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

Date: Tue, 04 Sep 2001 19:57:28 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Recommendations for a PERL editor
Message-Id: <jgcapt0os1tmh84bos2k8u2vtgpul6jib4@4ax.com>

Tad McClellan wrote:

>>What makes it funny is that #!/usr/bin/perl
>>breaks but #!/usr/bin/perl -w doesn't =)
>
>
>That is not funny at all if you understand how processing of
>shebang lines happens:
>
>   1) determine which processor to feed the file to.
>
>   2) pass everything after the processor-identifying part
>      as arguments to the processor.
>
>With "#!/usr/bin/perl\r\n" it determines in step 1 that the
>processor's name is "/usr/bin/perl\r". You get "file not found"
>when there is not a file with that name.
>
>With "#!/usr/bin/perl -w\r\n", step 1 works fine (it stops
>at whitespace), and step 2 passes "-w\r" as an argument to perl, 
>and _perl_ Does The Right Thing.

So the shell doesn't consider a CR to be whitespace. AFAIK, Perl does.

        Bart.
-- 
This post has a terrible OCR. So shoot me.


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

Date: Tue, 04 Sep 2001 21:15:42 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Recommendations for a PERL editor
Message-Id: <slrn9pa21d.rl9.tadmc@tadmc26.august.net>

Tina Mueller <tinamue@zedat.fu-berlin.de> wrote:
>Tad McClellan <tadmc@augustmail.com> wrote:
>
>> With "#!/usr/bin/perl\r\n" it determines in step 1 that the
>> processor's name is "/usr/bin/perl\r". You get "file not found"
>> when there is not a file with that name.
>
>> With "#!/usr/bin/perl -w\r\n", step 1 works fine (it stops
>> at whitespace), and step 2 passes "-w\r" as an argument to perl, 
>> and _perl_ Does The Right Thing.
>
>wouldn't it be clever if webserver-admins, ISPs just create
>a "/usr/bin/perl\r" binary additionally? they would never
                                                     ^^^^^

Until the program also contained a here-doc, which would also mess up :-)


>again have problems with people loading their script up
>and asking why it doesn't work...
>
>just kidding =)
>


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


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

Date: Tue, 4 Sep 2001 20:11:03 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: references, slices, voodoo
Message-Id: <999634263.551159946713597.gnarinn@hotmail.com>

In article <5y5l7.770$zi3.384429@news2-win.server.ntlworld.com>,
Stuart Moore <stumo@bigfoot.com> wrote:

[seemingly discussing the Fisher-Yates shuffle in FAQ]

>Just out of interest, is anyone able to comment on whether this technique
>produces results as random as
>
>my @flag = ();
>my @newarray = ();
>for (my $i = @array; --$i; $i){
>    do{
>        my $j = int rand (@array);
>    } while $flag[$j];
>    $newarray[$j] = $array[$i];
>}
>
>Code isn't very nice and also very inefficient, but seems to me to be more
>random, as each permutation would have equal chance - not sure that's the case
>for the other one.

this code is exactly equivalent to the Fisher-Yates, except for the
inefficiency. i do not know what you mean by equal chance here, 
but i suspect that you think that your rand(CONSTANT) is any
different than the F-Y rand($i+1) with decreasing $i, but your
do{} loop effectively make them equivalent.
both methods are during each pass selecting one out of X items left,
the only difference is that your items are distributed within a larger set,
but the F-Y has them neatly grouped in a array slice and therefore does
not have to grope blindly for them.

gnari


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

Date: 04 Sep 2001 22:03:24 GMT
From: ctcgag@hotmail.com
Subject: Re: references, slices, voodoo
Message-Id: <20010904180324.169$5p@newsreader.com>

Jasper McCrea <jasper@guideguide.com> wrote:
 ...
> But I wrote my own, anyway, in the way that I thought would be simplest
> ie extract a random element, and put it in a new array.
>
> sub new_order {
>   my @ray = @array;   # I was using a global for the testing...
>   my @new_order = ();
>   push @new_order, (splice @ray, (int rand @ray), 1) while (@ray);
>   return \@new_order;
> }
>
 ...

> Oh, and speed:
>
> Benchmark: running mine, yate, each for at least 3 CPU seconds...
>       mine:  4 wallclock secs ( 3.00 usr +  0.00 sys =  3.00 CPU) @
> 9299.00/s (n=27897)
>     fisher:  5 wallclock secs ( 3.00 usr +  0.00 sys =  3.00 CPU) @
> 7380.33/s (n=22141)

Dandy.  Now what if you want shuffle something with more than 4 elements?
Say, 3000?

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
                    Usenet Newsgroup Service


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

Date: 4 Sep 2001 11:20:37 -0700
From: stefan@borgia.com (Stefan Adams)
Subject: Regular Express
Message-Id: <dcc927de.0109041020.295f19c9@posting.google.com>

I want to capture all text in between ...<BODY ...>(Capture all
this)</BODY>...
I assumed the RE /<BODY\s+.*?>(.*?)</BODY>/ would work, but it
doesn't.  Any suggestions?

Thanks,
Stefan


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

Date: Tue, 4 Sep 2001 11:33:39 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Regular Express
Message-Id: <3b951e8f$1@news.microsoft.com>

"Stefan Adams" <stefan@borgia.com> wrote in message
news:dcc927de.0109041020.295f19c9@posting.google.com...
> I want to capture all text in between ...<BODY ...>(Capture all
> this)</BODY>...
> I assumed the RE /<BODY\s+.*?>(.*?)</BODY>/ would work, but it
> doesn't.  Any suggestions?

May I be so bold to suggest RTFM (PerlFAQ9):
     How do I remove HTML from a string?

perldoc -q HTML

jue




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

Date: 04 Sep 2001 14:28:41 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Regular Express
Message-Id: <m3y9nusql2.fsf@dhcp9-161.support.tivoli.com>

On 4 Sep 2001, stefan@borgia.com wrote:

> I want to capture all text in between ...<BODY ...>(Capture all
> this)</BODY>...
> I assumed the RE /<BODY\s+.*?>(.*?)</BODY>/ would work, but it
> doesn't.  Any suggestions?

Ignoring the plethora of problems that can be encountered with
attempting to parse what is apparently HTML in this manner, there are
two likely causes of your problem.  First, and perhaps only a
transcription error in this post, you have a "/" inside that
expression, which is almost certainly going to lead to a syntax error.

Second, and more probably the real problem, this will only work if you
have already read the entire text into a single variable.  The common
mistake is to use something like this expression when processing
single lines of a multi-line piece of data.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Tue, 04 Sep 2001 20:17:45 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Regular Express
Message-Id: <tgdapt00mq0e0a2tku7irsg95acva8344f@4ax.com>

Stefan Adams wrote:

>Subject: Regular Express

Whauh, that one's original.

> want to capture all text in between ...<BODY ...>(Capture all
>this)</BODY>...
>I assumed the RE /<BODY\s+.*?>(.*?)</BODY>/ would work, but it
>doesn't.  Any suggestions?

First of all, you'll need to escape the slash. Second, /.*/ doesn't
match newlines, so you'll need to add the /s modifier. And finally, it
ight be a good idea to make the regex case-insensitive, using the /i
modifier.

-- 
	Bart.


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

Date: Tue, 04 Sep 2001 19:46:46 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Why doesn't this regex work?
Message-Id: <ukbaptocrvsm26ho04c7aggp3l7u6jkm80@4ax.com>

Benoit Gauthier wrote:

>In my view, this code should truncate the variable to 20 characters.
>It does not work. Why?
>
>$data = "1234567 101234567 201234567 30";
>print "$data\n";
>
>$data =~ s/(.{0-20})/$1/;
>print "$data\n";

You need a comma, not a hyphen.

	$data =~ s/(.{0,20})/$1/;

But still, you're replacing the first 0 to 20 characters by themselves,
leaving the rest unchanged. In other words: it's a NOOP.

>$data =~ /(.{0-20})/;
>$data = $1;
>print "$data\n";

Of course, once the same error is fixed (comma not hyphen), this one
will work. But so does this:

	$data =~ s/(.{0,20}).*/$1/s;

Note that now, I'm matching but not replacing anything that follows the
first 20 characters.

-- 
	Bart.


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

Date: Tue, 04 Sep 2001 21:20:20 GMT
From: gauthier@circum.com (Benoit Gauthier)
Subject: Re: Why doesn't this regex work?
Message-Id: <3b954576.37358296@news.videotron.ca>

On Tue, 04 Sep 2001 18:30:46 +0100, Jasper McCrea
<jasper@guideguide.com> wrote:

>> $data =~ s/(.{0-20})/$1/;
>> print "$data\n";
>
>for both of these, replace {0-20} with {0,20}.

Thanks.

Benoît Gauthier
gauthier@circum.com


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

Date: Tue, 04 Sep 2001 21:20:40 GMT
From: gauthier@circum.com (Benoit Gauthier)
Subject: Re: Why doesn't this regex work?
Message-Id: <3b954596.37390963@news.videotron.ca>

>>$data =~ s/(.{0-20})/$1/;
>>print "$data\n";
>
>You need a comma, not a hyphen.
>
>	$data =~ s/(.{0,20})/$1/;

Thanks.

Benoît Gauthier
gauthier@circum.com


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

Date: Tue, 4 Sep 2001 11:45:52 -0700
From: "Swanthog" <lhswartw@ichips.intel.com>
Subject: Win32 process list
Message-Id: <9n37h0$mul@news.or.intel.com>

Hi,

Is there a way to obtain a list of running processes within my script
without resorting to a shell command? I am running on a win2k box. The
method I am using now that I want to get away from is this:

$proc_list = `ps`;

Thanks,
Larry S.




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

Date: Tue, 04 Sep 2001 20:21:20 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: win32 rmdir questions
Message-Id: <3B95382E.BE328CB7@acm.org>

Philippe PERRIN wrote:
> 
> keng wrote:
> > how can i remove a directory that is not empty (can have other sub-dir or
> > files in it) ?
> 
> not really a Perl solution, but a win32-based solution :
> system("rd /s /q $yourDir");

Philippe PERRIN wrote:
> 
> "John W. Krahn" wrote:
> > system "deltree /y $yourDir";
> 
> deltree doesn't exist on all Windows-OS (not on W2000 for instance).

Yes and the /s and /q switches to rd don't exist on Win9x. So the moral
of the story is: if you want it portable, code it in perl.  :-)



John
-- 
use Perl;
program
fulfillment


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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 1692
***************************************


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