in reply to Using the second word in a line to split a file into multiple files

This appears to work:

#!/usr/bin/perl use strict; use warnings; open my $infh, '<', 'testdat.dat' or die "Cannot open 'testdat.dat' be +cause: $!"; while ( my $line = <$infh> ) { if ( $line =~ /^zone\s*(\S+)\s+\S+\s*$/ ) { open my $outfh, '>', $1 or die "Cannot open '$1' because: $!"; select $outfh; } print $line or die "Failed to write to file: $!"; } close $infh;
  • Comment on Re: Using the second word in a line to split a file into multiple files
  • Download Code