Zary Necheva wrote:
>
> Hi everyone,
Hello,
> I have a file with data similar to this
> ..
> Ex|FEx|NQxx|OUxx|GExx|OVxxx|IQ|OR
> Ex|FExx|NQxx|GExxx|OVxx|OUxx|IQxxx|ORxxx
> Ex|FExxx|NQxx|OUxx|OVxxx|ORx
Rob Dixon wrote:
>
> use strict;
> use warnings;
>
> open INFILE, 'myfile.txt' or die $!;
>
> while () {
> chomp;
> my @fields = split /\|/;
> my @output = grep /^(E|FE|NQ|IQ)/, @fields;
> print join('|', @output), "\n";
> }
>
> **OUTPUT
>
> Ex|FEx|NQxx|IQ
> Ex|FExxx
Hi Tim.
Sorry, but may I mess with your code? :)
Tim Johnson wrote:
>
> Zary Necheva wrote:
> >
> > I have a file with data similar to this
> > ..
> > Ex|FEx|NQxx|OUxx|GExx|OVxxx|IQ|OR
> > Ex|FExx|NQxx|GExxx|OVxx|OUxx|IQxxx|O
This is a pretty classic example of where split and join come in handy. Here I'm
reading each line, splitting it into fields by the pipe character, then creating a new
array with only those fields that begin with the letters I specify. Then I use join
to make a string with those fields I chos