On 8/28/07, Dharshana Eswaran <[EMAIL PROTECTED]> wrote:
> Hi All,
>
> 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?
>
> Thanks and Regards,
> Dharshana
>


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";
}

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


Reply via email to