in reply to How do you properly use a variable for FILEHANDLE in print vs open
Is there a reason you need a named filehandle? Reusing the same variable for the filehandle and the file name seems to be tripping you up. I'd write:
while (<FILE>) { my $var_a = $_; my $var_b = "_INDEX"; my $var_c = $_; $var_a =~ s/(^[A-Z]{4})(.*)/$1/; $comb = $var_a . $var_b; open (my $fh, "c:\\my\\dest\\dir\\" . $comb . "found.txt") or die "failure to create '$comb': $!\n"; print $fh $var_c . "content detail for file found\n"; }
|
|---|