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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: regex question
by Transient (Hermit) on Jun 01, 2005 at 15:31 UTC
    How is the file set up? Do the lines alternate? Is what you generically need is anything before the first pipe (|) and anything before the first comma? If so...
    while (<FILE>) { if ( $. % 2 ) { $gref = (split /\|/, $_)[0]; } else { $type = (split /,/, $_)[0]; } }
      thanks, seems fine now
Re: regex question
by cool_jr256 (Acolyte) on Jun 01, 2005 at 15:37 UTC
    My mistake, here is the updated code:
    You can try this:
    It opens a file containing the above lines, then matches for the first and second instance.
    #!/usr/bin/perl open(TMP,"$ARGV[0]"); while(<TMP>) { if($_ =~ m/([0-9-.]+)\|/) { $gref=$1; } if($_ =~ m/([0-9]+),/) { $type=$1; } }

    Hope this helps...