M
M
Makarov2015-07-16 21:03:47
Perl
Makarov, 2015-07-16 21:03:47

String concatenation in Perl 5?

print "1fred2" * 2."\n";
Why is it not interpreted?
Here's what's in the console:

String found where operator expected at hello.pl line 1, near "2."\n""
(Missing operator before "\n"?)
syntax error at hello.pl line 1, near "2."\n""
Execution of hello.pl aborted due to compilation errors.

Shouldn't 1 be multiplied by 2 and then converted to a string due to the concatenation operator (i.e. 2 would have to be converted to "2")?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vaut, 2015-07-16
@s3lfstyle

Put a space after 2. Otherwise "." treated as a number instead of a concatenation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question