The "yapp" style parsing suggestion is good. If you've used that sort of parsing approach before, or want to learn it, you won't regret doing it that way.
But for some tasks it may be overkill, and this may be one of those tasks. You just want to keep a selected subset of features from the input file and format them a little differently for output. If the input is consistent in its structure and format, like your examples, then here's a different sort of hint:
{
local $/ = "}\n"; # end-of-record string
# (might need "}\r\n", if data is CRLF style)
while (<>) # this reads a whole multi-line record
{
my ( $cellname ) = ( /^\s*cell\s+(\S+)/ );
my ( $area ) = ( /area\s+(\d+)/ );
# and similarly for other items of interest...
# print according to taste
}
}
Read up on the "s" regex modifier and other useful tricks in "perldoc perlre" to work out how you want to handle the other items you're after in each record.
Of course, if your input file format varies significantly from the examples you showed, this sort of approach will tend to be easy to break. Good luck. |