[19637] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1832 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 27 14:05:56 2001

Date: Thu, 27 Sep 2001 11:05:10 -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: <1001613910-v10-i1832@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 27 Sep 2001     Volume: 10 Number: 1832

Today's topics:
    Re: carriage return <min_c_lee@yahoo.com>
    Re: delete/undef a hash inside a hash nobull@mail.com
    Re: Forcing reevaluation of code in mod_perl scripts? <nospaming@gmx.net>
    Re: Forcing reevaluation of code in mod_perl scripts? nobull@mail.com
        grep question <djberge@qwest.com>
    Re: grep question <davidhilseenews@yahoo.com>
    Re: grep question (Daniel S. Lewart)
    Re: grep question <stampes@xilinx.com>
    Re: grep question <djberge@qwest.com>
        Help with system() on win32 (JRoot)
    Re: Help with system() on win32 <Thomas@Baetzler.de>
        How to know the script is already running or not??? <hkdennis2k@yahoo.com.hk>
    Re: IO::Socket::INET nobull@mail.com
    Re: IO::Socket::INET (Chris Fedde)
    Re: maths <na@na>
    Re: maths <Thomas@Baetzler.de>
    Re: maths <tsee@gmx.net>
    Re: maths <jurgenex@hotmail.com>
    Re: maths <tsee@gmx.net>
        Mission Statement for this newsgroup? <djberge@qwest.com>
    Re: Parsing a string <please@no.spam>
    Re: Perl ROOT (Chris Fedde)
    Re: Pre spawning in perl (Mark Jason Dominus)
    Re: Pre spawning in perl (Randal L. Schwartz)
    Re: Push into an array <mjcarman@home.com>
    Re: Search engine (Chris Fedde)
    Re: Security of letting user specify regex in CGI scrip (Jay McGavren)
    Re: Security of letting user specify regex in CGI scrip (Randal L. Schwartz)
        Slashes (DeNunzio)
    Re: Slashes (Randal L. Schwartz)
    Re: Slashes <jurgenex@hotmail.com>
    Re: Sourcing Things in Perl ? <jurgenex@hotmail.com>
    Re: testing the "flatness" of a structured file <djberge@qwest.com>
    Re: Uninitialized Value... nobull@mail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 27 Sep 2001 17:41:36 GMT
From: "Michael" <min_c_lee@yahoo.com>
Subject: Re: carriage return
Message-Id: <kxJs7.459$Le.18538@sea-read.news.verio.net>


"Graham Wood" <Graham.T.Wood@oracle.com> wrote in message
news:3BB317B0.21D68E64@oracle.com...
> Michael wrote:
>
> > How do I replace carriage ruturn character with a space?
> > s/\n/ /g or s/\r\n/ /g can't work.
> >
> > Michael
>
> In what context are you trying to do this and why can't they work?
>
> Graham Wood
>

I am trying to handle the content in "comments" area (in a text box from
form submission),
replacing all carriage returns with spaces, so it turns into a regular
string that can be carried
into a query string, then a remote server can accept it.
I'm not sure why s/\n/ /g or s/\r\n/ /g can't work, but it turns out to be
that way.

However, Tim's suggestion just works perfectly.




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

Date: 27 Sep 2001 17:41:26 +0100
From: nobull@mail.com
Subject: Re: delete/undef a hash inside a hash
Message-Id: <u9ofnw37t5.fsf@wcl-l.bham.ac.uk>

"S" <x25@pobox.com> writes:

> What I first tried is to do "undef $a{$b}" when I don't need it
> anymore - but hash key still remained.
> 
> I have then added "delete $a{$b}" after this, and it *seems* like it's
> working now (key is gone if I try to access it).
> 
> Is this the correct way? :)

delete() is the correct way to delete an element from a hash.  The
undef is redundant.  The fact that the value of the element in
question happens to be a hash-ref is irrelevant.

BTW: Given the subject line of this post I suspect that when you said
"undef $a{$b}" you were actually trying to do "undef %{$a{$b}}".  But
in either case it is redundant if you are going to delete $a{$b}
anyhow.

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


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

Date: Thu, 27 Sep 2001 17:15:09 +0200
From: EXP <nospaming@gmx.net>
Subject: Re: Forcing reevaluation of code in mod_perl scripts?
Message-Id: <3BB3427D.1DDBD4BA@gmx.net>

Damian James wrote:
> >Any ideas?
> 
> A couple:
> 
>         use system(), pass the data as arguments (optionally serialised
>     with Data::Dumper or Storable, etc), suitably escaped for your
>     shell.
> 
>         system(), share the data via files or an DBMS or another external
>     mechanism (IPC shareable?).
> 

Hm,

That could be not as easy as it sounds here but might be doable.
Of course if there is any way to tell mod_perl directly to not cache a
certain part of the code it would be much better as the system() command
would start another perl process and perls startup time should not be
taken lightly. And communication between the mod_perl proccess and the
new perl process would be a mess as I would have to be bidirectional.

Or can somebody definetly say that this is indeed impossible with
mod_perl and has to be done via system()? *still hoping*

BYe!
EXP


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

Date: 27 Sep 2001 17:40:45 +0100
From: nobull@mail.com
Subject: Re: Forcing reevaluation of code in mod_perl scripts?
Message-Id: <u9pu8c37ua.fsf@wcl-l.bham.ac.uk>

EXP <nospaming@gmx.net> writes:

> I want to execute an external perl file

perldoc -f do

> I want to execute an external perl file from a mod_perl script 
>                                                        ...but I
> don't want mod_perl to keep that external perl file in memory.

> require ext.pl	#works, but would cache it

require('ext.pl') does _not_ cache ext.pl.  It simply assumes that
ext.pl is only being called to set some stuff up in the symbol table
and that once this has been done once then that is enough.

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


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

Date: Thu, 27 Sep 2001 11:51:21 -0500
From: "Mr. Sunblade" <djberge@qwest.com>
Subject: grep question
Message-Id: <ZJIs7.1037$x12.131311@news.uswest.net>

Got a question on the behavior of grep.

Before you roll your eyes, yes, I tried perldoc.  Yielded exactly 1
paragraph about using grep in void context.

 ...and yes, I read the Camel...

 ...and Effective Perl Programming...

Ok - now that *that's* settled, let me get to my question.  I've got a
simple test script I ran.  Here it is:

#!/usr/local/bin/perl -w
# Perl 5.6.1 on Solaris 8
use strict;

my %hash = (
   fname => 'daniel',
   mname => 'james',
   lname => 'berger',
);

# Prints
unless(grep /bergeg/,values(%hash)){ print "Singleton: Not found\n" }

# Doesn't print! (?)
foreach('daniel','bergeg'){
   unless(grep /$_/,values(%hash)){ print "Loop: Not found\n" }
}

# I also tried "unless( grep { /$_/ } values %hash..."

Now, I would expect the grep to fail in the first test, which it does.

Within the foreach loop, I would expect the pattern match to fail on the
second element ("bergeg").  However, it doesn't fail!

Is there some secret behavior of grep I should know about?  Or am I missing
something scathingly obvious?

Thanks in advance.

Regards,

Mr. Sunblade




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

Date: Thu, 27 Sep 2001 17:09:53 GMT
From: "David Hilsee" <davidhilseenews@yahoo.com>
Subject: Re: grep question
Message-Id: <B3Js7.4226$Xz1.1066294@news1.rdc1.md.home.com>


"Mr. Sunblade" <djberge@qwest.com> wrote in message
news:ZJIs7.1037$x12.131311@news.uswest.net...
> Got a question on the behavior of grep.
>
> Before you roll your eyes, yes, I tried perldoc.  Yielded exactly 1
> paragraph about using grep in void context.
>
> ...and yes, I read the Camel...
>
> ...and Effective Perl Programming...
>
> Ok - now that *that's* settled, let me get to my question.  I've got a
> simple test script I ran.  Here it is:
>
> #!/usr/local/bin/perl -w
> # Perl 5.6.1 on Solaris 8
> use strict;
>
> my %hash = (
>    fname => 'daniel',
>    mname => 'james',
>    lname => 'berger',
> );
>
> # Prints
> unless(grep /bergeg/,values(%hash)){ print "Singleton: Not found\n" }
>
> # Doesn't print! (?)
> foreach('daniel','bergeg'){
>    unless(grep /$_/,values(%hash)){ print "Loop: Not found\n" }
> }
>
> # I also tried "unless( grep { /$_/ } values %hash..."
>
> Now, I would expect the grep to fail in the first test, which it does.
>
> Within the foreach loop, I would expect the pattern match to fail on the
> second element ("bergeg").  However, it doesn't fail!
>
> Is there some secret behavior of grep I should know about?  Or am I
missing
> something scathingly obvious?
>
> Thanks in advance.
>
> Regards,
>
> Mr. Sunblade
>

What you're missing: $_ is what is used for the "current element", so you're
essentially matching each word against itself.

If you were to write out the statement explicitly, it would be $_ =~ /$_/;

Try something like this instead:

foreach my $name ('daniel','bergeg'){
   unless(grep /$name/,values(%hash)){ print "Loop: Not found\n" }
}

--
David Hilsee




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

Date: Thu, 27 Sep 2001 17:08:52 GMT
From: d-lewart@uiuc.edu (Daniel S. Lewart)
Subject: Re: grep question
Message-Id: <E2Js7.792$sc.10333@vixen.cso.uiuc.edu>

"Mr. Sunblade" <djberge@qwest.com> writes:

> Before you roll your eyes, yes, I tried perldoc.  Yielded exactly 1
> paragraph about using grep in void context.

perldoc answers you question:
	http://www.perldoc.com/perl5.6/pod/func/grep.html
and you are using grep in scalar context, not void.

> # Doesn't print! (?)
> foreach('daniel','bergeg'){
>    unless(grep /$_/,values(%hash)){ print "Loop: Not found\n" }
> }

The fine man page says:
	locally setting $_ to each element

Try this instead:
	foreach my $pat qw(daniel bergeg) {
	    warn "Loop: $pat not found\n" unless grep /$pat/, values(%hash);
	}

Cheers,
Daniel Lewart
d-lewart@uiuc.edu


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

Date: Thu, 27 Sep 2001 11:03:11 -0600
From: Jeff Stampes <stampes@xilinx.com>
To: djberge@qwest.com
Subject: Re: grep question
Message-Id: <3BB35BCF.A970FDD6@xilinx.com>


[Complimentary copy sent to OP]

"Mr. Sunblade" wrote:

> my %hash = (
>    fname => 'daniel',
>    mname => 'james',
>    lname => 'berger',
> );
>
> # Doesn't print! (?)
> foreach('daniel','bergeg'){
>    unless(grep /$_/,values(%hash)){ print "Loop: Not found\n" }
> }
>
> Is there some secret behavior of grep I should know about?  Or am I missing
> something scathingly obvious?

from perldoc -f grep:

     grep BLOCK LIST
     grep EXPR,LIST
             This is similar in spirit to, but not the same as,
             grep(1) and its relatives.  In particular, it is not
             limited to using regular expressions.

             Evaluates the BLOCK or EXPR for each element of LIST
             (locally setting "$_" to each element)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Don't rely on $_ too much...it can burn you in cases like this.




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

Date: Thu, 27 Sep 2001 12:24:34 -0500
From: "Mr. Sunblade" <djberge@qwest.com>
Subject: Re: grep question
Message-Id: <ddJs7.1384$x12.144738@news.uswest.net>

"David Hilsee" <davidhilseenews@yahoo.com> wrote in message
news:B3Js7.4226$Xz1.1066294@news1.rdc1.md.home.com...
<snip>
> What you're missing: $_ is what is used for the "current element", so
you're
> essentially matching each word against itself.
>
> If you were to write out the statement explicitly, it would be $_ =~ /$_/;
>
> Try something like this instead:
>
> foreach my $name ('daniel','bergeg'){
>    unless(grep /$name/,values(%hash)){ print "Loop: Not found\n" }
> }

DOH!  I guess I just didn't get it.  Thanks to all who replied!

Regards,

Mr. Sunblade




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

Date: 27 Sep 2001 08:19:21 -0700
From: awkster@yahoo.com (JRoot)
Subject: Help with system() on win32
Message-Id: <9efa6216.0109270719.d975faa@posting.google.com>

I'm running perl 5.005.03 (which I must stay with for reasons
I won't go into)
Running NT 4.0

I have been through the faq, perltoot, perlfunc and many samples
garnered off the web.

In the most simple terms, I want to open a text file in notepad.exe
and while the text file is open, have the program return to the
calling script to continue.

This is a very simple example

#!perl -w

use strict;

my $file = "c:\\file.txt":
system("notepad $file");
print "Howdy\n";

This will open the text file but does not return to the perl
script to print the line "Howdy" until I close notepad.

So far I have tried various was of using system,
various ways of using exec() and was going to try
fork(), exec() but according to perldocs fork is 
not available for win32.

SO far nothing has worked satisfactorily.

Thought about trying the win32::spawn and ::process
but do not have it loaded in the application which
is calling this perl script (the application comes
with a perl load and I am not allowed to modify it)

Am I chasing my tail with this??? 
Does anyone know a way this can be done???

Any help is greatly appreciated

Thanks and regards


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

Date: Thu, 27 Sep 2001 17:32:13 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: Help with system() on win32
Message-Id: <ddh6rto0222qpeu74de9hl4gga1ep0cv38@4ax.com>

On 27 Sep 2001 08:19:21 -0700, awkster@yahoo.com (JRoot) wrote:
>I'm running perl 5.005.03 (which I must stay with for reasons
>I won't go into)
>Running NT 4.0
[...]
>In the most simple terms, I want to open a text file in notepad.exe
>and while the text file is open, have the program return to the
>calling script to continue.

Try 

  system "start $file";

That'll launch the preconfigured viewer for *.txt files and return
control to your program. Works for me :-)

HTH,
-- 
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl


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

Date: Fri, 28 Sep 2001 01:26:25 +0800
From: "Dennis" <hkdennis2k@yahoo.com.hk>
Subject: How to know the script is already running or not???
Message-Id: <9ovn4l$b0v9@rain.i-cable.com>

Can I only let the script run one copy only?prevent two or more same script running???





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

Date: 27 Sep 2001 17:41:46 +0100
From: nobull@mail.com
Subject: Re: IO::Socket::INET
Message-Id: <u9n13g37sl.fsf@wcl-l.bham.ac.uk>

"felix" <mr.thanquol@gmx.de> writes:

> I actually try to write a script to send some controll-sequences to a
> java-webserver.
> but first I want to figure out some basic stuff of how to communicate to a
> webserver

Why?  Why not use LWP?

> my $request = IO::Socket::INET->new(PeerAddr   => 'server-name',

> print $request, "\n";

Spurious comma after handle.

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


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

Date: Thu, 27 Sep 2001 16:55:45 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: IO::Socket::INET
Message-Id: <lSIs7.716$Owe.282791936@news.frii.net>

In article <9ov4nf$1ln$1@crusher.de.colt.net>,
felix <mr.thanquol@gmx.de> wrote:
>hi,
>
>I actually try to write a script to send some controll-sequences to a
>java-webserver. but first I want to figure out some basic stuff of how
>to communicate to a webserver via script. my first try was to post a
>simple "GET" request to a normal webserver (apache) but it's not doing
>it's job.....have a look
>

Here is my rewrite of your code. See if you can tell where I've made
changes.  But if your goal is to communicate with a webserver you might
want to look at the LWP module before rollong your own.

#!/usr/local/bin/perl -w

# $Id$

use IO::Socket;

my $request = IO::Socket::INET->new(
    PeerAddr => 'www.perl.org',

    PeerPort => '80',
    Proto    => 'tcp',
    Type     => SOCK_STREAM,
);

print $request "GET /index.html 1.0\n";    # request a site
print $request "\n";                       # have a look at the request

print "Server said:\n\n";
while (<$request>) {
    print $_ ;

    # print content of requestet site
}
print "end of request.\n";

-- 
    This space intentionally left blank


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

Date: Thu, 27 Sep 2001 16:10:05 +0100
From: "Chris" <na@na>
Subject: Re: maths
Message-Id: <3bb34153$0$8513$ed9e5944@reading.news.pipex.net>

you wouldn't let it lie




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

Date: Thu, 27 Sep 2001 17:19:42 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: maths
Message-Id: <nmg6rt0nnu9lcv1hieginvf855gllc97dv@4ax.com>

On Thu, 27 Sep 2001 16:10:05 +0100, "Chris" <na@na> wrote:
>you wouldn't let it lie

Well, I'm "obviously a small lonely man, with little to brighten
[my] day apart from [my] officious perl doctrin".

You on the other hand, have important business waiting at the pub.
What are you still doing here?
-- 
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl


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

Date: Thu, 27 Sep 2001 19:05:38 +0200
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: maths
Message-Id: <9ovm8a$tvi$01$1@news.t-online.com>

"Thomas Bätzler" <Thomas@Baetzler.de> schrieb im Newsbeitrag
news:bm56rtsmdv9npir7o8959l8bv3mhk24206@4ax.com...

[snip]

>
> Now that's a good start, but you need to work a bit on the delivery.
> See http://baetzler.de/humor/powerposting.html for details.
>

[snip]

I think rule 10 applies here. Hell, what am I talking about? The whole list!

Steffen




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

Date: Thu, 27 Sep 2001 10:13:38 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: maths
Message-Id: <3bb35e42$1@news.microsoft.com>

"Chris" <na@na> wrote in message
news:3bb31576$0$225$ed9e5944@reading.news.pipex.net...
> this is a news group, you dont own and cant control what gets posted. this
> isn't your news group.

No, but I can control whom I listen to:

***PLONK***

jue




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

Date: Thu, 27 Sep 2001 19:18:20 +0200
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: maths
Message-Id: <9ovo22$u0u$03$1@news.t-online.com>

"Chris" <na@na> schrieb im Newsbeitrag
news:3bb31576$0$225$ed9e5944@reading.news.pipex.net...
> wow, what a friendly bunch you lot are.

You try to be and will, too.

> i have a script when i need a little help with  and look at the abuse i
get.

You don't get abuse. We post. We don't send you emails (and we wouldn't even
if you were less of a [snip] to not post a valid mail address and/or name of
some form).

> this is a news group, you dont own and cant control what gets posted. this
> isn't your news group.

1. You can't either.
2. We don't control.
3. You ask for help.
4. You don't have the *right* to be helped.
5. We choose whom to help.
6. If you are rude, you can be sure we won't.

> i come on and post a simple question which i can resolve because my perl
> knowledge is limited.

We all noticed that. We even offered help, eventhough you didn't RTFM as it
is usenet tradition. You flamed.

> if you dont think i deserve help then dont help me, dont just post message
> trying to sound hard, it doesn't impress anyone.

We don't care about sounding hard. We want to discuss Perl. If you have a
good answer to a problem - or better yet, an interesting problem - you can
impress us. That would be a way to convince us to help.

And we don't care about impressing a faceless.

> the internet is great because it promotes the free and easy exchange of
> information, dont tell me that i cant ask for help with perl - who are you
> ?

I'm 19 and probably either 5 years older than you or at least that much more
mature. (Umm, couldn't resist writing this, though, so I still have to gro
up a bit!)
The way you write suggests that, too.

Get lost or adapt.

Steffen Müller (<- that's faceless, too. There's a whole bunch of 19-year
old Steffen Müller's in Germany!)





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

Date: Thu, 27 Sep 2001 11:42:18 -0500
From: "Mr. Sunblade" <djberge@qwest.com>
Subject: Mission Statement for this newsgroup?
Message-Id: <ABIs7.931$x12.127812@news.uswest.net>

Is there one?  I searched google for a bit, but didn't find one.

Just curious.

Regards,

Mr. Sunblade




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

Date: Thu, 27 Sep 2001 15:05:05 GMT
From: Andrew Cady <please@no.spam>
Subject: Re: Parsing a string
Message-Id: <87k7yk4qxu.fsf@homer.cghm>

"Rob - Rock13.com" <rob_13@excite.com> writes:

> Brady Doll <news:9oub86$hhs$1@news-int.gatech.edu>:
> 
> > I am attempting to parse a string which has an attribute followed
> > by a value... Attribute="value"
> >
> > this was the code i was attempting to use, however the (.*) causes
> > it to freeze.
> >
> > m/(?:\s*)([\w])(?:\=)(?:[\'\"])(.*)(?:[\'\"])/;

Some problems in your (OP's) use of regexes:

(?:\s*) <-- entirely unnecessary to specify precedence with
parentheses here, the default precedence is what you want.  Use \s*

([\w]) <-- you don't need a character class with just one character,
even a special character like \w that matches multiple characters.
Just use (\w).  This matches only a single character, though, you
really want (\w+).

(?:[\'\"]) <-- ' and " don't need to be escaped in a character class,
and again the parentheses are unnecessary.  Just use ['"].

(?:\=) <-- = doesn't need to be escaped, doesn't need parens.  Just
use =.

(.*) <-- * is greedy, so this will match to the end of the line, even
if the line ends with a ' or ".  Either use (.*?)['"] or use
([^'"]*)['"].  The former is more correct and the latter faster.  Or,
use alternation as in the first regex I have listed below.

(?:[\'\") <-- see my previous comment on this construct.

Your exact same regex, with the unnecessary punctuation removed, would
be:

m/\s*(\w)=['"](.*)['"]/; # doesn't work

Change that to:

m/\s*(\w+)=['"](.*?)['"]/; # does work

 ...by adding just two characters, and it will work (if there are no
quotes in value).  The main problem was the \w instead of \w+.  It
only worked when Attribute was one character long.  Also see my regex
below, which will handle quotes in the value a little bit better.

> > What should be put in place of the (.*)...is there anything or am
> > I just going to have to result to a different method to parse this
> > string then using a reg. ex.?
> 
> My first thought would be, perhaps?  m/(.*)=['|"]([^"]+)['|"]/;

You don't use | to mean "or" in a character class like you do outside
one; or is implied, you just list the characters.  Also your regex
would match the closing single-quote in the field and wouldn't handle
an empty field (and the first greedy .* would cause performance
problems and would match a second = in the line).  Something like this
would be a little better: 

m/^\s*([^=]*)=(?:'([^']*)'|"([^"]*)")/; ($attr,$val) = ($1, $2||$3);

 ...which will handle attr="don't" or attr='10" pianist', but still
can't handle escaped quotes.  That'd be a little more effort (but
still not really hard).


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

Date: Thu, 27 Sep 2001 17:05:54 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Perl ROOT
Message-Id: <S%Is7.717$Owe.326902784@news.frii.net>

In article <MPG.161a55aa15eefeed989707@news.siol.net>,
Marvin  <glodalec@yahoo.com> wrote:
>In article <m2vgi7fm64.fsf@thunderbear.dyndns.dk>, 
>ravn@thunderbear.dyndns.dk says...
>> Marvin <glodalec@yahoo.com> writes:
>> 
>> > Hi !
>> > 
>> > I installed perl on exported FS under /tools/usr/local/....
>> > 
>> > Every client has mounted that directory.
>> > Now when Im trying to run a perl script, it looks in /usr/local/.... 
>> > structure for libraries. Is there any way I can change perl root 
>> > directory to be /tools.
>> > I also tried with 
>> > use lib "/tools/usr/local/lib/perl5/..." ;
>> > use lib "/tools/usr/local/lib/perl5/..." ;
>> > use lib "/tools/usr/local/lib/perl5/..." ;
>> > 
>> > but it doesnt work.
>> 
>> You might find the easiest solution is to recompile perl from scratch
>> and tell it that it will be placed in the above location.
>> 
>> 
>Although several people would tell the best idea is to recompile, I have  
>a binary version and want to find out the solution (if possible) within 
>the version already compiled. 

Something has to give in here.  Ether fix perl or fix the virtual file
system.

Since you say you are using the automounter you can set up the
virtual file sistem so that perl finds things in the places it
expects to find them by making clever uses of mounting maps and
symbolic links.  Running perl -V will give you a list of the paths
that perl expects to be able to find.

good luck
-- 
    This space intentionally left blank


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

Date: Thu, 27 Sep 2001 15:38:41 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Pre spawning in perl
Message-Id: <3bb34800.591c$b8@news.op.net>

In article <9of7bq$922$1@mamenchi.zrz.TU-Berlin.DE>,
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>- The parent's wait() could probably be made more robust.  For reasons
>  that are partly due to Perl and partly to the operating system, a
>  SIGCHLD could get lost, 

No, it can't.  Or rather, the process completely ignores SIGCHLD, so
it doesn't matter what happens with SIGCHLD.  This program uses wait()
everywhere.  wait() never gets lost.  

>- In handle_clients there seems to be a loop missing around accept()
>  and ++$clients.

Yes, I corrected this in the followup I made last week.  Oho, I see
that my news server did not receive your article until a week after
you posted it.  Bad news server!  

>- For purely esthetic reasons, I would let handle_clients merely
>  return (not exit) after $MAX_SERVICE is exhausted, and let the
>  child's main program do the exit.

I don't know what esthetic reasons those are.  I put the exit in both
places for engineering reasons, not esthetic reasons.   

It is a bad problem if the child somehow returns starts to execute the
main loop that only the parent should execute, so I put the exit in
both places to be sure.

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: 27 Sep 2001 08:56:13 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Pre spawning in perl
Message-Id: <m1d74csk4i.fsf@halfdome.holdit.com>

>>>>> "cubol" == cubol  <irl.com@ntlworld.com> writes:

cubol>     I am building a client/server program in perl and would
cubol> like to pre-spawn, say 10, child process's and hold them in a
cubol> pool and pass incoming connections to these process's.  My
cubol> theory behind this is that I assume this will give me a
cubol> increase in speed if not please tell me, otherwise any ideas on
cubol> how to do this will be greatly appreciated.

here's the preforking and managing part...

<http://www.stonehenge.com/merlyn/WebTechniques/col34.html>
<http://www.stonehenge.com/merlyn/LinuxMag/col15.html>
<http://www.stonehenge.com/merlyn/LinuxMag/col16.html>

I'm not sure there's any gain at letting the master take the
connection.  See the first column... we merely want the slave to take
the connection.

print lcfirst 'just another Perl hacker,'

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Thu, 27 Sep 2001 11:03:48 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Push into an array
Message-Id: <3BB34DE4.42DC88CD@home.com>

Blnukem wrote:
> 
> How do I get this code to "push" $I into the @items array.

If you want to push an item onto an array, use push().

   push(@items, $I);

Simple, huh?

> for ($i = 0; $i < 10; $i +=1 ){
> 
> @items = "$i"
> 
> }
> print "@items " ;

That's a very unperlish way of doing things.

@items = (0 .. 9);

-mjc


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

Date: Thu, 27 Sep 2001 16:40:16 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Search engine
Message-Id: <QDIs7.715$Owe.322886144@news.frii.net>

In article <0CEs7.15238$Tv6.79120@news1.rdc1.nsw.optushome.com.au>,
David Scarlett <dscarlett@REMOVETHIS.optushome.com.au> wrote:
>Firsly, please don't tell me to post this in
>comp.infosystems.www.authoring.cgi, it doesn't belong there, this is a
>perl-specific question. ;-)
>
>I'm thinking about write a perl script that will search through a FAQ for
>keywords, but I'm not sure what would be the best way to implement it. I
>want each answer (ie section of the FAQ) to be in seperate html files, with
>each having certain keywords that will be matched against those searched
>for.
>

You forgot option 4:  Generate your HTML files then tell Google about it
and have then index it for you.

And then there is 5:  Use HtDIG.

And then there is 6:  Install and use FAQ::OMatic from CPAN

Or you might try 7:   Put your data into a wiki like UseModWiki or twiki.

TAMTD7WTDI
chris
-- 
    This space intentionally left blank


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

Date: 27 Sep 2001 09:31:02 -0700
From: sgarfunkle@hotmail.com (Jay McGavren)
Subject: Re: Security of letting user specify regex in CGI script?
Message-Id: <6bb557e1.0109270831.6d4a6117@posting.google.com>

> I think Text::Query goes in the right direction, though I haven't tried
> it myself.

Aha!  It looks perfect!

> BTW there's no need to create one regex of it. After all, perl knows
> eval, so it's easy to create a sub that checks if a string matches your
> requirements. For example, "a and (b or c)" can be converted to
> 
> 	$query = eval "sub { /\ba\b/ and (/\bb\b/ or /\bc\b/ }";

True, but letting the user specify any portion of an eval gives me the
jitters.

$query = eval "sub { /\b/ and `rm source.xml` and  /\b/ and /\ba\b/
}";  #Shudder...

I could remove most of the punctuation first, but I'd be scared of
forgetting (or not knowing about) some possible trick.  The Camel
talks about running the script under reduced permissions and such in
Chapter 23, but that's all a bit over my head for now...

Anyway, with Text::Query available, none of that should be necessary. 
I'll experiment with it tonight!  Thanks!


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

Date: 27 Sep 2001 09:37:59 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Security of letting user specify regex in CGI script?
Message-Id: <m18zf0si6w.fsf@halfdome.holdit.com>

>>>>> "Jay" == Jay McGavren <sgarfunkle@hotmail.com> writes:

Jay> True, but letting the user specify any portion of an eval gives me the
Jay> jitters.

Jay> $query = eval "sub { /\b/ and `rm source.xml` and  /\b/ and /\ba\b/
Jay> }";  #Shudder...

Jay> I could remove most of the punctuation first, but I'd be scared of
Jay> forgetting (or not knowing about) some possible trick.  The Camel
Jay> talks about running the script under reduced permissions and such in
Jay> Chapter 23, but that's all a bit over my head for now...

No, you'd probably be forgetting the trick that permits

        $foo[`rm random.thing`]

in a regex working.  That's never a problem with /$a/, because
there's no reexamination of $a's value to see if it contains variables
(only meta characters).

Yes, eval is scary.  Very scary. :)

print "Just another Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: 27 Sep 2001 08:06:20 -0700
From: denunzio@hotmail.com (DeNunzio)
Subject: Slashes
Message-Id: <454576d1.0109270706.25edf9e3@posting.google.com>

Folks:

I seem to recall that you must precede a symbol you wish to be
interpreted literally, with a slash \.  The problem we're running into
is that we want to pass two slashes \\ as a literal value.  Preceding
each with a slash, \\\\, doesn't produce two slashes \\.  Any ideas?

Thanks!


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

Date: 27 Sep 2001 08:15:21 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Slashes
Message-Id: <m1u1xosm0m.fsf@halfdome.holdit.com>

>>>>> "DeNunzio" == DeNunzio  <denunzio@hotmail.com> writes:

DeNunzio> I seem to recall that you must precede a symbol you wish to be
DeNunzio> interpreted literally, with a slash \.

Uh, where?  What context?

DeNunzio>   The problem we're running into is that we want to pass two
DeNunzio> slashes \\ as a literal value.  Preceding each with a slash,
DeNunzio> \\\\, doesn't produce two slashes \\.  Any ideas?

Show some code that doesn't work, and what you wanted it to do.
We're not psychic.

print "Just another Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Thu, 27 Sep 2001 10:16:31 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Slashes
Message-Id: <3bb35eef$1@news.microsoft.com>

"DeNunzio" <denunzio@hotmail.com> wrote in message
news:454576d1.0109270706.25edf9e3@posting.google.com...
> I seem to recall that you must precede a symbol you wish to be
> interpreted literally, with a slash \.

Make that "some symbols in some contexts".

> The problem we're running into
> is that we want to pass two slashes \\ as a literal value.  Preceding
> each with a slash, \\\\, doesn't produce two slashes \\.  Any ideas?

What is the context? Show us some code that doesn't work as you intend it to
work.

jue





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

Date: Thu, 27 Sep 2001 10:20:18 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Sourcing Things in Perl ?
Message-Id: <3bb35fd2$1@news.microsoft.com>

<slightlysprintingdog@ntlworld.com> wrote in message
news:3BB2F9FF.D1538F3A@ntlworld.com...
> Is the file you're sourcing a shell script?
>
> >I'm not sure, from what I can see it looks like a shell script.
> >It contains a load of 'setenv' and 'echo' commands and thats about it.
>
> Is it for the same shell that the perl script is running under?
>
> >Yes.
>
> Is it the for the same shell that an individual user of your script uses?
>
> >Yes.
>
> Can you guarantee that this is always the case?
>
> >Yes.
>
> Are you checking the return value of system?  Was it successful?
>
> >I don't know how.  Would a 'die' command surfice ?

Your quoting is badly, badly messed up and virtually incomprehensible.

jue




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

Date: Thu, 27 Sep 2001 09:44:57 -0500
From: "Mr. Sunblade" <djberge@qwest.com>
Subject: Re: testing the "flatness" of a structured file
Message-Id: <cqIs7.838$x12.122258@news.uswest.net>


"Walter Hafner" <hafner@augusta.de> wrote in message
news:qdf8zf0pwoz.fsf@www.ibexnet.de...
> Hi!
>
> I'm sure there is a simple solution - i just can't see it.
>
> I have a couple of small, structured files in the form:
>
> ...
> [BEGIN xxx]
> ...
> [END xxx]
> ...
> [BEGIN yyy]
> ...
> [END yyy]
> ...
>
> I want to strip everything between the BEGIN ... END Blocks and write
> the blocks (including the delimiters) in an array.
>
> Ok, easily done:
>
>     # slurp input. Files are small enough (< 50 KB)
>     open IN, "<testfile" or die $!;
>     my $file = join "", <IN>;
>     close IN;
>     my @chunks = ($file =~ /\[BEGIN.*?\].*?\[END.*?\]/sg);
>
> Now the difficult part:
>
> How can i ensure that there aren't any nested blocks? I don't need to
> parse them, i simply need to stop parsing and print an error message.
> I know that Perl's regular expressions can't match nested balanced
> text.
>
> But it should be possible to test if there's a BEGIN ... BEGIN ... END
> pattern.

First, a couple of questions.

1) Are the (potentially) nested BEGIN ... END blocks indented at all?  If
so, you can use the ^ character to ignore the nested blocks.

2) Will the number of characters following the BEGIN ... END keywords be
different for nested blocks?  i.e. Would the outer block look like [BEGIN
xyz] and the inner block be something like [BEGIN abc]?  Or could they be
the same?  If they're different, you can use that to set your "real" outer
blocks.

Lemme know and I'll follow-up (or perhaps that's enough info to get you
going).

Regards,

Mr. Sunblade





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

Date: 27 Sep 2001 17:41:58 +0100
From: nobull@mail.com
Subject: Re: Uninitialized Value...
Message-Id: <u9lmj037s9.fsf@wcl-l.bham.ac.uk>

richardbriggs@att.com (rab) writes:

>     41  my @thatline=split(/ /,$rejec[-1]);

> Use of uninitialized value at rejects line 41, <SYSLOG> chunk 11558.

> what's causing these errors?

@rejec is empty.

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


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

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


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