Tom Yarrish wrote:

Hey all,

Hello,

I'm trying to pull some machine names out of a CSV file, and I'm using the Pattern Test Program from Learning Perl 4th ed, but I don't think I have the logic right. Here's a sample line from the CSV file:

TAP0SMITHJ | smithj (192.168.1.1),DOMAIN | Professional,"4.0.0.1180, 2008-07-31 12:04:56",I,U

(the data was scrubbed with generic info, but it's the same stuff)

So what I want to capture is the TAP0SMITHJ stuff only. Here's the Pattern Test Program I'm using:

#!/usr/bin/perl

use strict;
use warnings;
use 5.010;

while (<>) {                   # take one input line at a time
    chomp;
    if (/^TAP+\wb\|/xm) {

Your regular expression says to match 'TA' at the beginning of the line followed by one or more 'P' characters followed by a single \w character followed by the characters 'b|'. You probably want something more like this instead:

      if ( /^TAP\w+\s+\|/ ) {

        print "Matched: |$`<$&>$'|\n";  # the special match vars

perldoc perlre
[ snip ]
    WARNING: Once Perl sees that you need one of $&, "$`", or "$'"
    anywhere in the program, it has to provide them for every pattern
    match.  This may substantially slow your program.

    } else {
        print "No match: |$_|\n";
    }
}

I'm basically working on getting the regex, then I'm going to incorporate it into a program to pull out the TAP0SMITHJ stuff and put it in another file.


John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

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


Reply via email to