[32749] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4013 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 12 14:09:40 2013

Date: Mon, 12 Aug 2013 11:09:04 -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, 12 Aug 2013     Volume: 11 Number: 4013

Today's topics:
        Help With Security <chiragsharma.guru99@gmail.com>
    Re: Help With Security <uri@stemsystems.com>
    Re: Help With Security <uri@stemsystems.com>
    Re: s modifier doesn't seem to work fmassion@web.de
    Re: s modifier doesn't seem to work <hjp-usenet3@hjp.at>
    Re: s modifier doesn't seem to work <ben@morrow.me.uk>
    Re: s modifier doesn't seem to work fmassion@web.de
    Re: s modifier doesn't seem to work <hjp-usenet3@hjp.at>
    Re: s modifier doesn't seem to work <derykus@gmail.com>
    Re: s modifier doesn't seem to work <derykus@gmail.com>
    Re: s modifier doesn't seem to work <ben@morrow.me.uk>
    Re: s modifier doesn't seem to work <ben@morrow.me.uk>
    Re: s modifier doesn't seem to work <derykus@gmail.com>
    Re: s modifier doesn't seem to work <ben@morrow.me.uk>
    Re: s modifier doesn't seem to work <derykus@gmail.com>
    Re: s modifier doesn't seem to work <derykus@gmail.com>
    Re: s modifier doesn't seem to work <ben@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 12 Aug 2013 03:28:23 -0700 (PDT)
From: chirag sharma <chiragsharma.guru99@gmail.com>
Subject: Help With Security
Message-Id: <1cef3ed7-7e29-4d9b-adbf-6cfb95a3b321@googlegroups.com>

I have created an online PERL code executor at http://web.guru99.com/perl-t=
utorials/=20
Though I have checked all security aspects =85 do you experts see any major=
 flaw that I need to=20
care of?"


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

Date: Mon, 12 Aug 2013 14:02:14 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Help With Security
Message-Id: <87eh9ywzx5.fsf@stemsystems.com>

>>>>> "cs" == chirag sharma <chiragsharma.guru99@gmail.com> writes:

  cs> I have created an online PERL code executor at
  cs> http://web.guru99.com/perl-tutorials/
  cs> Though I have checked all security aspects … do you experts see any
  cs> major flaw that I need to
  cs> care of?"

did you see my reply the other day? read it first and then delete your
site. it is buggy and not contributing anything to the perl
community. you are asking experts and we are telling you this. if you
don't listen, that is on you.

uri


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

Date: Mon, 12 Aug 2013 14:03:06 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Help With Security
Message-Id: <878v06wzvp.fsf@stemsystems.com>

>>>>> "cs" == chirag sharma <chiragsharma.guru99@gmail.com> writes:

  cs> I have created an online PERL code executor at
  cs> http://web.guru99.com/perl-tutorials/
  cs> Though I have checked all security aspects … do you experts see any
  cs> major flaw that I need to
  cs> care of?"

did you see my reply the other day? read it first and then delete your
site. it is buggy and not contributing anything to the perl
community. you are asking experts and we are telling you this. if you
don't listen, that is on you.

uri


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

Date: Sun, 11 Aug 2013 02:49:21 -0700 (PDT)
From: fmassion@web.de
Subject: Re: s modifier doesn't seem to work
Message-Id: <540c559c-bde0-4f69-9ef1-22a76369e634@googlegroups.com>

Am Samstag, 10. August 2013 21:57:07 UTC+2 schrieb Ben Morrow:
> [Please quote properly: that is, put your reply underneath the bit of
>=20
> text you are replying to. It's also not helpful to keep replying to
>=20
> yourself; instead you should reply to the article you are, um, replying
>=20
> to. You appear to be using Google Groups, which has recently started
>=20
> inserting extra blank lines whenever it quotes something; if you can't
>=20
> find any way of turning this off you need to remove them by hand before
>=20
> posting.]
>=20
>=20
>=20
> Quoth fmassion@web.de:
>=20
> > Am Samstag, 10. August 2013 11:16:58 UTC+2 schrieb fmas...@web.de:
>=20
> > >=20
>=20
> > > I am currently testing a string search over line breaks.=20
>=20
> [...]
>=20
> > >=20
>=20
> > > This is a code extract:=20
>=20
> > >=20
>=20
> > > foreach $satz (@satz) {=20
>=20
> > > chomp $satz;=20
>=20
> > > if ($satz =3D~ m/\d(?s)(.*)keine/g) {=20
>=20
> > >         $satz =3D~ s/$&/xxxx/g;=20
>=20
> > > }=20
>=20
> > >         print "$satz\n";=20
>=20
> > > }=20
>=20
> > >=20
>=20
> > >=20
>=20
> > >=20
>=20
> > > I would expect the following result for the first three lines:=20
>=20
> > > 'Das ist ein Beispiel mit xxxxx Zahl.'=20
>=20
> > >=20
>=20
> > > With this search string, I get however no match. I have entered the
>=20
> >=20
>=20
> > This works as expected, but I don't quite understand what happens
>=20
> >=20
>=20
> > undef $/;
>=20
>=20
>=20
> This is documented in perldoc perlvar, under $/. Setting $/ to undef
>=20
> causes <> to read the whole file in one go. This means you now have your
>=20
> whole file in one string, so the s/// works over multiple lines.
>=20
>=20
>=20
> > while (<DATA>) {
>=20
>=20
>=20
> Since you are reading the whole file, there will only ever be one entry
>=20
> to loop over, so you don't really need a loop.
>=20
>=20
>=20
> > 	chomp;
>=20
>=20
>=20
> With $/=3Dundef chomp doesn't do anything.
>=20
>=20
>=20
> > 	print "$_<<\n";
>=20
> > s/\d(.*)Zahl/xxxx/sg;=20
>=20
> > print "\n$_\n"=20
>=20
> > }=20
>=20
> >  It searches over the first 3 lines and outputs as expected:=20
>=20
> > 'Das ist ein Beispiel mit xxxx'
>=20
>=20
>=20
> Since you're only doing one substitution it would be better to use an
>=20
> ordinary named variable and no loop:
>=20
>=20
>=20
>     my $text =3D <DATA>;
>=20
>     print "$text<<\n";
>=20
>=20
>=20
>     $text =3D~ s/\d(.*)Zahl/xxxx/sg;
>=20
>     print "\n$text\n";
>=20
>=20
>=20
> Ben

[Sorry for not replying properly. I hope this is OK now]

I understand what 'undef $/' does but it seems to be a workaround. Basicall=
y my goal is:

1) Read a text in an array
2) Iterate through the variables of the array: 'foreach $satz (@satz)'
3) Test various search and replace Regex (as a matter of fact I am working =
through the Regex Cookbook of Jan Goyvaerts & Steven Levithan). In this con=
text, one of several tests concerns the s modifier. I just wonder why it is=
n't possible to search for an expressions which spread over more than one l=
ine if I add this modifier. It works in UltraEdit. It works in a few other =
tools as well but I can't make it function in my perl script. If I use the =
undefine-workaround, other search expressions (e.g. with $ to mark the end =
of the string) won't work.

In one of the tools I use (Expresso), I see that the EOL is coded as [CR][L=
F]. Is this a reason for the problem with the s modifier?


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

Date: Sun, 11 Aug 2013 14:11:32 +0200
From: "Peter J. Holzer" <hjp-usenet3@hjp.at>
Subject: Re: s modifier doesn't seem to work
Message-Id: <slrnl0evrk.asu.hjp-usenet3@hrunkner.hjp.at>

On 2013-08-11 09:49, fmassion@web.de <fmassion@web.de> wrote:
> Am Samstag, 10. August 2013 21:57:07 UTC+2 schrieb Ben Morrow:
>> [Please quote properly: that is, put your reply underneath the bit of
>> 
>> text you are replying to. It's also not helpful to keep replying to
>> 
>> yourself; instead you should reply to the article you are, um, replying
>> 
>> to. You appear to be using Google Groups, which has recently started
>> 
>> inserting extra blank lines whenever it quotes something; if you can't
>> 
>> find any way of turning this off you need to remove them by hand before
>> 
>> posting.]
>> 
>> 
>> 
>> Quoth fmassion@web.de:
>> 
>> > Am Samstag, 10. August 2013 11:16:58 UTC+2 schrieb fmas...@web.de:
>> 
>> > > 
>> 
>> > > I am currently testing a string search over line breaks. 
>> 
>> [...]
>> 
>> > > 
>> 
>> > > This is a code extract: 
>> 
>> > > 
>> 
>> > > foreach $satz (@satz) { 
>> 
>> > > chomp $satz; 
>> 
>> > > if ($satz =~ m/\d(?s)(.*)keine/g) { 
>> 
>> > >         $satz =~ s/$&/xxxx/g; 
>> 
>> > > } 
>> 
>> > >         print "$satz\n"; 
>> 
>> > > } 
>> 
>> > > 
>> 
>> > > 
>> 
>> > > 
>> 
>> > > I would expect the following result for the first three lines: 
>> 
>> > > 'Das ist ein Beispiel mit xxxxx Zahl.' 
>> 
>> > > 
>> 
>> > > With this search string, I get however no match. I have entered the
>> 
>> > 
>> 
>> > This works as expected, but I don't quite understand what happens
>> 
>> > 
>> 
>> > undef $/;
>> 
[...]
> [Sorry for not replying properly. I hope this is OK now]

Not really. You are still quoting everything (whether it is relevant or
not) and you haven't removed the empty lines inserted by google. So we
have scroll/read through 130 lines on quotes which may or may not be
relevant. I dare say that not every one of us has the patience.

Do yourself and us a favour, get a real Newsreader and use one of the
free news servers (e.g. albasani).


> I understand what 'undef $/' does but it seems to be a workaround.
> Basically my goal is:
>
> 1) Read a text in an array

What are the elements of the array? Lines?


> 2) Iterate through the variables of the array: 'foreach $satz (@satz)'

So in each iteration of the loop you are looking at one line in
isolation.


> 3) Test various search and replace Regex (as a matter of fact I am
> working through the Regex Cookbook of Jan Goyvaerts & Steven
> Levithan). In this context, one of several tests concerns the s
> modifier. I just wonder why it isn't possible to search for an
> expressions which spread over more than one line if I add this
> modifier.

That's what the /s modifier does. But there have to be actually several
lines in the variable you are looking at for this to work. If the other
lines are in different variables, how can perl know that you would want
to match those other variables, too, especially if to tell it
explicitely to look only at this variable?

> It works in UltraEdit. It works in a few other tools as well

That's because UltraEdit and those other tools treat the whole text as
unit. But your script (not Perl - *your* script) splits it into many
small units and looks at each of them in isolation. None of these small
units matches.

	hp


-- 
   _  | Peter J. Holzer    | Fluch der elektronischen Textverarbeitung:
|_|_) | Sysadmin WSR       | Man feilt solange an seinen Text um, bis
| |   | hjp@hjp.at         | die Satzbestandteile des Satzes nicht mehr
__/   | http://www.hjp.at/ | zusammenpaßt. -- Ralph Babel


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

Date: Sun, 11 Aug 2013 13:43:00 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: s modifier doesn't seem to work
Message-Id: <kfdkda-ick.ln1@anubis.morrow.me.uk>


Quoth fmassion@web.de:
> 
> [Sorry for not replying properly. I hope this is OK now]

Nope, the blank lines are still there.

> I understand what 'undef $/' does but it seems to be a workaround.
> Basically my goal is:
> 
> 1) Read a text in an array
> 2) Iterate through the variables of the array: 'foreach $satz (@satz)'

Why do you want it in an array, rather than a single string?

> 3) Test various search and replace Regex (as a matter of fact I am
> working through the Regex Cookbook of Jan Goyvaerts & Steven Levithan).
> In this context, one of several tests concerns the s modifier. I just
> wonder why it isn't possible to search for an expressions which spread
> over more than one line if I add this modifier. It works in UltraEdit.

As I said before, that tells you nothing about whether or not it will
work in Perl, since UltraEdit uses different regexes from Perl. (AFAICT
UltraEdit's patterns behave as if they always had /sm.)

> It works in a few other tools as well but I can't make it function in my
> perl script. If I use the undefine-workaround, other search expressions
> (e.g. with $ to mark the end of the string) won't work.

To make ^ and $ match at the beginning and end of any line in a
multi-line string you need /m.

> In one of the tools I use (Expresso), I see that the EOL is coded as
> [CR][LF]. Is this a reason for the problem with the s modifier?

No, though it will mess up patterns with $ in unless you get rid of
those CRs. Are you on Windows? If you are, they will be handled
automatically, since CRLF is the default line ending on Windows.
Otherwise, you need to run

    binmode $FILEHANDLE, ":crlf";

on the filehandle you are reading from.

Ben



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

Date: Sun, 11 Aug 2013 08:42:03 -0700 (PDT)
From: fmassion@web.de
Subject: Re: s modifier doesn't seem to work
Message-Id: <afcce491-1bc6-43e3-99b0-30b73ada64e6@googlegroups.com>

Am Samstag, 10. August 2013 11:16:58 UTC+2 schrieb fmas...@web.de:
>> [Sorry for not replying properly. I hope this is OK now] 
>Nope, the blank lines are still there. 
Sorry to Peter, Ben and all of you. I hope it's fine now
[...]
>> 2) Iterate through the variables of the array: 'foreach $satz (@satz)' 
>Why do you want it in an array, rather than a single string? 
Because I may want to do things only with the $satz variables which meet the regex. E.g. send them to another array or whatever. This isn't possible when I read only one big large string.


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

Date: Sun, 11 Aug 2013 18:23:44 +0200
From: "Peter J. Holzer" <hjp-usenet3@hjp.at>
Subject: Re: s modifier doesn't seem to work
Message-Id: <slrnl0fekg.i2b.hjp-usenet3@hrunkner.hjp.at>

On 2013-08-11 15:42, fmassion@web.de <fmassion@web.de> wrote:
> Am Samstag, 10. August 2013 11:16:58 UTC+2 schrieb fmas...@web.de:
>>> [Sorry for not replying properly. I hope this is OK now] 
>>Nope, the blank lines are still there. 
> Sorry to Peter, Ben and all of you. I hope it's fine now

Not quite, but a lot better, thanks.


>>> 2) Iterate through the variables of the array: 'foreach $satz (@satz)' 
>>Why do you want it in an array, rather than a single string? 
> Because I may want to do things only with the $satz variables which
> meet the regex.

Apparently none of them does.

	hp


-- 
   _  | Peter J. Holzer    | Fluch der elektronischen Textverarbeitung:
|_|_) | Sysadmin WSR       | Man feilt solange an seinen Text um, bis
| |   | hjp@hjp.at         | die Satzbestandteile des Satzes nicht mehr
__/   | http://www.hjp.at/ | zusammenpaßt. -- Ralph Babel


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

Date: Sun, 11 Aug 2013 11:59:07 -0700
From: Charles DeRykus <derykus@gmail.com>
Subject: Re: s modifier doesn't seem to work
Message-Id: <ku8mut$3ad$2@speranza.aioe.org>

On 8/11/2013 8:42 AM, fmassion@web.de wrote:
> Am Samstag, 10. August 2013 11:16:58 UTC+2 schrieb fmas...@web.de:
>>> [Sorry for not replying properly. I hope this is OK now]
>> Nope, the blank lines are still there.
> Sorry to Peter, Ben and all of you. I hope it's fine now
> [...]
>>> 2) Iterate through the variables of the array: 'foreach $satz (@satz)'
>> Why do you want it in an array, rather than a single string?
> Because I may want to do things only with the $satz variables which meet the regex.

E.g. send them to another array or whatever. This isn't possible when I 
read only one big large string.
>

The problem is the match may extend over several $satz.  If you wanted 
to identify those individual $satz which are part of the match,  you 
could do something like this:

   my @satz = <DATA>;
   my $alles = join('', @satz);

   my $match;
   if ( $alles =~ /^.*\d.*Zahl.*?\n/gsmap ) {
      $match = ${^MATCH};
      foreach my $satz (@satz) {
          if ( $match =~ /$satz/ ) {
              #print "sentence is part of match: $satz"
              ...
          }
      }
   }

-- 
Charles DeRykus




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

Date: Sun, 11 Aug 2013 12:11:06 -0700
From: Charles DeRykus <derykus@gmail.com>
Subject: Re: s modifier doesn't seem to work
Message-Id: <ku8nle$69f$1@speranza.aioe.org>

On 8/11/2013 11:59 AM, Charles DeRykus wrote:
> ...
>
>    my @satz = <DATA>;
>    my $alles = join('', @satz);
>
>    my $match;
>    if ( $alles =~ /^.*\d.*Zahl.*?\n/gsmap ) {
>       $match = ${^MATCH};
>       foreach my $satz (@satz) {
>           if ( $match =~ /$satz/ ) {
>               #print "sentence is part of match: $satz"
>               ...
>           }
>       }
>    }
>

You could omit /p too:

my $match;
if ( $alles =~ /^(.*\d.*Zahl.*?\n)/gsma ) {
     $match = $1;
     foreach my $satz (@satz) {
         if ( $match =~ /$satz/ ) {
             #print "sentence is part of match: $satz"
             ...
         }
     }
}




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

Date: Sun, 11 Aug 2013 22:35:57 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: s modifier doesn't seem to work
Message-Id: <tmclda-5on.ln1@anubis.morrow.me.uk>


Quoth Charles DeRykus <derykus@gmail.com>:
> On 8/11/2013 11:59 AM, Charles DeRykus wrote:
> > ...
> >
> >    my @satz = <DATA>;
> >    my $alles = join('', @satz);
> >
> >    my $match;
> >    if ( $alles =~ /^.*\d.*Zahl.*?\n/gsmap ) {
> >       $match = ${^MATCH};
> >       foreach my $satz (@satz) {
> >           if ( $match =~ /$satz/ ) {
> >               #print "sentence is part of match: $satz"
> >               ...
> >           }
> >       }
> >    }
> >
> 
> You could omit /p too:
> 
> my $match;
> if ( $alles =~ /^(.*\d.*Zahl.*?\n)/gsma ) {
>      $match = $1;

    if (my ($match) = $alles =~ /^(...)/gsma) {

Ben



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

Date: Sun, 11 Aug 2013 22:34:17 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: s modifier doesn't seem to work
Message-Id: <pjclda-5on.ln1@anubis.morrow.me.uk>


Quoth Charles DeRykus <derykus@gmail.com>:
> On 8/11/2013 8:42 AM, fmassion@web.de wrote:
> > Am Samstag, 10. August 2013 11:16:58 UTC+2 schrieb fmas...@web.de:
> >>> [Sorry for not replying properly. I hope this is OK now]
> >> Nope, the blank lines are still there.
> > Sorry to Peter, Ben and all of you. I hope it's fine now
> > [...]
> >>> 2) Iterate through the variables of the array: 'foreach $satz (@satz)'
> >> Why do you want it in an array, rather than a single string?
> > Because I may want to do things only with the $satz variables which
> meet the regex.
> 
> E.g. send them to another array or whatever. This isn't possible when I 
> read only one big large string.
> >
> 
> The problem is the match may extend over several $satz.  If you wanted 
> to identify those individual $satz which are part of the match,  you 
> could do something like this:
> 
>    my @satz = <DATA>;
>    my $alles = join('', @satz);
> 
>    my $match;
>    if ( $alles =~ /^.*\d.*Zahl.*?\n/gsmap ) {
>       $match = ${^MATCH};
>       foreach my $satz (@satz) {
>           if ( $match =~ /$satz/ ) {

    /^\Q$satz/m

Also, this may pick up lines that were not part of the originally-
matched text. Given that the match is anchored to a whole line fore-and-
aft ($satz will contain a trailing newline) this can only happen with
whole duplicated lines, but it may still be a problem.

I would rather do this by matching on the whole string and then
splitting the result into lines if necessary, though it's still not
clear (at least to me) what the OP is trying to achieve here. fmassion,
can you explain a little more what you're trying to do? What does the
rest of the code surrounding this bit look like?

Ben



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

Date: Sun, 11 Aug 2013 16:53:55 -0700
From: Charles DeRykus <derykus@gmail.com>
Subject: Re: s modifier doesn't seem to work
Message-Id: <ku987p$e5k$1@speranza.aioe.org>

On 8/11/2013 2:34 PM, Ben Morrow wrote:
>
> Quoth Charles DeRykus <derykus@gmail.com>:

 >...

>>
>> The problem is the match may extend over several $satz.  If you wanted
>> to identify those individual $satz which are part of the match,  you
>> could do something like this:
>>
>>     my @satz = <DATA>;
>>     my $alles = join('', @satz);
>>
>>     my $match;
>>     if ( $alles =~ /^.*\d.*Zahl.*?\n/gsmap ) {
>>        $match = ${^MATCH};
>>        foreach my $satz (@satz) {
>>            if ( $match =~ /$satz/ ) {
>
>      /^\Q$satz/m
>
> Also, this may pick up lines that were not part of the originally-
> matched text. Given that the match is anchored to a whole line fore-and-
> aft ($satz will contain a trailing newline) this can only happen with
> whole duplicated lines, but it may still be a problem.

And it's been bothering me since posting... here's a messier solution
to ensure sentences overlap the target begin/end positions:

use 5.012;  # so each will work on arrays
 ...
my @satz = <DATA>;
my $alles = join('', @satz);

my ($b, $e) = (0, 0);
my @pos = map { $b= $e+1 if $e; $e += (length($_)-1); [$b,$e] } @satz;

if ( $alles =~ /^(.*\d.*Zahl.*?\n)/gsma ) {
      my($match, $begin, $end) = ($1, $-[0], $+[0]);

      while( my($i,$satz) = each @satz ) {
          next unless ($pos[$i][0] >= $begin and $pos[$i][0] <= $end)
                   or ($pos[$i][1] >= $begin and $pos[$i][1] <= $end);

          if ( $match =~ /$satz/ ) {
              print "sentence is part of match: $satz\n\n"
              ...
          }
      }
}



>
> I would rather do this by matching on the whole string and then
> splitting the result into lines if necessary, though it's still not
> clear (at least to me) what the OP is trying to achieve here. fmassion,
> can you explain a little more what you're trying to do? What does the
> rest of the code surrounding this bit look like?
>
>


-- 
Charles DeRykus


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

Date: Mon, 12 Aug 2013 01:42:07 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: s modifier doesn't seem to work
Message-Id: <vjnlda-tto2.ln1@anubis.morrow.me.uk>


Quoth Charles DeRykus <derykus@gmail.com>:
> On 8/11/2013 2:34 PM, Ben Morrow wrote:
> >
> > Quoth Charles DeRykus <derykus@gmail.com>:
> >>
> >> The problem is the match may extend over several $satz.  If you wanted
> >> to identify those individual $satz which are part of the match,  you
> >> could do something like this:
> >>
> >>     my @satz = <DATA>;
> >>     my $alles = join('', @satz);
> >>
> >>     my $match;
> >>     if ( $alles =~ /^.*\d.*Zahl.*?\n/gsmap ) {
> >>        $match = ${^MATCH};
> >>        foreach my $satz (@satz) {
> >>            if ( $match =~ /$satz/ ) {
> >
> >      /^\Q$satz/m
> >
> > Also, this may pick up lines that were not part of the originally-
> > matched text. Given that the match is anchored to a whole line fore-and-
> > aft ($satz will contain a trailing newline) this can only happen with
> > whole duplicated lines, but it may still be a problem.
> 
> And it's been bothering me since posting... here's a messier solution
> to ensure sentences overlap the target begin/end positions:
> 
> use 5.012;  # so each will work on arrays
> ...
> my @satz = <DATA>;
> my $alles = join('', @satz);
> 
> my ($b, $e) = (0, 0);
> my @pos = map { $b= $e+1 if $e; $e += (length($_)-1); [$b,$e] } @satz;
> 
> if ( $alles =~ /^(.*\d.*Zahl.*?\n)/gsma ) {

That .* will match across newlines, so the ^ (and the /m) does nothing.

>       my($match, $begin, $end) = ($1, $-[0], $+[0]);
> 
>       while( my($i,$satz) = each @satz ) {
>           next unless ($pos[$i][0] >= $begin and $pos[$i][0] <= $end)
>                    or ($pos[$i][1] >= $begin and $pos[$i][1] <= $end);
> 
>           if ( $match =~ /$satz/ ) {

You're still not quoting $satz. It's really important to quote user data
before interpolating it into a pattern. You're also not anchoring the
match at the beginning, so a line will match if it only ends with $satz.

>               print "sentence is part of match: $satz\n\n"
>               ...
>           }
>       }
> }

But this is still a great deal more complicated than

    my $alles = slurp \*DATA;

    while (my ($match) = 
        $alles =~ /([^\n]* \d .* Zahl [^\n]*)/gsx
        # or perhaps /(.* \d (?s:.)* Zahl .*)/gx
        # or /(\N* \d .* Zahl \N*)/gsx if you've got 5.12
    ) {
        for my $satz (split /\n/, $match) {
        # make that /(?<=\n)/ if you don't want to chomp
            print "sentence is part of match: $satz\n\n";
        }
    }

Ben



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

Date: Sun, 11 Aug 2013 18:58:44 -0700
From: Charles DeRykus <derykus@gmail.com>
Subject: Re: s modifier doesn't seem to work
Message-Id: <ku9fhq$s7u$1@speranza.aioe.org>

On 8/11/2013 5:42 PM, Ben Morrow wrote:
>
>> ...
>> use 5.012;  # so each will work on arrays
>> ...
>> my @satz = <DATA>;
>> my $alles = join('', @satz);
>>
>> my ($b, $e) = (0, 0);
>> my @pos = map { $b= $e+1 if $e; $e += (length($_)-1); [$b,$e] } @satz;
>>
>> if ( $alles =~ /^(.*\d.*Zahl.*?\n)/gsma ) {
>
> That .* will match across newlines, so the ^ (and the /m) does nothing.
>
>>        my($match, $begin, $end) = ($1, $-[0], $+[0]);
>>
>>        while( my($i,$satz) = each @satz ) {
>>            next unless ($pos[$i][0] >= $begin and $pos[$i][0] <= $end)
>>                     or ($pos[$i][1] >= $begin and $pos[$i][1] <= $end);
>>
>>            if ( $match =~ /$satz/ ) {
>
> You're still not quoting $satz. It's really important to quote user data
> before interpolating it into a pattern. You're also not anchoring the
> match at the beginning, so a line will match if it only ends with $satz.
>

Thanks, I'm missed that... very important to be there.

>>                print "sentence is part of match: $satz\n\n"
>>                ...
>>            }
>>        }
>> }
>
> But this is still a great deal more complicated than
>
>      my $alles = slurp \*DATA;
>
>      while (my ($match) =
>          $alles =~ /([^\n]* \d .* Zahl [^\n]*)/gsx
>          # or perhaps /(.* \d (?s:.)* Zahl .*)/gx
>          # or /(\N* \d .* Zahl \N*)/gsx if you've got 5.12
>      ) {
>          for my $satz (split /\n/, $match) {
>          # make that /(?<=\n)/ if you don't want to chomp
>              print "sentence is part of match: $satz\n\n";
>          }
>      }
>

Yes, I agree that's conciser and  clearer to many.
But, it'll loop endlessly :)

I think you probably meant:

     while ( $alles =~ /([^\n]* \d .* Zahl [^\n]*)/gsx;
        my $match = $1;
        ...
     }

-- 
Charles DeRykus



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

Date: Mon, 12 Aug 2013 00:28:59 -0700
From: Charles DeRykus <derykus@gmail.com>
Subject: Re: s modifier doesn't seem to work
Message-Id: <kua2t1$2r9$1@speranza.aioe.org>

On 8/11/2013 6:58 PM, Charles DeRykus wrote:
> ...
> I think you probably meant:
>
>      while ( $alles =~ /([^\n]* \d .* Zahl [^\n]*)/gsx;
                                                      ^^^^

And of course that should be:  "/gsx ) {"  rather than: ";"
-- 
Charles DeRykus


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

Date: Mon, 12 Aug 2013 12:40:47 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: s modifier doesn't seem to work
Message-Id: <v6umda-q3u.ln1@anubis.morrow.me.uk>


Quoth Charles DeRykus <derykus@gmail.com>:
> On 8/11/2013 5:42 PM, Ben Morrow wrote:
> >
> > But this is still a great deal more complicated than
> >
> >      my $alles = slurp \*DATA;
> >
> >      while (my ($match) =
> >          $alles =~ /([^\n]* \d .* Zahl [^\n]*)/gsx
> >          # or perhaps /(.* \d (?s:.)* Zahl .*)/gx
> >          # or /(\N* \d .* Zahl \N*)/gsx if you've got 5.12
> >      ) {
> >          for my $satz (split /\n/, $match) {
> >          # make that /(?<=\n)/ if you don't want to chomp
> >              print "sentence is part of match: $satz\n\n";
> >          }
> >      }
> >
> 
> Yes, I agree that's conciser and  clearer to many.
> But, it'll loop endlessly :)

Oh, yuck.

> I think you probably meant:
> 
>      while ( $alles =~ /([^\n]* \d .* Zahl [^\n]*)/gsx;
>         my $match = $1;

No, I think I meant

    for my $match ($alles =~ /.../) {

Ben



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

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:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 4013
***************************************


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