Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Split lines in file to columns

by hdb (Monsignor)
on Mar 20, 2019 at 10:01 UTC ( [id://1231485]=note: print w/replies, xml ) Need Help??


in reply to Split lines in file to columns

If all your columns are fixed-width, you can use unpack

use strict; use warnings; while(<DATA>) { my ($colA, $colB, $colC,$colD) = unpack "A19A15A7A45"; $colC = "N/A" if $colC eq "XYZ" and $colD =~ /Region/; print "$colA -- $colB -- $colC -- $colD\n"; } __DATA__ ValuesInColumn1 DataColumnB XYZ RowDescription|RowCode|Suppli +er ID::Region ValuesInColumn1 DataColumnB XYZ RowDescription|RowCode|Suppli +er ID::Region ValuesInColumn1 DataColumnB XYZ RowDescription|RowCode|Suppli +er ID::Region ValuesInColumn1 DataColumnB XYZ RowDescription at RowCode ValuesInColumn1 DataColumnB ABC RowDescription at RowCode

Log In?
Username:
Password:

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

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

    No recent polls found