Brian Blake wrote:
>
> Hi,
Hello,
> I am very new to PERL (as you will be able to tell!!!), can you please
> explain my question below?
>
> When I run this piece of code (below) I am looking for more than one word
> to be etered by the user and then the words that were entered are returned
> to the user in a right justified 20 character column. However only the
> first word I enter is returned when @words is used (where marked in bold)
> but the $_ variable works correctly.
>
> Can you please tell me what the difference is and how does it work?
>
> print "please neter a word\n";
You are asking for _a word_, if you want more than one word you should
ask for it.
> chomp (@words = <STDIN>);
Standard I/O is line oriented. Do you want your users to enter words
like:
one two three four
or like?
one
two
three
four
> foreach (@words){
> printf "%20s\n", @words; #$_
foreach (and for) store the current element of @words in $_ by default.
printf (and sprintf) use the format string ("%20s\n") to determine how
many elements of the following list to print. Since your format string
only allows one element to be printed it will only print one.
printf "%20s\n", $_;
> }
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]