[boulder.pm] grabbing ()
Walter Pienciak
walter at frii.com
Mon Jan 31 14:56:51 CST 2000
On Mon, 31 Jan 2000, Eric Shore Baur wrote:
> I'm working on a project where I'm looking through PS files for
> attendace data (at my high school)... and I'm basically just looking at
> anything in () by doing:
>
> @keep = map { /\((.*)\)/ } @lines;
>
> For the most part, this pulls out everything that would be on
> the printed page (and some extra stuff that I can just ignore). The
> problem I've run into (at least in part) is lines that contained () to
> start with. A line that looks, when printed, like this:
>
> *** Period 4: IMP MATH 1A (22)
>
> becomes:
>
> *** Period 4: IMP MATH 1A \(22\)
>
> Do I have to look back through the whole array to fix that, or can
> I do it in the same line with the map? (or, is there a better way than
> map to do this?)
>
> Thanks for any ideas,
> Eric
I wrote some quick code to play with, as follows,
#!/opt/bin/perl -w
my @lines = (
"This is junk #1",
"(This is a keeper)",
"(This is a keeper (with parens))",
"This is junk #2",
);
my @keep = map { /\((.*)\)/ } @lines;
foreach my $item ( @keep ) {
print $item, "\n";
}
and I'm not getting any escaped parentheses in the output. At any rate,
if you're going to wind up doing a string of substitutions (I did a
sed PS-to-ASCII script once, and a few were needed), you might want
to eschew the map and process the array in a foreach loop.
Walter
More information about the Boulder-pm
mailing list