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

Re: Syntax error in using do-until loop: How can I fix it?

by pvaldes (Chaplain)
on Jul 16, 2012 at 23:25 UTC ( #982103=note: print w/ replies, xml ) Need Help??


in reply to Syntax error in using do-until loop: How can I fix it?

Wishful thinking must die...

my $sentence="to baah or not to chomp, that's the question"; my $garbage = 0; $garbage++ while ($sentence =~ /[,'\s]/g); @chars = split //, $sentence; print "You can create ", (scalar(@chars) - $garbage)/4.0," groups of f +our characters here\n";

A little twisted but it works... note that you don't lose any info here in your sentence

Updated: printing the groups

@chars = grep {!/(,|'|\s)/} @chars; my $n = 0; while ($n < $#chars){ print $chars[$n],$chars[$n+1],$chars[$n+2],$chars[$n+3],"\n"; $n = $n+4}


Comment on Re: Syntax error in using do-until loop: How can I fix it?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2015-07-07 23:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls