Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Parsing a line of text items

by hippo (Bishop)
on Mar 30, 2021 at 11:25 UTC ( [id://11130585]=note: print w/replies, xml ) Need Help??


in reply to Parsing a line of text items

A Text::CSV solution:

use strict; use warnings; use Text::CSV; use Test::More tests => 2; my $in = '23 45.67 "John Marcus" Surname'; my $want = [23, 45.67, 'John Marcus', 'Surname']; my $csv = Text::CSV->new ({sep_char => ' '}); ok $csv->parse ($in), 'Parsing'; is_deeply [$csv->fields], $want, 'Fields match';

You will probably want to extend the tests to better reflect your real-world requirements.


🦛

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (1)
As of 2024-04-19 00:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found