Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: How to combine string and digits in perl

by davido (Cardinal)
on Mar 17, 2021 at 13:48 UTC ( [id://11129827]=note: print w/replies, xml ) Need Help??


in reply to How to combine string and digits in perl

The concatenation operator (dot), described in perlop, is not intended to be used inside a string. It is expected to join strings. So the following work:

"foo" . '_' . 123 $abc . '_' . 123 "foo" . '_' . $num

But the following do not work, because dot inside a string is just a dot, not an operator:

"$abc . _ . 123" "foo . _ . $num"

What you want is one of the following:

"${abc}_$_" # 1 $abc . '_' . $_ # 2 join('_', $abc, $_) # 3 "$abc\_.$_" # 4 $abc . "_$_" # 5

I prefer option 1, 2 or 3. Option 2 is probably the most legible.

Perl would probably make a lot more sense if you read perlintro, perlsyn, perlop, perlsub, and perldata. That's a couple hours worth of material, but it would move you forward in your learning curve.

In perlop you can also read The Gory Details of Parsing Quote and Quote-like Constructs.


Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11129827]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-03-28 12:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found