Reputation: 11
#!/usr/bin/perl
$test ="@test=hello"; #(Actually am reading this text from File and assigning to a variable)
print "$test";
After executing the above code perl outputs the below
Output:
=hello instead of @test=hello.
Can anyone please explain the above. I believe that it is considering as empty array, but how can i avoid this when and reading a file, please clear my misconception.
Thanks,
Upvotes: 1
Views: 39
Reputation: 943645
Perl interpolates variables in strings delimited by double quotes.
@test
is treated as an array.
Unless you have created this explicitly, you should get an error when you try to do that. If you don't then you must have forgotten to use strict;
and use warnings;
!
Use single quoted strings if you don't want to interpolate variables.
#!/usr/bin/env perl
use strict;
use warnings;
use v5.10;
my $test = '@test=hello';
say $test;
Upvotes: 3