[22022] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4244 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 10 21:10:39 2002

Date: Tue, 10 Dec 2002 18:10:12 -0800 (PST)
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, 10 Dec 2002     Volume: 10 Number: 4244

Today's topics:
    Re: reg exp problem (jaya prakash)
    Re: reg exp problem (Tad McClellan)
    Re: reg exp problem (jaya prakash)
    Re: reg exp problem (Tad McClellan)
    Re: reg exp problem (Malcolm Dew-Jones)
    Re: RegEx question? <mgjv@tradingpost.com.au>
    Re: Sending Email? <bacchi@rpi.edu>
    Re: Sending Email? <bacchi@rpi.edu>
    Re: Sending Email? <bacchi@rpi.edu>
    Re: which UI for Perl? <xxxxxxx@xxx.xxx>
    Re: Why doesn't my array grow? (Rob Richardson)
    Re: Why doesn't my array grow? <jeff@vpservices.com>
    Re: Why doesn't my array grow? <mbudash@sonic.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 10 Dec 2002 11:23:51 -0800
From: prakashrj@hotmail.com (jaya prakash)
Subject: Re: reg exp problem
Message-Id: <ee5d9.0212101123.5f71b6b9@posting.google.com>

tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnatpsjj.2ns.tadmc@magna.augustmail.com>...
> Tad McClellan <tadmc@augustmail.com> wrote:
> > jaya prakash <prakashrj@hotmail.com> wrote:
> >> 
> >> The following code snippet which was part my program  was giving the
> >> same output for Diffrent Data Inputs. 
> > 
> > 
> > What were you expecting it to do that it is not doing?
> > 
> > It looks straightforward to me, so I can't help explain why
> > it doesn't do what you expected, because you have neglected
> > to say what it is that you expected.  :-)
> > 
> > 
> >> I am not able to comprehend the
> >> reason behind it and any help will be greatly appreciated.
> > 
> > 
> > Your pattern will match when there are 24 consectutive "t"s
> > in the string.
> > 
> > There are 24 consecutive "t"s in both strings, so they
> > both match. What's the problem?
> > 
> > You would need 27 "t"s to get another \1 match, 25 is not enough,
> > since \1 contains 3 characters.
> 
> 
> On rereading this, I think I see what it was that you might
> have been expecting...
> 
> Your pattern was:
> 
>    m/(.{1,3})\1{7,}/

to eliminate greediness i have modified the pattern matching
expression to the following.

m/(.)\1{7,}|(..)\2{7,}|(...)\3{7,}/

but it's still I am not able to comprehend its behaviour.  for
example:

my $sequence = "xyzagagagagagagagagaglmn";

I was expecting it to match 'agagagagagagagagag' between xyz and lmn.
while its only matching
'gagagagagagagaga' . any reason for this behaviour

> Were you expecting that the regex engine would backtrack to
> choose the 1 in {1,3}, and hence match any char series of
> 8 or more characters?
> 
> That does not happen because perl will only backtrack when
> its earlier decision causes the overall match to fail.
> 
> With your original data, perl greedily chooses the 3 in {1,3}
> and does not reconsider that decision because the overall
> match can succeed with that decision as it is.
> 
> With data like:
> 
>    my $sequence = 'tttttttxyzttttttttabctttttttttdef'; # 7,8,9 "t" chars
> 
> It _will_ backtrack to choose the 1 in {1,3} for the 2nd two
> runs of "t" characters, because the match will fail if it 
> doesn't backtrack.


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

Date: Tue, 10 Dec 2002 15:41:41 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: reg exp problem
Message-Id: <slrnavcnsl.3lq.tadmc@magna.augustmail.com>


[ Please *trim* your replies if you want me to read them ]


jaya prakash <prakashrj@hotmail.com> wrote:

[big snip]

> to eliminate greediness i have modified the pattern matching
> expression to the following.
> 
> m/(.)\1{7,}|(..)\2{7,}|(...)\3{7,}/
> 
> but it's still I am not able to comprehend its behaviour.  for
> example:
> 
> my $sequence = "xyzagagagagagagagagaglmn";
> 
> I was expecting it to match 'agagagagagagagagag' between xyz and lmn.


That _is_ what it matches!


> while its only matching
> 'gagagagagagagaga' . any reason for this behaviour


any reason for thinking that 'gagagagagagagaga' is what it is matching?

Got a short and complete program that duplicates the problem?

Have you seen the Posting Guidelines that are posted here weekly?


------------------------------------------
#!/usr/bin/perl
use warnings;
use strict;

my $sequence = "xyzagagagagagagagagaglmn";

if ( $sequence =~ m/(.)\1{7,}|(..)\2{7,}|(...)\3{7,}/ ) {
   print "($&)\n";
}
------------------------------------------

output:

(agagagagagagagagag)


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


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

Date: 10 Dec 2002 14:30:41 -0800
From: prakashrj@hotmail.com (jaya prakash)
Subject: Re: reg exp problem
Message-Id: <ee5d9.0212101430.5b848988@posting.google.com>

a short program that will duplicate the behaviour.
#!/usr/local/bin/perl -w

#my $sequence = "xyzagagagagagagagagaglmn";
my $sequence = "xyzaaaaaaaaaaaaaagagagagagagagagaggaaaaaaaaacaacaaacaaaaaclmn";

while($sequence =~ /(.)\1{7,}|(..)\2{7,}|(...)\3{7,}/g) {
        print "$&\n";
}


output: 

aaaaaaaaaaaaaa
gagagagagagagaga
aaaaaaaaa

I am expecting the following output.

aaaaaaaaaaaaaa
agagagagagagagagag
aaaaaaaaa

I see the reason for its behaviour but can you please let me know what
I should do to get the expected output.

Thanks.


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

Date: Tue, 10 Dec 2002 17:27:36 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: reg exp problem
Message-Id: <slrnavcu38.3us.tadmc@magna.augustmail.com>

jaya prakash <prakashrj@hotmail.com> wrote:
> a short program that will duplicate the behaviour.
> #!/usr/local/bin/perl -w
> 
> #my $sequence = "xyzagagagagagagagagaglmn";
> my $sequence = "xyzaaaaaaaaaaaaaagagagagagagagagaggaaaaaaaaacaacaaacaaaaaclmn";
> 
> while($sequence =~ /(.)\1{7,}|(..)\2{7,}|(...)\3{7,}/g) {
>         print "$&\n";
> }
> 
> output: 
> 
> aaaaaaaaaaaaaa
> gagagagagagagaga
> aaaaaaaaa
> 
> I am expecting the following output.
> 
> aaaaaaaaaaaaaa
               ^
               ^
> agagagagagagagagag
  ^
  ^
> aaaaaaaaa


Those are the _same_ "a" characters. You appear to want to
find overlapping matches.


*Why* are you expecting that output?

We're going to go around and around if you cannot give
a real specification for what it is that you want.

If you wanted all overlapping matches, then you should be expecting:

aaaaaaaaaaaaaa
aaaaaaaaaaaaa
aaaaaaaaaaaa
aaaaaaaaaaa
aaaaaaaaaa
aaaaaaaaa
aaaaaaaa
agagagagagagagagag
gagagagagagagaga
agagagagagagagag
aaaaaaaaa
aaaaaaaa

You can get that by putting this in your while loop:

    # bump along, one character at a time
    pos($sequence) = pos($sequence) - length($&) + 1;

If you want only some of the overlapping matches, then provide
a specification that allows identifying which to keep and which
to ignore.


> I see the reason for its behaviour but can you please let me know what
> I should do to get the expected output.


Use this in your loop instead:

    pos($sequence) = pos($sequence) - 1;

But I'm pretty sure that that will prove unsatisfactory as well...


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


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

Date: 10 Dec 2002 16:08:03 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: reg exp problem
Message-Id: <3df681e3@news.victoria.tc.ca>

jaya prakash (prakashrj@hotmail.com) wrote:
: a short program that will duplicate the behaviour.
: #!/usr/local/bin/perl -w

: #my $sequence = "xyzagagagagagagagagaglmn";
: my $sequence = "xyzaaaaaaaaaaaaaagagagagagagagagaggaaaaaaaaacaacaaacaaaaaclmn";

: while($sequence =~ /(.)\1{7,}|(..)\2{7,}|(...)\3{7,}/g) {
:         print "$&\n";
: }


: output: 

: aaaaaaaaaaaaaa
: gagagagagagagaga
: aaaaaaaaa

: I am expecting the following output.

: aaaaaaaaaaaaaa
: agagagagagagagagag
: aaaaaaaaa

: I see the reason for its behaviour but can you please let me know what
: I should do to get the expected output.

: Thanks.

Just for interest, the following shows what happens

my $sequence =
"xyzaaaaaaaaaaaaaagagagagagagagagaggaaaaaaaaacaacaaacaaaaaclmn";

print "\n\$sequence=$sequence\n";

while($sequence =~ /(.)\1{7,}|(..)\2{7,}|(...)\3{7,}/g) {
print "\n$+\n";
print "[$`] ";
print "[$&] ";
print "[$'] ";
}



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

Date: Wed, 11 Dec 2002 01:34:16 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: RegEx question?
Message-Id: <slrnavd5ka.865.mgjv@verbruggen.comdyn.com.au>

On Tue, 10 Dec 2002 17:12:42 +0100,
	Dominik Seelow <kurzhalsflasche@netscape.net> wrote:
> Recently, Mike told us:
>> hello,
>> 
>> i am trying to write a regular expression to match this line:
>> 
>> 11449971_770_jig
>> 

> So it should be
> if ($name =~ /\d+_\d+_jig$/) { print "yes"; } else { print "no"; }

That will also match

foobar_1_2_jig

Maybe an anchor at the start is needed as well:

/^\d+_\d+_jig$/

Martien
-- 
                        | 
Martien Verbruggen      | Little girls, like butterflies, need no
Trading Post Australia  | excuse - Lazarus Long
                        | 


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

Date: Tue, 10 Dec 2002 16:25:15 -0500
From: Andrew Bacchi <bacchi@rpi.edu>
To: Bob <bob@bobber.com>
Subject: Re: Sending Email?
Message-Id: <3DF65BBB.8080706@rpi.edu>

Bob wrote:

> Hi,
>
> I need to send an email to several users from my perlscript (running on
> linux).  Searching CPAN and google show a LOAD of different modules as
> well as non-modular methods ( piping to sendmail, ..? ).
>
> Is there any one that is better or should I just take my pick?
>
> Thanks
> B
>
They all work.

If you aren't adding attachments to the mail try this. I cut this from a 
  program I wrote, so you will have to massage it a little to get it to 
work for you.

use Mail::Mailer;

mail_mailer();

sub mail_mailer {
         my $type = 'sendmail';
         my $mailprog = Mail::Mailer->new($type);
         # mail headers to use in the message
         my %headers = (
            'To' => 'someone@somewhere.com',
            'From' => 'root@somewhere.com',
            'Subject' => 'Your Subject here'
         );
         $mailprog->open(\%headers);
         print $mailprog "This is the Body of the message";
         $mailprog->close;
         }




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

Date: Tue, 10 Dec 2002 16:26:46 -0500
From: Andrew Bacchi <bacchi@rpi.edu>
To: Bob <bob@bobber.com>
Subject: Re: Sending Email?
Message-Id: <3DF65C16.50009@rpi.edu>

Bob wrote:

> Hi,
>
> I need to send an email to several users from my perlscript (running on
> linux).  Searching CPAN and google show a LOAD of different modules as
> well as non-modular methods ( piping to sendmail, ..? ).
>
> Is there any one that is better or should I just take my pick?
>
> Thanks
> B
>
They all work.

If you aren't adding attachments to the mail try this. I cut this from a 
  program I wrote, so you will have to massage it a little to get it to 
work for you.

use Mail::Mailer;

mail_mailer();

sub mail_mailer {
         my $type = 'sendmail';
         my $mailprog = Mail::Mailer->new($type);
         # mail headers to use in the message
         my %headers = (
            'To' => 'someone@somewhere.com',
            'From' => 'root@somewhere.com',
            'Subject' => 'Your Subject here'
         );
         $mailprog->open(\%headers);
         print $mailprog "This is the Body of the message";
         $mailprog->close;
         }




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

Date: Tue, 10 Dec 2002 16:27:46 -0500
From: Andrew Bacchi <bacchi@rpi.edu>
To: Bob <bob@bobber.com>
Subject: Re: Sending Email?
Message-Id: <3DF65C52.6050605@rpi.edu>

Bob wrote:

> Hi,
>
> I need to send an email to several users from my perlscript (running on
> linux).  Searching CPAN and google show a LOAD of different modules as
> well as non-modular methods ( piping to sendmail, ..? ).
>
> Is there any one that is better or should I just take my pick?
>
> Thanks
> B
>
They all work.

If you aren't adding attachments to the mail try this. I cut this from a 
  program I wrote, so you will have to massage it a little to get it to 
work for you.

use Mail::Mailer;

mail_mailer();

sub mail_mailer {
         my $type = 'sendmail';
         my $mailprog = Mail::Mailer->new($type);
         # mail headers to use in the message
         my %headers = (
            'To' => 'someone@somewhere.com',
            'From' => 'root@somewhere.com',
            'Subject' => 'Your Subject here'
         );
         $mailprog->open(\%headers);
         print $mailprog "This is the Body of the message";
         $mailprog->close;
         }




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

Date: Tue, 10 Dec 2002 23:13:29 GMT
From: "Brad" <xxxxxxx@xxx.xxx>
Subject: Re: which UI for Perl?
Message-Id: <tyuJ9.14346$y14.1318838@news1.east.cox.net>


"Erik Braun" <erik@pax07e3.mipool.uni-jena.de> wrote in message
news:slrn4avbhiv.86eq.erik@pax07e3.mipool.uni-jena.de...
> Erik Braun <erik@pax07e3.mipool.uni-jena.de> wrote:
>
> > I'm looking for a Perl Module, which provides interactive dialogs,
> > and some extensions like Radio buttons or file requestors.
>
> thank you for all the answers. I forgot to write one important
> detail: I look for an UI which runs in a Shell Window or on
> the console (Linux), so I cannot use the graphical extensions.
> Sorry about that.
>
> Erik

I would then use one of the Curses packages.  Take a look at CPAN, you have
several options, such a Curses....

Note, I've never use any of these, but they do what you want since any
bitmap based GUI appears out of the question for you.

Brad




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

Date: 10 Dec 2002 16:40:56 -0800
From: therobs@n2net.net (Rob Richardson)
Subject: Re: Why doesn't my array grow?
Message-Id: <f79bc007.0212101640.bba5066@posting.google.com>

My thanks to the person who pointed out that my loop index was
"currentIndex" instead of "$currentIndex".

No thanks to Tad.  I put "use strict" and "use warnings" in.  I ran my
program through my local Apache server.  Internet Explorer locked up. 
I ran it from an MS-DOS command prompt, and I got a couple hundred
errors saying "Global symbol &quot;$logname&quot; requires explicit
package name at index.cgi line 21.".  I got nothing talking about an
invalid use of "currentIndex".

I would be very happy to put an explicit package name around my
variables if I knew what one is, or what name I should use for a
global variable.  The reference book I am using (Sam's Teach Yourself
Perl in 21 Days) talks about using pre-built packages, but not what
package name a locally created variable should have.  I am a C++ and
Visual Basic programmer, and I understand the value of keeping
variables confined to the scope in which they are being used.  I
presume this "explicit package name" error has something to do with
that, but I don't know what.

Rob

> That you should enable warnings and strictures in your Perl programs.
> 
>    use strict;
>    use warnings;
> 
> 
> Either one would have pointed out what is wrong with your code
> in *milliseconds*.


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

Date: Tue, 10 Dec 2002 16:45:25 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Why doesn't my array grow?
Message-Id: <3DF68AA5.7000602@vpservices.com>

Rob Richardson wrote:

> My thanks to the person who pointed out that my loop index was
> "currentIndex" instead of "$currentIndex".


That was me, you're welcome.


> No thanks to Tad.


Tsk, tsk.  Just because you ran into problems doesn't mean you shouldn't 
thank Tad.  His advice was 100% correct - why ask me that the $ is 
missing when perl would have told you that yourself?

>  I put "use strict" and "use warnings" in.  I ran my
> program through my local Apache server.  Internet Explorer locked up. 
> I ran it from an MS-DOS command prompt, and I got a couple hundred
> errors saying "Global symbol &quot;$logname&quot; requires explicit
> package name at index.cgi line 21.".


You need to declare your variables with "my" the first time you use 
them, e.g.

   my $currentIndex = 1;

See the section on "Private Variables via my()" in the perlsub manpage 
(i.e. perldoc persub).

-- 
Jeff



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

Date: Wed, 11 Dec 2002 00:58:35 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Why doesn't my array grow?
Message-Id: <mbudash-FFFC01.16583410122002@typhoon.sonic.net>

In article <f79bc007.0212101640.bba5066@posting.google.com>,
 therobs@n2net.net (Rob Richardson) wrote:

> My thanks to the person who pointed out that my loop index was
> "currentIndex" instead of "$currentIndex".

so far so good...

> No thanks to Tad. 

uh-oh...

> [snip frustration misdirected at Tad]

*rarely* does Tad *not* deserve thanks... think again...

that fact that you did not understand the significance of his comment 
("use strict; use warnings;") is not an indication the comment's 
worthiness... you may have fixed *one* script error, but the 2 "use"'s 
illuminated the others... you should be thanking tad...


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

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


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