regex error

  • Thread starter Brendon Caligari
  • Start date
B

Brendon Caligari

I cannot understand what i'm doing wrong but my script fails to compile
("panic: end_shift");

$SMContents =~ m/^User data: '(.{$SMMessageLength})'$/ms

The following two alternatives work well

$SMContents =~ m/^User data: '(.{18})'$/ms

$SMContents =~ m/^User data: '(.{$SMMessageLength})'/ms


B.
 
G

Gunnar Hjalmarsson

Brendon said:
I cannot understand what i'm doing wrong but my script fails to
compile ("panic: end_shift");

$SMContents =~ m/^User data: '(.{$SMMessageLength})'$/ms

The following two alternatives work well

$SMContents =~ m/^User data: '(.{18})'$/ms

$SMContents =~ m/^User data: '(.{$SMMessageLength})'/ms

There is nothing with any of the expressions above that should cause a
script to not compile. Please post a short but *complete* program that
illustrates the problem.
 
B

Brendon Caligari

Abigail said:
Brendon Caligari ([email protected]) wrote on MMMMLII
September MCMXCIII in <URL:;; I cannot understand what i'm doing wrong but my script fails to compile
;; ("panic: end_shift");

Probably a syntax error that is triggering a bug in Perl. You should
never get the "panic" message - if you get it, it's a bug in Perl.

Probably the most common source of such 'panic' errors happen when
Perl tries to compile a regexp containing some kind of syntax error.

;; $SMContents =~ m/^User data: '(.{$SMMessageLength})'$/ms

Since we don't know what's in $SMMessageLength, it's hard to say
what is going wrong.



Abigail

Thanks Abigail...


<cut filename = 'x.pl'>
#!/usr/bin/perl
use warnings;
use strict;

my $str = '';
my $num = 0;
open(MF, "<x");
{
local $/ = '';
$str = <MF>;
}
close(MF);
$str =~ m/^length: (\d+?)$/ms;
$num = $1;
$str =~ m/^data: '(.{$num})'$/ms;
</cut>


<cut filename = 'x'>
length: 5
data: '01234'
</cut>


$ uname -r
2.4.21-20.EL


$ rpm -q perl
perl-5.8.0-88.7



I tried the same thing on a WinXP machine with a recentish version of
ActivePerl port and it worked well.


Brendon
 
B

Brendon Caligari

Always *always* before using a "number variable", check to see if the
match succeeded. Maybe like:

if($str=~m/^length: (\d+?)$/ms){
$num=$1;
}
else{
die "Bad length: line";
}



Again, before using $1 from this statement, check to see if the match
was successful. Another way:

This code was not meant to be 'proper' ..but to expose the panic
situation. The original script was longer but i reduced it to the
shortest i could where it would still 'panic'.
 
B

Brendon Caligari

Abigail wrote:

It might be a bug in Perl. Could you make a self-contained program that
exhibits this bug?

That is EXACTLY what the earlier posted script and other file does.

I shortened the script as much as possible that while it makes no sense
whatsoever it should be syntactically correct but still 'panics'.

If I include the contents of the associated data file 'x' directly into
the variable the script does NOT panic.

Anyhows...my conclusion is that this WAS a Perl bug...one that's been
fixed a while ago. Red Hat ES seem to ship a pretty oldish Perl. I
installed a newer release and all worked as expected.


B.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,161
Messages
2,570,891
Members
47,423
Latest member
henerygril

Latest Threads

Top