If you just have a string with items separated by dots, split might be able to do the job:
Or do you mean something more like this:use IO::File; ... my %fd; my %files = ( 'somestring' => 'somefilename', 'someother' => 'someother', ); my @items = ( 'somestring.this.content.will.go.into.somefilename', 'someother.this.will.go.into.someother', 'notthere.this.will.generate.a.warning', ); foreach @items { my @array = split(/\./); if (exists($files{$array[0]})) { $fd{$array[0]} ||= new IO::File "> $files{$array[0]}" or die "Couldn't open $files{$array[0]}: $!"; $fd{$array[0]}->print; } else { warn "No filename defined for $array[0]"; } } $fd{$_}->close for keys %fd;
If that doesn't look like it helps you with your problem (or at least puts you on the track to adapting some of this to your solution), please give us more information.my @array = ( [ 'somefilename', @data1 ], [ 'otherfilename', @data2 ], ); foreach @array { my $filename = shift(@{$_}); open(F, ">$filename") or die "Couldn't open $filename: $!"; print F join("\n", @{$_}), "\n"; }
In reply to Re: Variable Filehandles
by Fastolfe
in thread Variable Filehandles
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |