Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > grep for text from a postscript file

Reply
Thread Tools

grep for text from a postscript file

 
 
J M
Guest
Posts: n/a
 
      01-23-2004
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!


 
Reply With Quote
 
 
 
 
Walter Roberson
Guest
Posts: n/a
 
      01-23-2004
In article <tFZPb.7698$> ,
J M <> wrote:
: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 .


--
Inevitably, someone will flame me about this .signature.
 
Reply With Quote
 
 
 
 
Darren Dunham
Guest
Posts: n/a
 
      01-26-2004
Walter Roberson <> wrote:
> 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;

--
Darren Dunham
Unix System Administrator Taos - The SysAdmin Company
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inverted text in Ruby Tk canvas postscript Len Lawrence Ruby 0 06-14-2008 09:36 PM
Can anybody give me an example about how to write the image drawn by the canvas in WxPython into postscript file Hank Gong Python 0 04-12-2007 06:06 PM
Grep Text File for Lines Containing 1 or 2 Words Buck Turgidson Perl Misc 6 01-26-2005 10:54 PM
Generating postscript file BCC Perl Misc 3 11-05-2004 02:07 PM
Re: anyone know here to get the API/Library for reading Postscript file into JAVA? Roedy Green Java 0 08-02-2003 06:28 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57