I'm trying to build a script that checks link availability and licence costs for given frequencies, channel widths and antenna lengths. Some antenna lengths are not compatible with certain frequencies. The purpose of this section of code is to compare all frequency, channel width and antenna length combination and calculate the availability but not running the subroutines for availability and price calculations if the frequency does not match the antenna length.

$FREQUENCY_QUERY = $dbh->prepare("SELECT `id`, `frequencies` FROM `microwave-frequencies` ORDER BY `frequencies` DESC"); $CHANNEL_QUERY = $dbh->prepare("SELECT `channel` FROM `microwave-modulation-lookup` WHERE `rate` = '$DATA_RATE'"); $SITE_A_ANTENNA_LENGTH_QUERY = $dbh->prepare("SELECT `length` FROM `microwave-antenna-length-lookup`"); $SITE_B_ANTENNA_LENGTH_QUERY = $dbh->prepare("SELECT `length` FROM `microwave-antenna-length-lookup`"); $FREQUENCY_QUERY->execute( ); while ( ($FREQUENCY_ID) = @FREQUENCY_QUERY = $FREQUENCY_QUERY- +>fetchrow_array() ) { $FREQUENCY_ID = "$FREQUENCY_QUERY[0]"; $FREQUENCY = "$FREQUENCY_QUERY[1]"; $CHANNEL_QUERY->execute( ); while ( ($CHANNEL_SIZE) = @CHANNEL_QUERY = $CHANNEL_QUERY- +>fetchrow_array() ) { $CHANNEL_SIZE = "$CHANNEL_QUERY[0]"; $SITE_A_ANTENNA_LENGTH_QUERY->execute( ); foreach ( ($SITE_A_ANTENNA_LENGTH) = @SITE_A_ANTENNA_L +ENGTH_QUERY = $SITE_A_ANTENNA_LENGTH_QUERY->fetchrow_array() ) { $SITE_A_ANTENNA_LENGTH = "$SITE_A_ANTENNA_LENGTH_QUERY +[0]"; $SITE_B_ANTENNA_LENGTH_QUERY->execute( ); foreach ( ($SITE_B_ANTENNA_LENGTH) = @SITE_B_ANTEN +NA_LENGTH_QUERY = $SITE_B_ANTENNA_LENGTH_QUERY->fetchrow_array() ) { $SITE_B_ANTENNA_LENGTH = "$SITE_B_ANTENNA_LENG +TH_QUERY[0]"; &conflict_check; &calculate_rsl; &calculate_oav_h; &calculate_oav_v; &calculate_licence_fee; $tb->addRow( "$TABLE_ROW_COUNT", "$DATA_RATE Mbps", "$ +FREQUENCY GHz", "$CHANNEL_SIZE MHz", "$SITE_A_ANTENNA_LENGTH", "$SITE +_B_ANTENNA_LENGTH", "$OVERALL_AVAILABILITY_H_RESULT %", "$OVERALL_AVA +ILABILITY_V_RESULT %", "&pound;$ANNUAL_LICENCE_FEE", "<a href='ofcom- +document-generator.cgi?LINKDETAILS=True&FREQUENCY=$FREQUENCY&CHANNEL_ +SIZE=$CHANNEL_SIZE&SITE_A_ANTENNA_LENGTH=$SITE_A_ANTENNA_LENGTH&SITE_ +B_ANTENNA_LENGTH=$SITE_B_ANTENNA_LENGTH'>Link Details</a>" ); $TABLE_ROW_COUNT++; if ($LINK_TYPE eq 'Core Infrastructure') { if ($OVERALL_AVAILABILITY_H_RESULT >= 99.99) { $tb->setCellClass ($TABLE_ROW_COUNT, 7, 'tbrowgree +n'); } elsif ($OVERALL_AVAILABILITY_H_RESULT < 99.99) { $tb->setCellClass ($TABLE_ROW_COUNT, 7, 'tbrowerro +r'); } if ($OVERALL_AVAILABILITY_V_RESULT >= 99.99) { $tb->setCellClass ($TABLE_ROW_COUNT, 8, 'tbrowgree +n'); } elsif ($OVERALL_AVAILABILITY_V_RESULT < 99.99) { $tb->setCellClass ($TABLE_ROW_COUNT, 8, 'tbrowerro +r'); } } elsif ($LINK_TYPE eq 'Customer Link') { if ($OVERALL_AVAILABILITY_H_RESULT >= 99.95) { $tb->setCellClass ($TABLE_ROW_COUNT, 7, 'tbrowgree +n'); } elsif ($OVERALL_AVAILABILITY_H_RESULT < 99.95) { $tb->setCellClass ($TABLE_ROW_COUNT, 7, 'tbrowerro +r'); } if ($OVERALL_AVAILABILITY_V_RESULT >= 99.95) { $tb->setCellClass ($TABLE_ROW_COUNT, 8, 'tbrowgree +n'); } elsif ($OVERALL_AVAILABILITY_V_RESULT < 99.95) { $tb->setCellClass ($TABLE_ROW_COUNT, 8, 'tbrowerro +r'); } } } } } }

For some reason, the two inner most foreach's, if I change them to whiles, seem to ignore the &conflict_check; next statement and throw up a logarithmic error due to the fact that the frequency does not work with the antenna length (Can't take log of -0.364299 at /var/www/dev/ofcom-document-generator.cgi line 3358.). A little example of the &conflict_check; :

sub conflict_check { if (($FREQUENCY eq '7') && ($SITE_A_ANTENNA_LENGTH eq '0.3')) { next; } if (($FREQUENCY eq '7') && ($SITE_B_ANTENNA_LENGTH eq '0.3')) { next; } if (($FREQUENCY eq '11') && ($SITE_A_ANTENNA_LENGTH eq '0.3')) { next; } if (($FREQUENCY eq '11') && ($SITE_B_ANTENNA_LENGTH eq '0.3')) { next; } if (($FREQUENCY eq '28') && ($SITE_A_ANTENNA_LENGTH eq '0.8')) { next; } if (($FREQUENCY eq '28') && ($SITE_B_ANTENNA_LENGTH eq '0.8')) { next; } ...and so on...

It is of my understanding that the next; should exit the current while (or foreach) and so should not process any of the other subroutine calls, therefore should not attempt to `log` the number which is usually a minus.

The two inner most foreach's do work if they are foreach's and not while's as earlier noted, however they seem to exit after just one loop so the only antenna length that gets calculated is 0.3. Possible lengths are 0.3, 0.6, 0.8, 1.0 and 1.2 for both site A and site B.

Frequency SQL query outputs: 7, 11, 13, 15, 18, 23, 26, 28, 38

Channel Width SQL query outputs: 7, 14, 28, 56

I have put all 4 SQL queries into Perl arrays and referenced them that way, but it has not changed anything, they behave in the same way as with SQL query outputs.

Many thanks to anyone who can shed any light onto the situation.

Kind regards,

Ben


In reply to Nested While Loops, foreach and next by Chipwiz_Ben

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.