use diagnostics; use strict; open (FILE, "c:\\my\\dir\\src.file.txt") || die "failed to open src file"; while (Using the strict pragma, I have found that I need to do some editing to the open function. Yet the print function alludes me.){ my $var_a = $_; my $var_b = "_INDEX"; my $var_c = $_; $var_a =~ s/(^[A-Z]{4})(.*)/$1/o; $comb = $var_a . $var_b; open ($comb, "c:\\my\\dest\\dir\\" . $comb . "found.txt") || die "failure to create" . $comb; print $comb $var_c . "content detail for file found\n"; } close FILE; #_## do some other functions that add more information to file. close $comb.
WORKS: open ('$comb', "c:\\my\\dest\\dir\\" . $comb . "found.txt")
Unable to figure out the print function.
ERROR: print $comb $var_c . "content detail for file found\n";
ERROR output:
Can't use string ("ACFT_INDEX") as a symbol ref while "strict refs"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 () { 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"; }
Your $comb is not declared to satisfy strict,
# . . .
my $comb = $var_a . $var_b;
Then you try to use the value of $comb as the filehandle name as well as part of the file name. Why not use a lexical file handle? You open the file to read, not write, so your print will fail in any case.
open (my $fh, '>', "c:\\my\\dest\\dir\\" . $comb . "found.txt")
|| die "failure to create" . $comb;
print $fh $var_c, "content detail for file found\n";
After Compline,
Zaxo
require("hlpsymbgen.config"); # general variables
use diagnostics;
use strict;
open (SCINDEX, "$::inputDir\\SymbolCategories.txt")
|| die "Failed to Open SymbolCategories.txt. \n";
my $comb;
while (){
my $cat_title = $_;
my $var_c = $_;
my $sufix = "_INDEX";
if ($cat_title ne 'NULL' && $var_c =~ m/::/o == 0){
$cat_title =~ s/(^[A-Z]{4})(.*)/$1/o;
$cat_title =~ s/\n|\r//g;
$cat_title =~ s/\s//g;
$comb = $cat_title . $sufix;
open ($::{'comb'}, ">$::outputDir\\" . $cat_title . "index.html")
|| die "Failure to create" . $cat_title . "\n";
print { $::{'comb'} } $var_c . "content detail for file found\n";
close $::{'comb'};
}
}
close SCINDEX;
I don't know if the initial idea will work and I may end up having to use the fixed FILEHANDLE name. In the end whatever I end up with will be faster than doing by hand.perlmonks.org content © perlmonks.org and Anonymous Monk, chromatic, Zaxo
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03