Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Help formatting text to delimited text in file

by jwkrahn (Abbot)
on Apr 21, 2019 at 00:26 UTC ( [id://1232841]=note: print w/replies, xml ) Need Help??


in reply to Help formatting text to delimited text in file

#!/usr/bin/perl use warnings; use strict; open my $IN, '<', 'input.txt' or die "Cannot open 'input.txt' becaus +e: $!"; open my $OUT, '>', 'output.txt' or die "Cannot open 'output.txt' becau +se: $!"; # Input record separator $/ = '+'; while ( <$IN> ) { # skip empty records next unless /\S/; # remove input record separator chomp; my ( $id, $name ) = ( $1, $2 ) if s/ \s* \^ \s* ( \d+ ) \s* % \s* +( .+? ) \s* \.\| \s* //x; for my $data ( split /\s*;\s*/ ) { print $OUT join( ',', map qq/"$_"/, $id, $name, split /\s*-\s* +/, $data ), "\n"; } }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-24 14:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found