grep for text from a postscript file

J

J M

How can I grep for each record in array of text filter against postscript
files?

ArrayF
aaaa
bbbb
abcd
ABcd

I needs to run each record against postscript file and see if there is any
filter matches?

TIA!
 
W

Walter Roberson

:How can I grep for each record in array of text filter against postscript
:files?

:ArrayF
:aaaa
:bbbb
:abcd
:ABcd

:I needs to run each record against postscript file and see if there is any
:filter matches?

Tricky. Postscript is a complete programming language in itself.
There is no possible [finite] general mechanism to determine whether
arbitrary Postscript programs wil produce particular outputs.

Consider for example that a Postscript driver might choose to use
absolute positioning to place the AB and then relative positioning
for the following cd. Absolute positioning of an uppercase letter
introducing a word happens quite a bit in Postscript drivers, in
my experience.


What happens if the driver choses to define producing cd as a function,

/frotz1733 (cd) def
[.... thousands of lines of postscript here]
(AB) 12 timesnewroman
frotz1733

?


If you know that the target might appear *as code* then you just
have a traditional matching problem

use strict;
use warnings;
my @ArrayF = qw(aaaa bbbb abcd ABcd);
my $matchstring = join '|', @ArrayF;
print grep { m/$matchstring/o } (<>)


Note 1: as @ArrayF gets big, the backtracking involved in the matching
can really slow you down.

Note 2: Watch out for metacharacters in @ArrayF

Note 3: Your target list suggests you'd be better off doing a case-
insensitive search such as m/aaaa|bbbb|abcd/i .
 
D

Darren Dunham

Walter Roberson said:
have a traditional matching problem
use strict;
use warnings;
my @ArrayF = qw(aaaa bbbb abcd ABcd);
my $matchstring = join '|', @ArrayF;
print grep { m/$matchstring/o } (<>)
Note 1: as @ArrayF gets big, the backtracking involved in the matching
can really slow you down.

If you can guarantee surrounding context, then this can be much faster..

for instance..
m/^$matchstring$/o or
m/\($matchstring\)/o

If you can't, *and* you care which one it matched, you might want to
sort the list by length first (so the longest matches are tried first).

join '|', sort {length $b <=> length $a} @ArrayF;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top