Hey folks, I have two pricing structures that I need to add to a price file prep process that I run in Perl. It seems like a perfectly simple thing to do, but I must not understand true and false like I should. In this price file there are around 150,000 lines and I am only interested in 4 of the columns in the tab delimited file. Those columns are the part number, part description, company 1 price, company 2 price. Here is the code:
my @line = split(/\t+?/, $row); my $part_number = $line[0]; my $part_desc = $line[1]; my $company1_price = $line[3]; my $company2_price = $line[5]; print Dumper $company1_price, $company2_price; if (!$company1_price && !$company2_price) { die "Entered if block\n"; #next; } else { die "Entered else block\n"; print $company1_file"$part_number\t$part_desc\t $company1_price\n"; print $company2_file "$part_number\t$part_desc\t $company2_price\n"; }
There are two cases I am looking for: 1. Both prices are empty or 2. Both prices are not empty. The two die statements are there for troubleshooting as is the print Dumper statement. If both prices have a price listed then I want to write the part number, part description, and price to the appropriate file for upload into the business system. The print Dumper statement prints the value of both prices as '     ' which I have visually verified, however I am entering the else block. Because of that I am writing every line to the file, which I don't want. What should I be using as a condition in the if block. Keep in mind that it is possible that a price value could look like '    150' and the number of white space characters is unknown.

In reply to Something is defined when it shouldn't be? by tnyflmngs

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.