@text_lines = <STDIN>; chomp($text_lines);

The statement  chomp($text_lines); chomp-s the (nonexistent) scalar  $text_lines not the  @text_lines array. Always

use warnings; use strict;
at the start of your scripts. (Update: Actually, it's not accurate to describe  $text_lines as "nonexistent": if strictures are not enabled (see strict), just referring to such a variable causes Perl to call it into existence. This is known as autovivification (see perlglossary), and such a scalar is initialized with a default value of undef. However, chomp-ing undef doesn't do very much, and the script never accesses  $text_lines anywhere else, so...)

$column = <STDIN>;

This leaves  $column un-chomp-ed.

say "$ruler" x $column;

Not sure what this is supposed to do.

rrrrr eeeeee tyyyyy

This is just one line.

c:\@Work\Perl\monks>perl -le "use 5.010; ;; use warnings; use strict; ;; say 'Please enter a few lines of text. Press ctrl-Z when finished'; my @text_lines = <STDIN>; chomp(@text_lines); ;; say 'Please enter the width of the column: '; my $column = <STDIN>; chomp $column; ;; my $ruler = '1234567890'; say $ruler x $column; ;; foreach (@text_lines) { printf qq{%${column}s\n}, $_; } " Please enter a few lines of text. Press ctrl-Z when finished xyzzy now is the time for all good men x foo bar ^Z Please enter the width of the column: 7 1234567890123456789012345678901234567890123456789012345678901234567890 xyzzy now is the time for all good men x foo bar
(Run under Windoze, so had to use ^Z instead of ^D.)

Update: Try
    printf qq{%*s\n}, $column, $_;
as an experiment (see * format specifier in sprintf specifier definitions).
(Update: Tried that? Ok, now try
    printf qq{%*.*s\n}, $column, $column, $_;
also.)


Give a man a fish:  <%-{-{-{-<


In reply to Re: Print format not working (updated) by AnomalousMonk
in thread Print format not working by catfish1116

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.