From 56877963f16686af6f357a3cd3ef017bb040482b Mon Sep 17 00:00:00 2001 From: Andinus Date: Sun, 14 Jun 2020 00:16:50 +0530 Subject: 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. --- ara.pl | 16 ++++++++-------- 1 file 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. -- cgit 1.4.1-2-gfad0