For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > May 2007 > (was: Regarding files)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author (was: Regarding files)
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."

Eraede1

2007-05-26, 1:31 am

Adult BDSM movie
http://free-bdsm-movies.info/movies/218571.avi
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com