Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenation needs a "space" in Perl?

Tags:

perl

Didn't find any explanation from google on the question, although it's possible that I did not use the correct search word.

script1:

#!usr/bin/perl
#concatenation2.pl
use warnings;
use strict;
print"Four sevens are",4*7 ,"\n";
print"Four sevens are".4*7 ."\n";

script2:

#!usr/bin/perl
#concatenation2.pl
use warnings;
use strict;
print"Four sevens are",4*7,"\n";
print"Four sevens are".4*7."\n";

The output for script1 is:

Four sevens are28
Four sevens are28

Okay, so I (learned that) need to have a space before I close the double quote. However, the output for script2 ends up a error message:

string found where operator expected at concatenate2.pl line 6, near "7."\n""
(Missing operator before "\n"?)
syntax error at concatenate2.pl line 6, near "7."\n""

Nowhere could I find an explanation why there needs to be a space between numbers and . in script2, while no space is needed between numbers and , I am currently relying on google and the free perl books to help me pick up the language. Any help (general guidelines for this kind of nuances) will be greatly appreciated. Thank you.

like image 865
B Chen Avatar asked Dec 21 '22 09:12

B Chen


1 Answers

7. is a number for perl lexer, like 3.1415926535. To avoid confusion, separate the dot from the preceding digit with a space: "the answer is " . 4*7 . " times more complicated".

like image 110
Anton Kovalenko Avatar answered Jan 09 '23 05:01

Anton Kovalenko