Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Unpack or substr to create CSV?

by toolic (Bishop)
on May 02, 2015 at 16:23 UTC ( [id://1125454]=note: print w/replies, xml ) Need Help??


in reply to Unpack or substr to create CSV?

Since the fields never change length it would seem that unpack is a better choice than substr, is that correct?
Perhaps. Read perlpacktut, which compares the various approaches. Here is an example of using unpack to parse each line into an array:
use warnings; use strict; while (<DATA>) { chomp; my @cols = unpack 'A1A15A14A16', $_; print join(',', @cols), "\n"; } __DATA__ C4432882490H019000020150211ESL6690 0H2015PC C4833076550HC0P0000201412093J46651 0H2015DX C6033106980H057130020150323FRE7602 0H2015PC C663160140MT007015G20141124274847A MT2015PC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-19 19:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found