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. Advertising

  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. Advertising

  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. Advertising

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. Roedy Green
    Replies:
    0
    Views:
    1,123
    Roedy Green
    Aug 2, 2003
  2. Len Lawrence
    Replies:
    0
    Views:
    138
    Len Lawrence
    Jun 14, 2008
  3. BCC

    Generating postscript file

    BCC, Nov 4, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    99
    Ian Wilson
    Nov 5, 2004
  4. Carsten Thomas

    print file information from postscript headers

    Carsten Thomas, Nov 9, 2005, in forum: Perl Misc
    Replies:
    0
    Views:
    108
    Carsten Thomas
    Nov 9, 2005
  5. Replies:
    0
    Views:
    171
Loading...

Share This Page