! for ($j=1;$j<=2;$j++) {
! $FileName= $File$j.dat;
! }
The problem seems to be in the two $ that appear there. How do you solve the problem?
Many thanks,
Felix
Use the string concatenation operator
$FileName= $File . $j . ".dat";
or use interpolation
$FileName= "$File$j.dat";
By the way,
for (my $j=1;$j<=2;$j++)
is not nearly as readable as
for my $j (1..2)
for(1..2) {
my $filename = $file . "$_.dat";
}
Update: s/j/_/;
$FileName= $File . $j . '.dat';Or interpolate them inside double quotes:
$FileName= "$File$j.dat";Or you can always use sprintf:
$FileName= sprintf '%s%d.dat', $File, $j;
#!/bin/perl-w
use strict;
my $File = "File";
for (1..2) {
my $FileName= "$File"."$_".'.dat';
print"Filename=> $FileName\n";
}
Thanks and Regards,perlmonks.org content © perlmonks.org and F/lix, friedo, ikegami, imp, madtoperl
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03