I have a perl script that receives 3 arugments.
First argument is very long and contains spaces and quotes and I actually don’t know what size to expect it could be any size . To separate my arguments I use “:” sign.
See example:
./my_script.pl 2MT5 4XAW KEAR TTRR YYMM “TEMP 2012 FEB 01”:Single:123.x
The problem is that I lose double quotes and spaces.See output :
LOG The 1st input is:2MT54XAWKEARTTRRYYMMTEMP 2012 FEB 01
LOG Type is:Single
LOG Version is:123.x
My Code :
open (FD, ">file2.txt");
print FD @ARGV;
close FD;
my $str1=`cat file2.txt`;
my @argv_values = split(':',$str1);
$new_str = $argv_values[0];
$type = $argv_values[1];
$ver = $argv_values[2];
Your Perl program does NOT receive 3 arguments, it receives 6 arguments. Simply print them out to see for yourself:
Your first argument (2MT5) is not “very long” it is only 4 characters.
You do not have a Perl problem, you have a shell problem. The shell splits args on spaces and processes double quotes. If you don’t want it to do that, then you must quote any args that contain spaces or quotes: