
Jean
User

Apr 3, 2001, 9:42 AM
Post #1 of 5
(956 views)
|
|
Hash of file handles
|
Can't Post
|
|
I'm using a hash of file handles (example follows) and on my machine (ActiveState Perl 5.6.0 build 620) it works perfectly. The problem is when the same script is run on other machines it reports error. The question sounds funny, but anyway - is it some version/port specific functionality ? Just to help understand what's this all about: The following script writes the contents of the source file to the files named accoding to the first letter of the source file content, e.g. line "victory" will be copied to the file "V.imp"
my $SrcFile = $ARGV[0] || "users.imp"; my $Ext = 'imp'; my $CurLetter = "\0"; my $line; my %FN; # File Names my %FH; # File Handles # Open source file. open(SRCFILE, "<$SrcFile") or die "Unable to open file $SrcFile\n"; print "Working...\n"; while ( $line = <SRCFILE> ) { $CurLetter = substr($line, 0, 1); if ( !defined $FN{$CurLetter} ) { $FN{$CurLetter} = "$CurLetter.$Ext"; open($FH{$CurLetter}, ">".$FN{$CurLetter}) or die "Unable to open/create target file\n"; } print {$FH{$CurLetter}} "$line"; } print "Done.\n"; # Close all. close; Jean Spector QA Engineer @ Extent Technologies, Ltd. mage@lycosmail.com
|