Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have lines like this;
0 I/B FLAP SPA LOAD QSC2040303, U.L.F.=1.4 SUBCASE 85003 + 0 I/B FLAP SPA LOAD QSA1010304, U.L.F.=1.4 SUBCASE 85004
How can I extract the expression between the 0 and the SUBCASE

Replies are listed 'Best First'.
Re: How can I extract the expression between two key words
by BrowserUk (Patriarch) on Sep 20, 2002 at 01:07 UTC

    You could try

    $line =~ m/0\s+(.+?)\s+SUBCASE/; my $expr = $1;

    Or

    my $expr = substr( $line, 4, 40 );

    If the format is truely as fixed as it appears from your limited sample.

Re: How can I extract the expression between two key words
by Zaxo (Archbishop) on Sep 20, 2002 at 02:31 UTC

    If the records are as fixed as they appear, substr or unpack would be better than matching a regular expression:

    # assume the current line is in $_ my $foo = substr $_, 5, 40; # or else my ($foo) = unpack "x5 A46", $_;
    The unpack solution will trim trailing space, because of the "A" template, and is better if the text to capture has varying width. If 'SUBCASE' is not at fixed offset, index can find it to be used in the unpack template.

    After Compline,
    Zaxo

Re: How can I extract the expression between two key words
by the_slycer (Chaplain) on Sep 20, 2002 at 01:10 UTC
    You'd probably want to use a regular expression .. Look into perlre for more info, but this should get you started:
    my ($match) = $text =~ /^0(.+)SUBCASE/;
    Where $text is the text entered above.