about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-06-14 00:16:50 +0530
committerAndinus <andinus@nand.sh>2020-06-14 00:16:50 +0530
commit56877963f16686af6f357a3cd3ef017bb040482b (patch)
tree0be333578de86d369baa506407066e6b95da3c17
parentbc55695847c80b2a86becb54d72da30bbaf70048 (diff)
downloadara-56877963f16686af6f357a3cd3ef017bb040482b.tar.gz
Fix rows option behaviour
The behaviour was broken because previously it wouldn't have printed
as many rows as user had entered because of other options.

For example, say if user ran `ara --rows 2 --hide india`, previously
this would've printed only 1 row because "India" is always the first
row & the foreach loop would've looped only two times so
$rows_to_print was more like number of rows to iterate over.

Now it does what it says, it prints that many number of rows.
-rwxr-xr-xara.pl16
1 files changed, 8 insertions, 8 deletions
diff --git a/ara.pl b/ara.pl
index ee4ae78..6e8f622 100755
--- a/ara.pl
+++ b/ara.pl
@@ -171,14 +171,13 @@ if ( $state_notes ) {
         ->plus_minutes(30); # Current time in 'Asia/Kolkata' TimeZone.
 }
 
-# Print all the rows if $rows_to_print evaluates to False or is
-# greater than the size of @$statewise or if user wants $state_notes.
-$rows_to_print = scalar @$statewise
-    if ( not $rows_to_print
-             or $rows_to_print > scalar @$statewise
-             or $state_notes );
-
-foreach my $i ( 0 ... $rows_to_print - 1  ) {
+my $rows_printed = 0;
+foreach my $i ( 0 ... scalar @$statewise - 1 ) {
+    # $rows_printed is incremented at the end of this foreach loop.
+    if ( $rows_to_print ) {
+        last if $rows_printed == $rows_to_print;
+    }
+
     my $state = $statewise->[$i]{state};
 
     $state = "India"
@@ -286,6 +285,7 @@ foreach my $i ( 0 ... $rows_to_print - 1  ) {
             $update_info,
         );
     }
+    $rows_printed++;
 }
 
 # Generate tables.