in reply to Can a filehandle name be dynamic?
You can store a filehandle is a variable, so why not use an array of filehandles, e.g. open($aFiles[$i], ">>"$filename")?
Note: apparently print doesn't like print $aFiles[$i] "Some text" so you will have to assign the file handle to a scalar before using it, something like this:
use strict; use warnings; my @aFiles; for (0..2) { my $sFile = "foo.$_"; open($aFiles[$_], '>', $sFile) or die "$sFile: $!"; my $fh = $aFiles[$_]; #make print happy print $fh "Hello World\n"; close $fh; }
Best, beth
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can a filehandle name be dynamic?
by goeb (Pilgrim) on Sep 24, 2009 at 12:35 UTC | |
|
Re^2: Can a filehandle name be dynamic?
by almut (Canon) on Sep 24, 2009 at 13:47 UTC |