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

Re: keeping split delimiters causing empty string elements

by Athanasius (Archbishop)
on Apr 15, 2016 at 13:15 UTC ( [id://1160522]=note: print w/replies, xml ) Need Help??


in reply to keeping split deliimiters causing empty string elements

Hello previous,

TMTOWTDI: Put the separator in a single capture group:

use strict; use warnings; use Data::Dump; my $eqn = '$profit=$sales-$cogs'; my @wrds = split /(=|-)/, $eqn; dd \@wrds;

Output:

23:13 >perl 1596_SoPW.pl ["\$profit", "=", "\$sales", "-", "\$cogs"] 23:13 >

See the final paragraph of split.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: keeping split delimiters causing empty string elements
by previous (Sexton) on Apr 15, 2016 at 17:59 UTC
    Hello Athanasius Thanks very much for your help and solution.

Log In?
Username:
Password:

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

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

    No recent polls found