in reply to Re^3: Print to specific line
in thread Print to specific line
I agree with Laurent. Using both is unnecessary.
Here's an adjusted version which only uses a hash and accounts for possible missing line numbers, which prevents the uninitialized warnings.
use 5.010; use strict; use warnings; use List::Util qw( max ); my %hash = ( 4 => 'The future is unknown.', 1 => 'The day before yesterday sucked.', 5 => 'Today is a good day.', 3 => 'Not much hope for tomorrow.', ); my $last = max keys %hash; for my $line ( 1 .. $last ) { say exists $hash{$line} ? $hash{$line} : ''; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Print to specific line
by GotToBTru (Prior) on Jun 23, 2015 at 19:01 UTC |