Thanks for explaining the while loop, but what I was wondering is why perl
printed the happy face and heart in the first place? I was using ASCII
Characters and there aren't any like that.
Thanks
Joel
----- Original Message -----
From: "Shaw, Matthew" <[EMAIL PROTECTED]>
To: "Joel" <[EMAIL PROTECTED]>
Sent: Tuesday, March 02, 2004 12:13 PM
Subject: RE: Why did it print a happy face?
Joel:
There's a few problems with your sample code... please see my comments
below:
#!usr/bin/perl # You forgot the leading slash in your path here
use Warnings; # This should be 'use warnings;' (Lowercase)
use Strict; # This should be 'use strict;' (Lowercase)
my $h=4;
my @word = (0x4E, 0x65, 0x72, 0x64);
while ($h > 0) {
$h++; # This should probably be $h-- if you want your while loop to end
$letter=shift @word;
print chr(@word); # chr() is evaluating the @word array in scalar
context,
# which returns the number of elements in the
array.
# this line is printing the characters 4, 3, 2,
1 (As you
# shift off the array) and finally '0' over and
over
# again when the array contains no elements.
}
# end
Here's another way of writing what (I think) you intended:
#!/usr/bin/perl
use warnings;
use strict;
my @word = (0x4E, 0x65, 0x72, 0x64);
print chr for @word;
# end
Hope this helps. Enjoy and let me know if you have any questions.
Thanks
Matt Shaw
Technical Architect
xwave, An Aliant Company
Desk: 506-389-4641
Cell: 506-863-8949
[EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>