Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Parsing a line of text items

by philipbailey (Deacon)
on Mar 30, 2021 at 12:23 UTC ( #11130588=note: print w/replies, xml ) Need Help??


in reply to Parsing a line of text items

I often use Text::ParseWords for this problem. It has the advantage of being a core module.
use strict; use warnings; use feature "say"; use Text::ParseWords; my $args = '23 45.67 "John Marcus" Surname'; my @parsed = parse_line('\s+', 0, $args); say for @parsed;
Output:
23 45.67 John Marcus Surname

Replies are listed 'Best First'.
Re^2: Parsing a line of text items
by mikkoi (Beadle) on Mar 31, 2021 at 11:26 UTC

    Thanks. I had no idea Text-ParseWords existed. This is the ideal solution. And it is in the core!

    I also tested Text-CSV and while good, it left some problems, especially the possible multiple whitespace between words.

      I had no idea Text-ParseWords existed

      Likewise...
      Perhaps more time is needed studying the list of core modules

Re^2: Parsing a line of text items
by LanX (Cardinal) on Mar 30, 2021 at 15:58 UTC
    Oh Text::ParseWords is pretty cool, thanks for sharing. :)

    (So many core modules which need more attention)

    > It has the advantage of being a core module.

    Indeed.

    C:\Strawberry\perl\bin>corelist Text::ParseWords Data for 2021-01-23 Text::ParseWords was first released with perl 5

    Tho it's exporting a lot on default

    our @EXPORT = qw(shellwords quotewords nested_quotewords parse_line);

    And you can tell the documentation is old, could have more examples.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (None)
    As of 2021-05-10 01:19 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Perl 7 will be out ...





      Results (103 votes). Check out past polls.

      Notices?