You are not reading from a file, so
$. does not change. Either read from the input when printing the lines, or use an index to the array instead.
Here's how I modified your code:
#!/usr/bin/perl
use warnings;
use strict;
use feature qw{ say };
use v5.10;
sub view_all_railcars {
say "View All Cars";
*MYINPUTFILE = *DATA{IO}; # To simulate the input.
my $viewlines = 4;
print "=====================\n";
print "|CAR MODEL|CAR OWNER|\n";
print "=====================\n";
while (<MYINPUTFILE>) {
chomp;
my ($VcarModel, $VcarOwner) = split /:/;
$_ //= q() for $VcarModel, $VcarOwner;
if ($. > 1 and $. % $viewlines == 1) {
<>;
} else {
print "\n";
}
my $format = " %-13s %0s\n";
printf $format, $VcarModel, $VcarOwner;
}
print ("\n\n\nWHEN YOU ARE DONE VIEWING HIT RETURN: \n\n\n");
do 1 until defined <>; # Do not end on CTRL+D
say 'cls';
say 'Menu';
}
view_all_railcars();
__DATA__
Ford|Philip
Renault|Renee
Citroen|Cyrill
Mercedes|Mike
Chrysler|Chris
Bentley|Brian
BMW|Brittney
Chevrolet|Shirley
Skoda|Stanley
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.