grep for text from a postscript file

Discussion in 'Perl Misc' started by J M, Jan 23, 2004.

  1. J M

    J M Guest

    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!
     
    J M, Jan 23, 2004
    #1
    1. Advertisements

  2. 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.
     
    Walter Roberson, Jan 23, 2004
    #2
    1. Advertisements

  3. Walter Roberson <-cnrc.gc.ca> 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. >
     
    Darren Dunham, Jan 26, 2004
    #3
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arthur

    Printing Postscript in Perl

    Arthur, Mar 7, 2004, in forum: Perl
    Replies:
    2
    Views:
    732
    Roel van der Steen
    Mar 7, 2004
  2. bilian
    Replies:
    1
    Views:
    613
    Niels Dybdahl
    Nov 4, 2004
  3. aidy

    grep-ing text in an array

    aidy, Jun 28, 2006, in forum: Ruby
    Replies:
    10
    Views:
    300
    Robert Klemme
    Jun 30, 2006
  4. Len Lawrence
    Replies:
    0
    Views:
    227
    Len Lawrence
    Jun 14, 2008
  5. BCC

    Generating postscript file

    BCC, Nov 4, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    186
    Ian Wilson
    Nov 5, 2004
  6. Buck Turgidson

    Grep Text File for Lines Containing 1 or 2 Words

    Buck Turgidson, Jan 25, 2005, in forum: Perl Misc
    Replies:
    6
    Views:
    280
    John W. Krahn
    Jan 26, 2005
  7. Carsten Thomas

    print file information from postscript headers

    Carsten Thomas, Nov 9, 2005, in forum: Perl Misc
    Replies:
    0
    Views:
    184
    Carsten Thomas
    Nov 9, 2005
  8. Replies:
    0
    Views:
    255
Loading...