monkeyking monkeyking - 2 months ago 5x
Perl Question

How to print variables in Perl

I'm extremely new in Perl.

I have some code that looks like

my ($ids,$nIds);
while (<myFile>){
$ids.= $_." ";

This should concatenate every line in my
, and
should be my number of lines.
How do i print out my

I tried simply
print $ids
, but Perl complains.

my ($ids,$nIds)

Is a list right? with 2 elements?

print "Number of lines: $nids\n";
print "Content: $ids\n";

How did Perl complain? print $ids should work, though you probably want a newline at the end, either explicitly with print as above or implicitly by using say or -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 {}:

print "foo${ids}bar";