Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by jwkrahn (Abbot)
on Aug 26, 2019 at 22:25 UTC ( [id://11105093]=note: print w/replies, xml ) Need Help??


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;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11105093]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-03-29 11:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found