开发者

perl + set value in parameter

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜