Q:

how to add slash separator in perl

I have the following command 
how could I add "\" (path) between v1 and bin in perl to say : c:\path\bin 
as v1 = c:\path
system(dirname($v1) . $bin . " " . $trinp);

could someone recommend tutorial for perl?
Thanks

A:

If you are trying to create a path, using File::Spec is a good idea. It is a core module, so it will already be on your system.
use strict;
use warnings;
use File::Spec;

my @path = qw(C: path bin);
my $path = File::Spec->catdir(@path);
print $path;

Output in Windows:
C:\path\bin

If you wish to emulate another OS, you can select the appropriate module for it, e.g.
use File::Spec::Win32;
use File::Spec::Unix;

As for myself, if I use the Unix version, I get the output:
C:/path/bin

(Note for forward slashes)

A:

You have asked a question that has multiple answers. To just put a backslash in to form a Windows path, you need to escape the backslash thus, and this will solve your direct problem:
system($v1 . "\\" . $bin . " " . $trinp);

However, there are a few refinements. Firstly, you can use Perl's interpolation to make it easier to read:
system("$v1\\$bin $trinp");

You can also use Unix-style forward slashes, as Windows understands these, and prevents so-called "backslashitis":
system("$v1/$bin $trinp");

A better way however is to use Path::Class to generate paths on any operating system.
Further, there is a potential security problem in your code that can be caused if $trinp (or any of the other variables) contains shell metacharacters such as | to pipe into another command. If you provide a list of arguments to the system() function, it will pass those directly to the command instead of the shell. You will probably also want to check if the command was successful, and do something useful (e.g. die()ing) if it failed:
system("$vi/$bin", $trinp) == 0
   or die "Couldn't run $vi/$bin: $!";

I'll leave it as an exercise for you to convert my final example to use Path::Class.
[Edited to correct misuse use of system(), which returns the status of the command that was run which is zero for success. I confused it with more common other Perl functions which return nonzero for success.]

