Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: split with a delimiter, every 4 time it occurs.

by hdb (Prior)
on Jul 01, 2013 at 07:10 UTC ( #1041767=note: print w/ replies, xml ) Need Help??


in reply to split with a delimiter, every 4 time it occurs.

Splitting can be done in other ways than using split. Here it is by far easier to describe the pieces that should result from the splitting and use a regex (a simple regex, relatively simple regex):

use strict; use warnings; my $to_split = "'A','B','C','D','E','F','G','H','I','J','K','L','M','N +','O','P','Q','R','S','T','U','V','W','X','Y','Z'"; my @pieces = $to_split =~ /('\w'(?:,'\w'){0,4})/g; $"="\n"; print "@pieces\n";

Or, if you insist on split, use the above as a delimiter, and remove the commas:

use strict; use warnings; my $to_split = "'A','B','C','D','E','F','G','H','I','J','K','L','M','N +','O','P','Q','R','S','T','U','V','W','X','Y','Z'"; my @pieces = grep {$_} split /('\w'(?:,'\w'){0,4}),?/, $to_split; $"="\n"; print "@pieces\n";


Comment on Re: split with a delimiter, every 4 time it occurs.
Select or Download Code
Re^2: split with a delimiter, every 4 time it occurs.
by Anonymous Monk on Jul 01, 2013 at 08:19 UTC
    I want this ','(not just comma) as the delimiter. I tried changein the coma to ',' but not working!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2014-12-19 15:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (85 votes), past polls