in reply to get some part of the string using regex

Hi,
If I were you, I wouldn't use a regex to split the input data:
#!/usr/bin/perl -w use strict; while(<>) { chomp; next unless($_ =~ /\|/); #Skip if no pipe sy +mbol my @fields = split '\|', $_; $fields[0] =~ s/^>//; #Remove leading ang +le-bracket print $fields[0], " == ", $fields[1], "\n"; }
Cheers

davis
Is this going out live?
No, Homer, very few cartoons are broadcast live - it's a terrible strain on the animator's wrist

Replies are listed 'Best First'.
Re: Re: get some part of the string using regex
by Sifmole (Chaplain) on May 17, 2002 at 11:23 UTC
    Of course when using split you can always limit the number times the string gets split by adding the third parameter:
    my $foo = 'abc|def|ghi|jkl|mno'; my @bar = split('|', $foo, 3);
    Since you are only interested in the first two fields.