On 1/6/10 Wed  Jan 6, 2010  9:27 AM, "Grove, Michael" <migr...@state.pa.us>
scribbled:

> Can someone tell me why I need double quotes for this to work at the line
> with: print $first, $second, $third\n;
> 
> #!/usr/bin/perl -w
> 
> $first = 0xFF;
> $second = 0377;
> $third = 0b11111111;
> print $first, $second, $third\n;
> $answer = $first + $second + $third;
> print "$answer\n";
> 
> It only gives this output when I write double quotes "print $first, $second,
> $third\n";
> 
> 255, 255, 255
> 765

What output do you get when you do not write double quotes? I get 'Backslash
found where operator expected at ...'. Is that what you get? (It helps to
let us know what you are getting from your original version).

The print function prints strings. The unquoted \n is not a string - it is a
syntax error. If the \n is enclosed in double quotes, it will generate a
newline character.

Did you really mean "print $first, $second, $third\n"
or did you mean print "$first, $second, $third\n" ?
The former is a standalone string and does nothing. The latter will print
the results as you have shown.

You should put 'use strict;' at the top of your program, and remove the '-w'
and replace it with 'use warnings;'.



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to