Matthew Bonner wrote:
Hi Anamika

I know this thread has focussed on using split -- thought I'd add a
regex powered version for reference/comparison.

cheers

Matthew


use strict;
use warnings;

while (<DATA>) {
        my @keys;
        @keys = $_ =~ m/(NM_\d+)+/g;
        $_ =~ m/\:1\s+(.*)$/;
        print "$_ = $1\n" foreach (@keys);
}

Your loop could be written more simply as:

while (<DATA>) {
        mt @keys = /NM_\d+/g;
        /:1\s+(.*)$/;
        print "$_ = $1\n" for @keys;
}

Your use of capturing parentheses with a quantifier, ()+, around the pattern is superfluous and would produce the wrong results if it actually matched more than once.

Your use of $1 without verifying that the pattern actually matched could also produce the wrong results.



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to