One suggestion of a general nature I have is to make your matches more tolerant, or provide a list of 'approved' things to search on (in the form of a drop-down list). Don't test for strict equality, test for (case-insensitive) patterns:

foreach my $name (@names) { if ($dbpattern{$name} =~ /$pattern/i or $dbcolor{$name} =~ /$color/ +i) { # print out the record } }

That deals with issues like funky newline problems, etc. (which this version of your code doesn't deal with, although I recall you had put some code in at some point). Although, as I recommend below, you should change the way you store your data, you'll need to chomp each variable:

$i =0; while (my $name[$i] = <DBFILE>) { chomp $name[$i]; my $color = <DBFILE>; my $pattern = <DBFILE>; my $dbcd = <DBFILE>; chomp ($color, $pattern, $dbcd); #yep, all at once! # now go on as before ... $i++; }

I'd also recommend you change the way the information is stored in your flat file; multiline records are relatively more error-prone than single-line records (e.g. what if you accidentally leave out a single line in the file somewhere in the middle? Every record below that will be messed up). Your code could be made more compact if you stored the information as, say, pipe-separated records (just for example: pick a character you know won't end up in the data).

superpicture|TerraCotta|Offset Brick|5

You'd read in a record using something as simple as a split:

chomp $line; my @record = split /\|/, $line, 4; # $record[0] is name, 1 => color 2 => pattern, etc.

and you woulnd't have the problem that a messed up line would mess up everything afterwards.

HTH.

perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'

In reply to Re: CGI, Newlines, and If Statements by arturo
in thread CGI, Newlines, and If Statements by wiz

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.