[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Variable Names in Formatted Output

On Thu, Jun 10, 1999 at 05:29:43PM -0400, Robert wrote:
> At 14.23 -0400 1999.06.10, Robert wrote:
> >I'm learning the examples from _Learning Perl on Win32 Systems_ using my
> >PowerBook. The following example does not work correctly. It appears that I
> >am incorrectly specifying that columnz is a variable. The script just
> >outputs words, right-justified, in a column of an arbitrary width. What am I
> >doing wrong?
> >
> >print "How many columns? ";
> >chomp ($columnz = <STDIN>);
> >print "Enter a list of words:\n";
> >chomp (@list = <STDIN>);
> >foreach (@list) {
> > printf "%${columnz}s\n", $_;
> > }
> Chris wrote:
> Looks fine, but your post has a problem.  You say "The following example
> does not work correctly", without telling us what it is doing that is wrong.
> The first five lines execute as expected. When I enter Cntrol-D to end the
> array entry, I fully expect the lines to print. They do not. Nothing
> happens. I feel confident in the loop. the printf syntax may have me
> confused. As the title of the post indicates. Is there something wrong with
> a variable used with curly quotes in this manner?

Although you are using the book _Learning Perl on Win32 Systems_, you are
in fact using MacPerl, correct?

Does this script behave properly?

print "How many columns? ";
chomp ($columnz = <STDIN>);
print "Enter a list of words:\n";
@list = qw(first second third fourth);
foreach (@list) {
    printf "%${columnz}s\n", $_;

Also, when you say 'curly quotes', I assume you mean 'double quotes'.  Perl
doesn't recognize curly quotes.


===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org