Note that there are some explanatory texts on larger screens.

plurals
  1. POI need a single line array. I am using nested loops to push elements into the array. The array contains multipe lines
    primarykey
    data
    text
    <p>I am using perl to produce an array of elements arranged as a single, tab-delimited line. However, only a portion of my array is like this. Other parts get printed as separate lines.</p> <p>Below is the relevant portion of the code.</p> <p>It is a foreach loop that has three conditional <code>for</code> loops embedded in it. The <code>push</code> command is used four times at four different <code>if</code>/<code>else</code> conditions. The particular array I'm having the issue with is called <code>@imputed_positions</code>. Several variables are defined near the beginning, which can be ignored. I don't think those are the problem.</p> <p>The output I get is correctly printed as a single line when the variable <code>$distance</code> is<code>&gt; 1</code>, even though those values get processed by 3 separate instances of the push command (the first three). Values for <code>$distance</code> that are <code>&gt; 1</code> and also floating point values for $distance get printed as a single line. When <code>$distance</code> is <code>&lt; 1</code> or <code>= 1</code>, they get printed as separate lines. These lines correspond to elements pushed into @imputed_positions by the last of the four push commands.</p> <p>I can't recognize an analogous problem within "Similar Questions," probably because I don't have a precise enough clue of what the issue is.</p> <p>Thanks!!!</p> <pre><code>foreach my $distance ( @distances ) { if ( $distance &gt; 1 &amp;&amp; ( int ( $distance ) != $distance ) ) { ###just asking whether $variable is an integer and whether it is &gt; than 1. my $rounded_up = rounding_up( $distance ); my $rounded_down = rounding_down( $distance ); my $up_distance = $distance/$rounded_up; my $down_distance = $distance/$rounded_down; my $abs_up = abs ( 1 - $up_distance ); my $abs_down = abs ( 1 - $down_distance ); if ( $abs_up &lt; $abs_down ) { for ( my $i = 0; $i &lt; $rounded_up; $i++ ) { push ( @imputed_positions, "IMP!$up_distance!A\tIMP!$up_distance!D\tIMP!$up_distance!I\t" ); } } else { for ( my $i = 0; $i &lt; $rounded_down; $i++ ){ push ( @imputed_positions, "IMP!$down_distance!A\tIMP!$down_distance!D\tIMP!$down_distance!I\t" ); } } } else { if ( $distance &gt; 1 ){ for ( my $i = 1; $i &lt;= $distance; $i++ ) { push ( @imputed_positions, "IMP!1!A\tIMP!1!D\tIMP!1!I\t" ); } } else { push ( @imputed_positions, "IMP!$distance!A\tIMP!$distance!D\tIMP!$distance!I\t" ); } } } #print @imputed_positions; #rounding down subroutine sub rounding_down { my ( $round_me ) = @_; my $rounded_down = int( $round_me ); return $rounded_down; } #rounding up subroutine sub rounding_up { my ( $round_me ) = @_; my $rounded_up = int( $round_me ) + 1; return $rounded_up; } </code></pre> <p>Maybe it would help if I explained the input. The @distances is just a txt file, where each line is a number. The numbers are all positive, and can be 0, integers, or floating point numbers. For eg, <code>@distance = ( 1, 3, 5.9999, 4.9, 3.1, 3.000001, 0, 0, 0.3 )</code>. </p> <p>When <code>@distance</code> contains the above elements, the output does not print as a single line, but rather looks like:</p> <pre><code>IMP!1 !A IMP!1 !D IMP!1 !I IMP!1!A IMP!1!D IMP!1!I IMP!1!A IMP!1!D IMP!1!I IMP!1!A IMP!1!D IMP!1!IIMP!0.999999998333333!A IMP!0.999999998333333!D IMP!0.999999998333333!I IMP!0.999999998333333!A IMP!0.999999998333333!D IMP!0.999999998333333!I IMP!0.999999998333333!A IMP!0.999999998333333!D IMP!0.999999998333333!I IMP!0.999999998333333!AIMP!0.999999998333333!D IMP!0.999999998333333!I IMP!0.999999998333333!A IMP!0.999999998333333!D IMP!0.999999998333333!I IMP!0.999999998333333!A IMP!0.999999998333333!D IMP!0.999999998333333!I IMP!0.98!A IMP!0.98!D IMP!0.98!I IMP!0.98!A IMP!0.98!D IMP!0.98!I IMP!0.98!A IMP!0.98!D IMP!0.98!I IMP!0.98!A IMP!0.98!D IMP!0.98!I IMP!0.98!A IMP!0.98!D IMP!0.98!I IMP!1.03333333333333!A IMP!1.03333333333333!D IMP!1.03333333333333!I IMP!1.03333333333333!A IMP!1.03333333333333!D IMP!1.03333333333333!I IMP!1.03333333333333!A IMP!1.03333333333333!D IMP!1.03333333333333!I IMP!1.00000003333333!A IMP!1.00000003333333!D IMP!1.00000003333333!I IMP!1.00000003333333!A IMP!1.00000003333333!D IMP!1.00000003333333!I IMP!1.00000003333333!A IMP!1.00000003333333!D IMP!1.00000003333333!I IMP!0 !A IMP!0 !D IMP!0 !I IMP!0 !A IMP!0 !D IMP!0 !I IMP!0.3 !A IMP!0.3 !D IMP!0.3 !I </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload