Dharshana Eswaran wrote:
On 8/28/07, Chas Owens <[EMAIL PROTECTED]> wrote:
On 8/28/07, Dharshana Eswaran <[EMAIL PROTECTED]> wrote:

I have a pattern, which reads as shown below:

my $comment    = qr{\s* (?:/\* .*? \*/ \s*)*}xs;
my $identifier = qr{ [A-Za-z_]\w* }xs;
my $statement  = qr{
                   \s*
                   ($identifier)
                   \s+
                   ($identifier)
                   \s*
                   (?: \[ (.*?) \] )?
                   \s*
                   ;
                   \s*
                   $comment?
            }xs;

            my @m = $abc =~ /$statement/g;

My string reads as shown below:

$abc = "typedef struct  _MSG_S
{
    CALL_ID              callId;     /**< call id */
    VOICE_STATUS    status;     /**< Call status */
    id_t                       id;        /**< The id of process call */
} TAPI_VOICE_NOTIFY_CALL_STATUS_MSG_S;";


The condition $abc =~ /$statement/g; is not satisfied. The array @m is
not being filled.

I am unable to find out the mistake. Is the pattern regex wrong
somewhere?

That is not the behaviour I am seeing.  Please post a full example
that demonstrates your problem.  The following code prints out:

callId is of type CALL_ID
status is of type VOICE_STATUS
id is of type id_t

as expected.

#!/usr/bin/perl

use strict;
use warnings;


my $comment    = qr{\s* (?:/\* .*? \*/ \s*)*}xs;
my $identifier = qr{ [A-Za-z_]\w* }xs;
my $statement  = qr{
                  \s*
                  ($identifier)
                  \s+
                  ($identifier)
                  \s*
                  (?: \[ (.*?) \] )?
                  \s*
                  ;
                  \s*
                  $comment?
           }xs;

my $abc = "typedef struct  _MSG_S
{
   CALL_ID              callId;     /**< call id */
   VOICE_STATUS    status;     /**< Call status */
   id_t                       id;        /**< The id of process call */
} TAPI_VOICE_NOTIFY_CALL_STATUS_MSG_S;";

while ($abc =~ /$statement/g) {
        my ($type, $name, $size) = ($1, $2, $3);
        $type = "array of $type with $size elements" if defined $size;
        print "$name is of type $type\n";
}

When i write the condition
my @m = $fullStruct =~ /$DLstatement/g;
and try printing the array,
            print "\nThe array is @m\n";
It prints nothing.... This is the problem...

If I use the variable names in your original code:

my @m = $abc =~ /$statement/g;
print "\nThe array is @m\n";

then I get

Use of uninitialized value in join or string at E:\Perl\source\x.pl line 30.
Use of uninitialized value in join or string at E:\Perl\source\x.pl line 30.
Use of uninitialized value in join or string at E:\Perl\source\x.pl line 30.

The array is CALL_ID callId VOICE_STATUS status id_t id
which is what I would expect. Every third array element is undefined because
the optional array index is absent.

HTH,

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to