Jason Balicki wrote:
Hello,

Hello,

If you would, please consider the following input file:

<code>
|6643    |Jason Balicki   |          |0501211243|000:00:00|        0| S
|0|
|        |13145551212         |N|            |   0|001001|001001| 100|
10|B|A|
</code>

And the following code:

<code>
while(<>){
        if (whichline($_) == 1){
                print "input line is call record line 1\n";
        }
        else {
                if (whichline($_) == 2){
                        print "input line is call record line 2\n";
                }
        }
}

sub whichline {
        if (/\|[BNPG]\|/){
                return 2;
        }
        else {
                if (/\|[0A-Z]\|$/) {
                        return 1;
                }
        }
}
</code>

You'll notice that regex "|[BNPG]|" which should match the
|N| on the second line of the input file.  That field will
always be located on the 31st, 32nd and 33rd characters on
the line.

This regex works, and has been in use for a couple of days
now, but I'd like to be more explicit, especially since I
can never be sure that another line of input won't contain
that string (I am filtering from a serial port that will
have other output.)  If I can pin it to a specific location,
it would at least be a little better.

Is there a way that I can specify that that regex starts
on a particular character on the line?

Yes, two ways that I can think of:

        if ( substr( $_, 30, 3 ) =~ /\|[BNPG]\|/ ) {


if ( /^.{30}\|[BNPG]\|/ ) {



John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to