| Dr.Ruud 2007-05-21, 9:59 pm |
| "Dharshana Eswaran" schreef:
You really shouldn't quote text that is no longer relevant, such as
signatures and mailing list tails.
> Ruud:
[color=darkred]
>
> Can you please help me with a small piece of code for the same logic
> which you mentioned?
#!/usr/bin/perl
use strict;
use warnings;
my $phase = 0;
my $s;
while (<> ) {
if (0 == $phase) {
/^\s*typedef union\s*(?:\{\s*)?$/
and ++$phase and $s = $_;
}
elsif (1 == $phase) {
$s .= $_;
if (/^\s*}\s*(\w+)\s*;\s*$/) {
'CHANNEL_INFO_T' eq $1
and ++$phase and last;
$s = '';
$phase--;
}
}
else { die "ugly phase($phase)"}
}
$phase == 2 and print $s;
__END__
(untested)
But a real parser would also catch variants such as
typedef union {
TYPE_T type;
MODE_T mode;
}
CHANNEL_INFO_T;
See also:
http://search.cpan.org/search?query...ced&mode=module
--
Affijn, Ruud
"Gewoon is een tijger."
|