开发者

perl + set value in parameter

开发者 https://www.devze.com 2023-01-12 09:25 出处:网络
With the following example script I try to print the parameter[1] content. My question is how to print also FLORIDA word (in place $VAL)

With the following example script I try to print the parameter[1] content. My question is how to print also FLORIDA word (in place $VAL) so I wil开发者_运维技巧l get FLORIDA on print output

#!/usr/bin/perl

my @parameter = ();
my $VAL=FLORIDA;

$parameter[1]='45487539
               $VAL
               5847366
               83564566';

print $parameter[1];

Output:

45487539
               $VAL
               5847366
               83564566


$parameter[1]="45487539
               $VAL
               5847366
               83564566";

Try that.


The answer is to replace the single quotes "'" with double quotes """. Now it will work.


If you need to dynamically replace variables from user supplied data, use the following syntax:

$parameters[1] =~ s/\$(\w+)\b/eval "return \$$1;"/ge;
print $parameters[1];
0

精彩评论

暂无评论...
验证码 换一张
取 消