Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: string concatenation, which way is better?

by trizen (Hermit)
on Aug 08, 2012 at 21:27 UTC ( #986365=note: print w/ replies, xml ) Need Help??


in reply to string concatenation, which way is better?

Both are good, but if you concatenate files and want to make your code portable, I recommend the File::Spec::Functions module.

Something like this:

use File::Spec::Functions qw(catfile); my $filename = catfile($file_dir, q{filename1.log.} . $today_date);

Back on the topic. The following codes are equivalent:
1. $this . q{/} . $that
2. join(q{/}, $this, $that)
3. "$this/$hat"
4. do{local $"=q{/}; "@{[$this, $that]}"}
5. sprintf('%s/%s', $this, $that)

Most used are: 1, 2, 3.


Comment on Re: string concatenation, which way is better?
Select or Download Code
Replies are listed 'Oldest First'.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2015-07-07 16:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (91 votes), past polls