I have some code that looks like
my ($ids,$nIds);
while (<myFile>){
chomp;
$ids.= $_ . " ";
$nIds++;
}
This should concatenate every line in my myFile, and nIds should be my number of lines. How do I print out my $ids and $nIds?
I tried simply print $ids, but Perl complains.
my ($ids, $nIds)
is a list, right? With two elements?
How did Perl complain?
print $idsshould work, though you probably want a newline at the end, either explicitly withprintas above or implicitly by usingsayor -l/$\.If you want to interpolate a variable in a string and have something immediately after it that would looks like part of the variable but isn’t, enclose the variable name in
{}: