G'day mnnb,

Welcome to the monastery.

I suspect you're very new to Perl and have guessed at most of the code you've posted here. Various inconsistencies also suggest you've borrowed code from other sources without understanding what they do.

Commenting out strict and warnings is a big mistake: it doesn't fix the reported issues; you've simply stuck your head in the sand and pretended they're not there.

I suggest you read perlintro. Follow the links you find there for further information on the various topics that are relevant to your current task and ask here if you don't understand.

From your problem description, here's how I might have tackled it.

#!/usr/bin/env perl use strict; use warnings; my @match_letters = 'A' .. 'E'; my @argv = qw{q w a s z x qwe wer zxcvb xcvbn}; my @re_pairs = map { [ qr{$argv[$_ * 2]}, qr{$argv[$_ * 2 + 1]} ] } 0 +.. 4; while (<DATA>) { my $first_col = (split /\t/)[0]; my $match_code = ''; for my $i (0 .. 4) { if ($first_col =~ $re_pairs[$i][0] && $first_col =~ $re_pairs[ +$i][1]) { $match_code .= $match_letters[$i]; } } print "$match_code: $_" if length $match_code; } __DATA__ qwerty blah1 asdfgh blah2 zxcvbn blah3

Output:

AD: qwerty blah1 B: asdfgh blah2 CE: zxcvbn blah3

As you can see, I've dummied up file and command line input and have only produced basic output. This may not be exactly what you want but should provide some direction: note, for instance, that I've only captured the first column not every tab-separated element; used a for loop instead of your deeply nested if statements; and, printed the original line read rather than attempting to recreate it from the split elements.

[For subsequent questions, please follow the guidelines in "How do I post a question effectively?": a better question gets better answers.]

-- Ken


In reply to Re: Need Speed:Search Tab-delimited File for pairs of names by kcott
in thread Need Speed:Search Tab-delimited File for pairs of names by mnnb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.