Blame


1 ffd9a51f 2023-08-04 jrmu #!/usr/bin/perl
2 ffd9a51f 2023-08-04 jrmu
3 ffd9a51f 2023-08-04 jrmu #Modify the previous program to let the user choose the column width, so that
4 ffd9a51f 2023-08-04 jrmu #entering 30, hello, good-bye (on separate lines) would put the strings at the
5 ffd9a51f 2023-08-04 jrmu #30th column. (Hint: see "Interpolation of Scalar Variables into Strings" on
6 ffd9a51f 2023-08-04 jrmu #page 32, about controlling variable interpolation.) For extra credit, make the
7 ffd9a51f 2023-08-04 jrmu #ruler line longer when the selected width is larger.
8 ffd9a51f 2023-08-04 jrmu
9 ffd9a51f 2023-08-04 jrmu use v5.10;
10 ffd9a51f 2023-08-04 jrmu use warnings;
11 ffd9a51f 2023-08-04 jrmu use strict;
12 ffd9a51f 2023-08-04 jrmu use utf8;
13 ffd9a51f 2023-08-04 jrmu
14 ffd9a51f 2023-08-04 jrmu chomp(my @lines = <>);
15 ffd9a51f 2023-08-04 jrmu my $width = shift @lines;
16 ffd9a51f 2023-08-04 jrmu if ($width > 70) {
17 ffd9a51f 2023-08-04 jrmu print "1234567890"x($width/10 + 1) ."\n";
18 ffd9a51f 2023-08-04 jrmu } else {
19 ffd9a51f 2023-08-04 jrmu print "1234567890"x7 ."\n";
20 ffd9a51f 2023-08-04 jrmu }
21 ffd9a51f 2023-08-04 jrmu printf "%${width}s\n"x@lines, @lines;