in reply to Re: split (grep)
in thread split (grep)

I understand why the hash-based solution makes more sense for performance. Especially in a "fancy" solution. I guess I just want to be able to split on the grep statement as an argument if I needed to... If I can...

This started out as a one liner "brute force" grep replacement in case I needed more than a single or just a few members of the first list...

perl -ne 'next if(!/tom/ && !/steve/) ; printf("%10s %5s",(split/;/)[0 +,1]);' list.txt tom 54 steve 56

Thank you for the input

Replies are listed 'Best First'.
Re^3: split (grep)
by tbone654 (Beadle) on Oct 24, 2014 at 18:33 UTC

    I settled on this for the moment, as it preserves the order of the first list, which is a requirement.

    @foo = qw/tom steve bill roger bob/; @bar = qw/roger;99 steve;56 ted;88 tom;54/; foreach $line(@foo){ foreach $line1(@bar){ @split1=(split/;/,$line1); if($line =~ $split1[0]){ printf("%5s %3s\n",$split1[0],$split1[1]); } } } __END__ tom 54 steve 56 roger 99
    Thank you for the suggestions