[29597] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 841 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 11 14:09:41 2007

Date: Tue, 11 Sep 2007 11:09:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 11 Sep 2007     Volume: 11 Number: 841

Today's topics:
    Re: (?{ code }) block works fine in child rule but not  <ben@morrow.me.uk>
    Re: (?{ code }) block works fine in child rule but not  xhoster@gmail.com
    Re: (?{ code }) block works fine in child rule but not  <clint.olsen@gmail.com>
    Re: (?{ code }) block works fine in child rule but not  <m@rtij.nl.invlalid>
        a random sub-array <jiehuang001@gmail.com>
    Re: a random sub-array <mritty@gmail.com>
    Re: a random sub-array <jiehuang001@gmail.com>
        Car-ac-systems <knjaz0@gmail.com>
        Go Here to win a free guitar  nutsbreaker1@gmail.com
    Re: Go Here to win a free guitar <noemail@address.com>
        How can I get a colored subject in my Perl created e-ma <absmienk@hotmail.com>
    Re: How can I get a colored subject in my Perl created  <check.sig@for.email.invalid>
    Re: How can I get a colored subject in my Perl created  <s.denaxas@gmail.com>
    Re: How to get a colored subject <ben@morrow.me.uk>
        negation - RE  fred78980@yahoo.com
    Re: negation - RE <ben@morrow.me.uk>
    Re: Regular Expression <tadmc@seesig.invalid>
    Re: SSH on windows <glex_no-spam@qwest-spam-no.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 11 Sep 2007 14:14:49 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: (?{ code }) block works fine in child rule but not in parent
Message-Id: <9vgir4-aqq.ln1@osiris.mauzo.dyndns.org>


Quoth abigail@abigail.be:
>                                                _
> xhoster@gmail.com (xhoster@gmail.com) wrote on VCXXIII September MCMXCIII
> in <URL:news:20070910165330.968$RF@newsreader.com>:
> {}  Clint Olsen <clint.olsen@gmail.com> wrote:
> {} > On 2007-09-10, xhoster@gmail.com <xhoster@gmail.com> wrote:
> {} > > Apparently the problem is that you think the answer is to start out by
> {} > > reading the source code rather than the documentation.
> {} > >
> {} > > The behavior you describe is documented in both perldoc perlre and
> {} > > perldoc re.
> {} >
> {} > Yes, I read that section, but I'm not relying on any runtime
> {} > interpolation to get my work done (or did I misread something?).
> {}  
> {}  Ah, now I see.  Now I prefer your reading of the docs to my reading of the
> {}  docs (or I would if it weren't for the sad fact that the worse reading
> {}  seems to be correct one).
> {}  
> {} > I want
> {} > to avoid using switches that are 'perilous' when it isn't required.
> {}  
> {}  Maybe I'm missing something here, but I would argue that if you are running
> {}  in a hostile environment, it isn't enough to refuse to use re 'eval', you
> {}  should also run under taint.  And once you use taint appropriately, I don't
> {}  see why use re 'eval' would be perilous.
> 
> Well, for starters, /$tainted_variable/ doesn't trigger an exception under -T.

It does if the result contains any code assertions:

    % perl -T -Mre=eval -e'/$^X (?{1;})/'
    Eval-group in insecure regular expression in regex m/perl (?{1;})/
    at -e line 1.

so, *if* you are tainting, re 'eval' should be safe.

> The regexp engine of 5.10 will have many new features; some of the current
> usages of (?{ .. }) can be replaced by the new features. I do not what the
> intended usage of (?{ .. }) in the example given by the OP is, but is might
> very well be that the same could have done with named capture buffers and
> %+ or %- in 5.10.

I think this is very likely.

Ben



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

Date: 11 Sep 2007 16:59:24 GMT
From: xhoster@gmail.com
Subject: Re: (?{ code }) block works fine in child rule but not in parent
Message-Id: <20070911125925.933$Iq@newsreader.com>

Ben Morrow <ben@morrow.me.uk> wrote:
> Quoth xhoster@gmail.com:
> > Ben Morrow <ben@morrow.me.uk> wrote:
> > >
> > > This last regex contains both interpolation and code escapes which do
> > > not come from a qr//. This is what is forbidden unless you have re
> > > 'eval'.
> >
> > Does this requirement make sense?  Why does it matter if some part
> > of the regex which *isn't* the code part comes from an interpolation?
>
> It doesn't... :)
>
> > Was this just easier to implement than whatever makes more sense
> > would be?
>
> AFAICS (and the guts of the regex engine are *very* hard to follow) it
> is a consequence of Perl's regexen doing two-fold interpolation. First
> the qr is stringified and interpolated, and then the result is compiled.
> Perl has no way of knowing which bits came from where. (Any ideas anyone
> may have had about qrs being more efficient when interpolated into other
> regexen later are, unfortunately, false.[1])


Was there ever a time when qr// was the only way to have different parts
of the pattern have different "global" options, or was qr// introduced
after (?-xism:...) was introduced?

>
> However, when a qr is interpolated, it makes a record of how many eval
> groups it contained; then when the regex engine compiles an eval group,
> it checks to see whether it has met more eval groups so far than have
> been interpolated from qrs; if so, it throws the 'Eval-group not
> allowed' error.

If the construct has no interpolations at all, yet does have eval
groups, it will encounter more eval groups than have been interpolated
from qr//.  Is it the IN_PERL_RUNTIME that handles that part? And
which of these variables' behaviors is changed by use re 'eval'?

          else {                                          /* First pass */
               if (PL_reginterp_cnt < ++RExC_seen_evals
                   && IN_PERL_RUNTIME)
                   /* No compiled RE interpolated, has runtime
                      components ===> unsafe.  */
                   FAIL("Eval-group not allowed at runtime, use re
               'eval'"); if (PL_tainting && PL_tainted)
                   FAIL("Eval-group in insecure regular expression");
          }

> This is, of course, horribly crude, but it's hard to see
> what else could be done without completely re-working the way the regex
> engine operates.

I think you could just add another flag:
         if (PL_reginterp_cnt < ++RExC_seen_evals
                   && IN_PERL_RUNTIME && AT_LEAST_ONE_NON_QR_INTERPOLATION)

Of course, assuring the flag is set appropriately would be the hard part,
surely beyond my competence.  And if 5.10 is going to be quite different,
then I guess there is no point.


> >
> > I'm no longer confident that I know what it does, so I don't know
> > what it should say.
> >
> >                  For reasons of security, this construct is for-
> >                  bidden if the regular expression involves run-
> >                  time interpolation of variables, unless the per-
> >                  ilous "use re 'eval'" pragma has been used (see
> >                  re), even if those variables are results of "qr//".
> >                  However, variables containing qr// compiled forms of
> >                  this construct can themselves be interpolated into
> >                  other regular expressions which involve other
> >                  interpolations.
>
>     For reasons of security, this construct is forbidden if the regular
>     expression contains variable interpolations, unless it results from
>     the interpolation of a C<qr//>, or C<use re 'eval'> is in effect.

That is still confusing to me.  I keep reading the antecedent of
the pronoun in "unless it results from" as being the interpolation, not the
code construct.  I (now) know that this is the incorrect way to read it,
yet still that is how I read it when I approach it from the viewpoint of
someone who doesn't already know the answer.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


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

Date: Tue, 11 Sep 2007 12:01:59 -0500
From: Clint Olsen <clint.olsen@gmail.com>
Subject: Re: (?{ code }) block works fine in child rule but not in parent
Message-Id: <slrnfedig7.5mi.clint.olsen@belle.0lsen.net>

On 2007-09-11, Abigail <abigail@abigail.be> wrote:
> The regexp engine of 5.10 will have many new features; some of the
> current usages of (?{ .. }) can be replaced by the new features. I do not
> what the intended usage of (?{ .. }) in the example given by the OP is,
> but is might very well be that the same could have done with named
> capture buffers and %+ or %- in 5.10.

The intent of using the (?{ code }) blocks is so that I can construct one
massive RE for the entire lexical specification of the language ala what
lex/flex would do when you write a spec file.  So, at the end of a match
(and we /should/ match under normal circumstances), I have the token type
and any special processing all taken care of by the time I fall into the
code block.

Thanks,

-Clint


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

Date: Tue, 11 Sep 2007 19:47:01 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: (?{ code }) block works fine in child rule but not in parent
Message-Id: <pan.2007.09.11.17.45.00@rtij.nl.invlalid>

On Mon, 10 Sep 2007 23:25:24 -0700, Brian Helterlilne wrote:

> Martijn Lievaart wrote:
>> Did you look at Parser::Decent? Seems like the perfect tool for this
>> job.
> 
> Parse::RecDescent

Sorry, thx for the correction.

M4


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

Date: Tue, 11 Sep 2007 16:27:11 -0000
From:  Jie <jiehuang001@gmail.com>
Subject: a random sub-array
Message-Id: <1189528031.424230.70730@19g2000hsx.googlegroups.com>


I have an array like below:
@Big_array = (1, 2, 3, 4, 6, 7,10);

now I need to randomly generates a sub-array with 3 elements only,
say.

i tried to read the documentation for rand() but could not find the
solution. most of the examples online is talking about how to generate
ONE random element, but i need 3....

I guess it would something like below, but it does not work....
@new_array = rand(3, @Big_array)



Jie



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

Date: Tue, 11 Sep 2007 09:42:20 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: a random sub-array
Message-Id: <1189528940.211492.118540@57g2000hsv.googlegroups.com>

On Sep 11, 12:27 pm, Jie <jiehuang...@gmail.com> wrote:
> I have an array like below:
> @Big_array = (1, 2, 3, 4, 6, 7,10);
>
> now I need to randomly generates a sub-array with 3 elements only,
> say.
>
> i tried to read the documentation for rand() but could not find the
> solution. most of the examples online is talking about how to generate
> ONE random element, but i need 3....

So just do it three times.
my @sub_array = map { $Big_array[rand @Big_array] } 1..3;

Of course, this gives the possibility that you could have repeated
elements in your sub array.  If you don't want that, you'll have to do
a little more work.

First, make a copy of the array that you can destroy as we build the
sub array:
my @copy = @Big_array;
Then, randomly splice out an element as many times as you need to:
my @sub_array;
for (1..3) {
   push @sub_array, splice @copy, rand(@copy), 1;
}

Alternatively, use List::Util's shuffle() function to shuffle the
original, then just take the first three elements.
use List::Util qw/shuffle/;
my @sub_array = (shuffle @Big_array)[0,1,2];

Paul Lalli




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

Date: Tue, 11 Sep 2007 10:36:08 -0700
From:  Jie <jiehuang001@gmail.com>
Subject: Re: a random sub-array
Message-Id: <1189532168.161376.4020@k79g2000hse.googlegroups.com>

Hi, Paul:

Thank you very much!

This Shuffle works great!

jie

On Sep 11, 12:42 pm, Paul Lalli <mri...@gmail.com> wrote:
> On Sep 11, 12:27 pm, Jie <jiehuang...@gmail.com> wrote:
>
> > I have an array like below:
> > @Big_array = (1, 2, 3, 4, 6, 7,10);
>
> > now I need to randomly generates a sub-array with 3 elements only,
> > say.
>
> > i tried to read the documentation for rand() but could not find the
> > solution. most of the examples online is talking about how to generate
> > ONE random element, but i need 3....
>
> So just do it three times.
> my @sub_array = map { $Big_array[rand @Big_array] } 1..3;
>
> Of course, this gives the possibility that you could have repeated
> elements in your sub array.  If you don't want that, you'll have to do
> a little more work.
>
> First, make a copy of the array that you can destroy as we build the
> sub array:
> my @copy = @Big_array;
> Then, randomly splice out an element as many times as you need to:
> my @sub_array;
> for (1..3) {
>    push @sub_array, splice @copy, rand(@copy), 1;
>
> }
>
> Alternatively, use List::Util's shuffle() function to shuffle the
> original, then just take the first three elements.
> use List::Util qw/shuffle/;
> my @sub_array = (shuffle @Big_array)[0,1,2];
>
> Paul Lalli




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

Date: Tue, 11 Sep 2007 04:59:19 -0700
From:  knjaz <knjaz0@gmail.com>
Subject: Car-ac-systems
Message-Id: <1189511959.540806.157450@50g2000hsm.googlegroups.com>

Here you can find everything you need to know about car air
conditioning

http://car-ac-systems.blogspot.com/



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

Date: Tue, 11 Sep 2007 13:05:32 -0000
From:  nutsbreaker1@gmail.com
Subject: Go Here to win a free guitar
Message-Id: <1189515932.474336.220890@r29g2000hsg.googlegroups.com>

http://freeguitars.blogspot.com/



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

Date: Tue, 11 Sep 2007 13:12:03 GMT
From: "FreeRTOS.org" <noemail@address.com>
Subject: Re: Go Here to win a free guitar
Message-Id: <DuwFi.12472$c_1.6715@text.news.blueyonder.co.uk>

Please everybody that reads this report the poster to gmail for spam and, 
and to google adsense for promoting via spam (against rules).  The poster is 
a persistant nusance and should have both email and adverts accounts 
suspended. 




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

Date: Tue, 11 Sep 2007 03:11:21 -0700
From:  ab <absmienk@hotmail.com>
Subject: How can I get a colored subject in my Perl created e-mails.
Message-Id: <1189505481.999429.147670@57g2000hsv.googlegroups.com>

My script is sending e-mails to certain parties. It runs fine. Now I
want to have the recipients of my Perl created e-mail to see a colored
(say: red) subject. How can I direct my mail header to do this or
should I use a trick? All our customers use Outlook.

I'm using this format to crfeate the e-mail:

		from => 'me@domain.com',
		to => 'you@yourdomain.com',
		subject => "this is the subject",
		encoding => "7bit",
		multipart => 'related

All help is appreciated.



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

Date: Tue, 11 Sep 2007 14:39:35 +0300
From: Alex <check.sig@for.email.invalid>
Subject: Re: How can I get a colored subject in my Perl created e-mails.
Message-Id: <W7vFi.221745$oC3.142984@reader1.news.saunalahti.fi>

ab wrote:
> My script is sending e-mails to certain parties. It runs fine. Now I
> want to have the recipients of my Perl created e-mail to see a colored
> (say: red) subject. How can I direct my mail header to do this or
> should I use a trick? All our customers use Outlook.

This is not really a question about Perl. It /could/ be a question about
a Perl module, but your not specifying which (if any) module you are
using. If so, you should check the documentation, but I'd be very
surprised to find the functionality you are looking for in a
Perl-module, since coloured subject lines are not a feature of the
e-mail standard (see RFC 2822, link below). The fact that your customers
are using Outlook is irrelevant to Perl.


RFC 2822:
http://www.ietf.org/rfc/rfc2822.txt


-- Alex
localpart = alext
domain = iki dot fi
email = localpart at domain


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

Date: Tue, 11 Sep 2007 12:50:55 -0000
From:  Spiros Denaxas <s.denaxas@gmail.com>
Subject: Re: How can I get a colored subject in my Perl created e-mails.
Message-Id: <1189515055.520591.144670@r29g2000hsg.googlegroups.com>

On Sep 11, 11:11 am, ab <absmi...@hotmail.com> wrote:
> My script is sending e-mails to certain parties. It runs fine. Now I
> want to have the recipients of my Perl created e-mail to see a colored
> (say: red) subject. How can I direct my mail header to do this or
> should I use a trick? All our customers use Outlook.
>
> I'm using this format to crfeate the e-mail:
>
>                 from => '...@domain.com',
>                 to => '...@yourdomain.com',
>                 subject => "this is the subject",
>                 encoding => "7bit",
>                 multipart => 'related
>
> All help is appreciated.

Is that even supported by Outlook?

Spiros



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

Date: Tue, 11 Sep 2007 14:16:38 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How to get a colored subject
Message-Id: <m2hir4-aqq.ln1@osiris.mauzo.dyndns.org>


Quoth ab <absmienk@hotmail.com>:
> I want to have the recipients of my Perl created e-mail to see a
> colored (say: red) subject. How can I direct my mail header to do this
> or should I use a trick? All our customers use Outlook.

If you know of any way of creating an email so that it comes up with a
red subject in Outlook (I don't), then create one, and look at the
message source.

Ben



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

Date: Tue, 11 Sep 2007 08:22:17 -0700
From:  fred78980@yahoo.com
Subject: negation - RE
Message-Id: <1189524137.712399.34850@57g2000hsv.googlegroups.com>

Case1
This is my RE to negate cer which is OK
negation of (cer)
(\w{0,10})(?<!c)er
This take every word ending with er except word that end cer

Case2
and I use a similar RE to negate bcer
negation of (bcer)
(\w{0,10})(?<!b)(?<!c)er
I tried (?<!bc) which is not working

Case 3
negation of (b|c|d)er
(\w{0,10})(?<!b)(?<!c)(?<!d)er
This RE is too long

Please help me with case 2 and 3.

Many thanks



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

Date: Tue, 11 Sep 2007 17:24:00 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: negation - RE
Message-Id: <02sir4-1jr.ln1@osiris.mauzo.dyndns.org>


Quoth fred78980@yahoo.com:
> Case1
> This is my RE to negate cer which is OK

You will need to explain what you mean by 'negate'. It seems you have
some function which takes a regex as input and attempts to make a new
regex that matches some different set of data? You will need to explain
what forms of regex are possible input, and how you determine what you
want the output regex to match. The best way to do this is to post a
*short* example program *with input data* that demonstrates your
problem.

> negation of (cer)
> (\w{0,10})(?<!c)er
> This take every word ending with er except word that end cer

OK, though it would probably be simpler to write it as

    / ( \w{0,9} [^\Wc] ) er /x

i.e. matching what you want to match, rather than matching a \w and then
making a look-behind assertion about it.

> Case2
> and I use a similar RE to negate bcer
> negation of (bcer)
> (\w{0,10})(?<!b)(?<!c)er
> I tried (?<!bc) which is not working

I think you are confused about how look-around assertions work. (It is
rather confusing.) They do not consume any of the matched string, so
/(?<!b)(?<!c)/ is equivalent to /(?<! b|c)/x rather than to /(?<!bc)/.
If what you want is 'twelve-character words ending in "er" but not in
"bcer"', then it is the latter you want; since you say it is not
working, you will have to say what you expected it to match.

This is where look-behinds really are valuable. Matching something like
that 'by construction', while possible, is terribly messy.

> Case 3
> negation of (b|c|d)er
> (\w{0,10})(?<!b)(?<!c)(?<!d)er
> This RE is too long

Huh? Too long for what? Perl is quite happy with it.

Ben



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

Date: Tue, 11 Sep 2007 11:47:29 GMT
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Regular Expression
Message-Id: <slrnfectss.elv.tadmc@tadmc30.sbcglobal.net>

fritz-bayer@web.de <fritz-bayer@web.de> wrote:
> On 8 Sep., 07:50, Joe Smith <j...@inwap.com> wrote:
>> fritz-ba...@web.de wrote:
>> > I'm looking for a regular expression, which is plattform independet
>> > and works for java, perl or net.
>>
>> I'd say you have an impossible task.  The advanced parts of perl
>> regular expressions that almost do what you want are not implemented
>> the same way (if at all) on the other platforms.
>>
>>         -Joe
>
>
> What about finding all words which are not inside a href tag? So if
> I'm looking for the word OUTSIDE, then it should match, if it's not
> inside a href. So the following should not match
><a href='/somethin.html'>OUTSIDE</a>
>
> but this should match twice!
>
> OUTSIDE <a href='/somethin.html'>SOME OTHER TEXT</a> OUTSIDE


So the below should match twice also?

   <!--
   OUTSIDE <a href='/somethin.html'>SOME OTHER TEXT</a> OUTSIDE
   -->

And the below should match once (since it doess not appear in an anchor)?

   <!--
   <a href='/somethin.html'>OUTSIDE</a>
   -->


> Can somebody come up with a regular expression that does the job?


A regular expression is not the Right Tool for this job.

Use a real parser instead. 

Strip all of the anchor elements, then match against what remains.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Tue, 11 Sep 2007 09:51:57 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: SSH on windows
Message-Id: <46e6ab8e$0$504$815e3792@news.qwest.net>

gil wrote:
> Hi,
> 
> In the last week I'm trying to use Net::SSH unsuccessfully (Windows).
> 
> when trying to compile:
> 
> use Net::SSH;
> 
> my $ssh = new Net::SSH($host, [options]);
> $ssh->login('user', 'pass');
> my ($out, $err, $exit) = $ssh->cmd('ls');
> 
> I receive (after editing Perl.pm) :
> 
> Global symbol "$home" requires explicit package name at C:/usr/Perl/
> site/lib/Net
> /SSH/Perl.pm line 112.
> Compilation failed in require at C:/usr/Perl/site/lib/Net/SFTP.pm line
> 11.
> BEGIN failed--compilation aborted at C:/usr/Perl/site/lib/Net/SFTP.pm
> line 11.
> Compilation failed in require at hello.pl line 3.
> BEGIN failed--compilation aborted at hello.pl line 3.

Well, what's on line 112 in Perl.pm?????????

> 
> *when I change the value of $home, I receive other errors.

It sounds like user error, e.g. you left off the 'my' in
my $home = ...;


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 V11 Issue 841
**************************************


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