[29593] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 837 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 10 16:09:45 2007

Date: Mon, 10 Sep 2007 13:09:09 -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           Mon, 10 Sep 2007     Volume: 11 Number: 837

Today's topics:
        (?{ code }) block works fine in child rule but not in p <clint.olsen@gmail.com>
    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  <abigail@abigail.be>
    Re: (?{ code }) block works fine in child rule but not  <ben@morrow.me.uk>
    Re: Array Question <benoit.lefebvre@gmail.com>
    Re: Array Question <benoit.lefebvre@gmail.com>
    Re: Array Question <mritty@gmail.com>
    Re: Array Question <amerar@iwc.net>
    Re: Array Question <uri@stemsystems.com>
    Re: Array Question <mritty@gmail.com>
    Re: Array Question <amerar@iwc.net>
    Re: Array Question <jgibson@mail.arc.nasa.gov>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 10 Sep 2007 13:02:30 -0500
From: Clint Olsen <clint.olsen@gmail.com>
Subject: (?{ code }) block works fine in child rule but not in parent
Message-Id: <slrnfeb1lm.5mi.clint.olsen@belle.0lsen.net>

I'm trying to write a lexical analyzer in Perl, and I was trying to take
advantage of the above construct to simplify and be able to reuse rules as
much as possible.  My script looks like:

------

#!/usr/bin/perl

use strict;
use warnings;

my $foo;

my $escaped_identifier = qr/\\(\S+)(?=\s)/o;
my $simple_identifier = qr/([a-zA-Z_][a-zA-Z0-9_\$]*)/o;
my $identifier = qr/  ($simple_identifier
                    | $escaped_identifier)
                      (?{ $foo = $^N })
                   /xo;

$_ = '\\blah!$@%$!^ ';

if (s/$identifier//o) {
    print "Match is $foo\n";
}

$_ = "identifier";

if (s/$identifier//o) {
    print "Match is $foo\n";
}

------

However, in this config, I get the runtime error:

Eval-group not allowed at runtime, use re 'eval' in regex m/  ((?-xism:([a-zA-Z_][a-zA-Z0-9_\$]*))
                    | (?-xism:\\(\S+)(?=\s)))
                      (?{ $foo =.../ at /tmp/re line 10.

But when I had it written like:

------

#!/usr/bin/perl

use strict;
use warnings;

my $foo;

my $escaped_identifier = qr/\\(\S+)(?=\s)(?{ $foo = $^N })/o;
my $simple_identifier = qr/([a-zA-Z_][a-zA-Z0-9_\$]*)(?{ $foo = $^N })/o;
my $identifier = qr/  $simple_identifier
                    | $escaped_identifier
                   /xo;

$_ = '\\blah!$@%$!^ ';

if (s/$identifier//o) {
    print "Match is $foo\n";
}

$_ = "identifier";

if (s/$identifier//o) {
    print "Match is $foo\n";
}

------

I get:

Match is blah!$@%$!^
Match is identifier

As with anything with Perl, the answer is buried in the millions of lines
of source code they call a language.  Any cluepons would be greatly
appreciated.

-Clint


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

Date: 10 Sep 2007 18:21:12 GMT
From: xhoster@gmail.com
Subject: Re: (?{ code }) block works fine in child rule but not in parent
Message-Id: <20070910142114.196$Vi@newsreader.com>

Clint Olsen <clint.olsen@gmail.com> wrote:
>
> However, in this config, I get the runtime error:
>
> Eval-group not allowed at runtime, use re 'eval' in regex m/
> ((?-xism:([a-zA-Z_][a-zA-Z0-9_\$]*))
>                     | (?-xism:\\(\S+)(?=\s)))
>                       (?{ $foo =.../ at /tmp/re line 10.

Did you try adding a "use re 'eval';" like the error message said?

 ...

> As with anything with Perl, the answer is buried in the millions of lines
> of source code they call a language.

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.

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: Mon, 10 Sep 2007 13:35:02 -0500
From: Clint Olsen <clint.olsen@gmail.com>
Subject: Re: (?{ code }) block works fine in child rule but not in parent
Message-Id: <slrnfeb3im.5mi.clint.olsen@belle.0lsen.net>

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?).  I want to avoid using
switches that are 'perilous' when it isn't required.  There isn't a way to
convince the interpreter that I'm not relying on this behavior?

-Clint


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

Date: 10 Sep 2007 19:50:33 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: (?{ code }) block works fine in child rule but not in parent
Message-Id: <slrnfeb7v3.1n7.abigail@alexandra.abigail.be>

                                             _
Clint Olsen (clint.olsen@gmail.com) wrote on VCXXIII September MCMXCIII
in <URL:news:slrnfeb3im.5mi.clint.olsen@belle.0lsen.net>:
&&  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?).  I want to avoid using
&&  switches that are 'perilous' when it isn't required.  There isn't a way to
&&  convince the interpreter that I'm not relying on this behavior?


Yes, it's called "use re 'eval'".



Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
 .qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
 .qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'


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

Date: Mon, 10 Sep 2007 20:50:14 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: (?{ code }) block works fine in child rule but not in parent
Message-Id: <mojgr4-5a2.ln1@osiris.mauzo.dyndns.org>


Quoth Clint Olsen <clint.olsen@gmail.com>:
> 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?).

But you are. From your original post:

| my $escaped_identifier = qr/\\(\S+)(?=\s)/o;
| my $simple_identifier = qr/([a-zA-Z_][a-zA-Z0-9_\$]*)/o;
| my $identifier = qr/  ($simple_identifier
|                     | $escaped_identifier)
|                       (?{ $foo = $^N })
|                    /xo;

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'. The documentation does say this, but it is not entirely clear.
(Patches welcome :) ).

The solution (if you want to avoid re 'eval', which is a good idea) is
to precompile the code assertion into a qr// as well:

    my $escape_id = qr/\\(\S+)(?=\s)/;
    my $simple_id = qr/([a-zA-Z_][a-zA-Z0-9_\$]*/;
    my $capture   = qr/(?{ $foo = $^N })/;
    my $id        = qr/ ($simple_id | $escape_id) $capture /x;

Note that all of your '/o's are redundant, as you are using qr//.

| As with anything with Perl, the answer is buried in the millions of
| lines of source code they call a language.

FWIW, insulting Perl in a Perl newsgroup is not likely to be a way to
get useful advice...

Ben



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

Date: Mon, 10 Sep 2007 08:17:10 -0700
From:  Benoit Lefebvre <benoit.lefebvre@gmail.com>
Subject: Re: Array Question
Message-Id: <1189437430.943074.234450@22g2000hsm.googlegroups.com>

On Sep 10, 10:53 am, Paul Lalli <mri...@gmail.com> wrote:
> On Sep 10, 10:48 am, Benoit Lefebvre <benoit.lefeb...@gmail.com>
> wrote:
>
>
>
> > On Sep 10, 10:38 am, "ame...@iwc.net" <ame...@iwc.net> wrote:
> > > I need to create an array.  Each element will have 1 row and 3
> > > columns.  So, the array would look something like this:
>
> > > $x[1] = 1,2,3
> > > $x[2] = 4,5,6
> > > $x[3] = 7,8,9
>
> > >  Basically, I have 1 row and 3 columns.........how would I store
> > > the values, and retrieve the values???
> > You can make an array of array
>
> > $x[1][1] = 1;
> > $x[1][2] = 2;
> > $x[1][3] = 3;
> > $x[2][1] = 4;
>
> You're sticking undefined values all over the place.  Arrays in Perl
> start with 0, not 1.  You've made $x[0] undefined, as well as $x[1]
> [0], $x[2][0], etc.
>
> > see:<link to pirated material snipped.>
>
> Please don't do that again.  Perl has free built-in documentation
> available.  Reference that.  http://perldoc.perl.org.  Do not post
> links to commercially available material that people have illegally
> duplicated.
>
> Paul Lalli

Oh, sorry for that..

I just realised what it was..

I did a search on google and found that this document was well done
and had what he was requesting for.

--Ben



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

Date: Mon, 10 Sep 2007 08:18:59 -0700
From:  Benoit Lefebvre <benoit.lefebvre@gmail.com>
Subject: Re: Array Question
Message-Id: <1189437539.399386.272190@d55g2000hsg.googlegroups.com>

On Sep 10, 10:55 am, "ame...@iwc.net" <ame...@iwc.net> wrote:
> On Sep 10, 9:51 am, Paul Lalli <mri...@gmail.com> wrote:
>
>
>
> > On Sep 10, 10:38 am, "ame...@iwc.net" <ame...@iwc.net> wrote:
>
> > > I need to create an array.  Each element will have 1 row and 3
> > > columns.  So, the array would look something like this:
>
> > > $x[1] = 1,2,3
> > > $x[2] = 4,5,6
> > > $x[3] = 7,8,9
>
> > my @x = ( [1, 2, 3], [4, 5, 6], [7, 8, 9] );
>
> > OR
>
> > my @x;
> > $x[0] = [ 1, 2, 3 ];
> > $x[1] = [ 4, 5, 6 ];
> > $x[2] = [ 7, 8, 9 ];
>
> > >  Basically, I have 1 row and 3 columns.........how would I store
> > > the values, and retrieve the values???
>
> > print "(0,2) = $x[0][2]\n";
>
> > You need to read up on creating multidimensional structures in Perl:
>
> > perldoc perlreftut
> > perldoc perllol
>
> > Paul Lalli
>
> So, if I would want to use MySQL and pull some values from a table and
> store them in an array, could I use a method like this:
>
> while (($customer_id, $report_name, $report_string) $sel->fetchrow_array()) {
>
>    $y = 0;
>    $info[$x][$y] = $customer_id;
>    $y++
>    $info[$x][$y] = $report_name;
>    $y++
>    $info[$x][$y] = $report_string;
>    $x++;
>
> }
>
> And, if I wanted to use a foreach loop to process the array, can I do
> something like this:
>
> foreach $info (@info) {
>    $customer_id = $info[0];
>    $rpt_name = $info[1];
>    $rpt_str  = $info[2];
>    .
>    .
>    .
>
> }

For that.. maybe you can use an ash or array or ash of ashes



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

Date: Mon, 10 Sep 2007 08:21:21 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: Array Question
Message-Id: <1189437681.524561.304810@50g2000hsm.googlegroups.com>

On Sep 10, 10:55 am, "ame...@iwc.net" <ame...@iwc.net> wrote:
> On Sep 10, 9:51 am, Paul Lalli <mri...@gmail.com> wrote:
> > You need to read up on creating multidimensional structures in
> > Perl:
> > perldoc perlreftut
> > perldoc perllol

> So, if I would want to use MySQL and pull some values from a
> table and store them in an array, could I use a method like this:

> while (($customer_id, $report_name, $report_string) $sel->fetchrow_array()) {
>
>    $y = 0;
>    $info[$x][$y] = $customer_id;
>    $y++
>    $info[$x][$y] = $report_name;
>    $y++
>    $info[$x][$y] = $report_string;
>    $x++;
>
> }

I suppose you *could*, but why would you want to??
my @info;
while (my $ref = $sel->fetchrow_arrayref) {
   push @info, [ @{$ref} ];
}

> And, if I wanted to use a foreach loop to process the array,
> can I do something like this:
>
> foreach $info (@info) {
>    $customer_id = $info[0];
>    $rpt_name = $info[1];
>    $rpt_str  = $info[2];

No. $info is a reference to an array.  You need to dereference the
array.  Did you read those two perldocs I linked you to?

my $customer_id = $info->[0];
my $rpt_name = $info->[1];
my $rpt_str = $info->[2];

OR:

my ($customer_id, $rpt_name, $rpt_str) = @{$info};

Paul Lalli



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

Date: Mon, 10 Sep 2007 08:24:26 -0700
From:  "amerar@iwc.net" <amerar@iwc.net>
Subject: Re: Array Question
Message-Id: <1189437866.765620.47930@w3g2000hsg.googlegroups.com>

On Sep 10, 10:21 am, Paul Lalli <mri...@gmail.com> wrote:
> On Sep 10, 10:55 am, "ame...@iwc.net" <ame...@iwc.net> wrote:
>
>
>
> > On Sep 10, 9:51 am, Paul Lalli <mri...@gmail.com> wrote:
> > > You need to read up on creating multidimensional structures in
> > > Perl:
> > > perldoc perlreftut
> > > perldoc perllol
> > So, if I would want to use MySQL and pull some values from a
> > table and store them in an array, could I use a method like this:
> > while (($customer_id, $report_name, $report_string) $sel->fetchrow_array()) {
>
> >    $y = 0;
> >    $info[$x][$y] = $customer_id;
> >    $y++
> >    $info[$x][$y] = $report_name;
> >    $y++
> >    $info[$x][$y] = $report_string;
> >    $x++;
>
> > }
>
> I suppose you *could*, but why would you want to??
> my @info;
> while (my $ref = $sel->fetchrow_arrayref) {
>    push @info, [ @{$ref} ];
>
> }
> > And, if I wanted to use a foreach loop to process the array,
> > can I do something like this:
>
> > foreach $info (@info) {
> >    $customer_id = $info[0];
> >    $rpt_name = $info[1];
> >    $rpt_str  = $info[2];
>



> No. $info is a reference to an array.  You need to dereference the
> array.  Did you read those two perldocs I linked you to?
>
> my $customer_id = $info->[0];
> my $rpt_name = $info->[1];
> my $rpt_str = $info->[2];
>
> OR:
>
> my ($customer_id, $rpt_name, $rpt_str) = @{$info};
>
> Paul Lalli

Dereference......I see how you are referring to each 'column' in the
array, but how do you access each row of the array?





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

Date: Mon, 10 Sep 2007 16:03:33 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Array Question
Message-Id: <x7zlzu7bje.fsf@mail.sysarch.com>

>>>>> "BL" == Benoit Lefebvre <benoit.lefebvre@gmail.com> writes:

  >> > see:<link to pirated material snipped.>
  >> 
  >> Please don't do that again.  Perl has free built-in documentation
  >> available.  Reference that.  http://perldoc.perl.org.  Do not post
  >> links to commercially available material that people have illegally
  >> duplicated.

  BL> Oh, sorry for that..

  BL> I just realised what it was..

  BL> I did a search on google and found that this document was well done
  BL> and had what he was requesting for.

you should be able to tell a pirated book from a free web document. most
recent computer books which have ebook formats too have pirated copies
on the web.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Mon, 10 Sep 2007 09:10:20 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: Array Question
Message-Id: <1189440620.428647.29160@y42g2000hsy.googlegroups.com>

On Sep 10, 11:24 am, "ame...@iwc.net" <ame...@iwc.net> wrote:
>
> Dereference......I see how you are referring to each 'column' in the
> array, but how do you access each row of the array?- Hide quoted text -

Stop.  Go read those two documents.  Then if you still don't
understand something, come back and ask your question.  I'm not going
to read bits and pieces of the docuements to you for you.

perldoc perlreftut
perldoc perllol

Paul Lalli



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

Date: Mon, 10 Sep 2007 09:13:19 -0700
From:  "amerar@iwc.net" <amerar@iwc.net>
Subject: Re: Array Question
Message-Id: <1189440799.026648.28280@19g2000hsx.googlegroups.com>

On Sep 10, 11:10 am, Paul Lalli <mri...@gmail.com> wrote:
> On Sep 10, 11:24 am, "ame...@iwc.net" <ame...@iwc.net> wrote:
>
>
>
> > Dereference......I see how you are referring to each 'column' in the
> > array, but how do you access each row of the array?- Hide quoted text -
>
> Stop.  Go read those two documents.  Then if you still don't
> understand something, come back and ask your question.  I'm not going
> to read bits and pieces of the docuements to you for you.
>
> perldoc perlreftut
> perldoc perllol
>
> Paul Lalli

Read the documents.  Everything refers to dereferencing, but nothing
really gives an example on running through a loop and accessing each
row, and then accessing columns.   Just a bit confusing for me.  Not
asking for someone to do it, but since I do not understand, a small
example would help.




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

Date: Mon, 10 Sep 2007 10:39:14 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Array Question
Message-Id: <100920071039147625%jgibson@mail.arc.nasa.gov>

In article <1189440799.026648.28280@19g2000hsx.googlegroups.com>,
<"amerar@iwc.net"> wrote:

> On Sep 10, 11:10 am, Paul Lalli <mri...@gmail.com> wrote:

> > perldoc perlreftut
> > perldoc perllol

> 
> Read the documents.  Everything refers to dereferencing, but nothing
> really gives an example on running through a loop and accessing each
> row, and then accessing columns.   Just a bit confusing for me.  Not
> asking for someone to do it, but since I do not understand, a small
> example would help.

Read 'perldoc perllol' and search for the section titled 'Access and
Printing'. It has examples on accessing an array of arrays (your
problem), including the following:

    for $i ( 0 .. $#AoA ) {
      for $j ( 0 .. $#{$AoA[$i]} ) {
        print "elt $i $j is $AoA[$i][$j]\n";
      }
    }

After reading that, post any questions you have about that text.

-- 
Jim Gibson

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


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

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


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