Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: not able to get the output using split function

by CountZero (Bishop)
on Sep 02, 2012 at 17:39 UTC ( #991313=note: print w/replies, xml ) Need Help??

in reply to not able to get the output using split function

That ungainly "C-style" for loop, can be made much more perlish as follows:
use Modern::Perl '2011'; my $sentence = 'aaaa bbb ccc'; my @words = split(/\s+/, $sentence); my $i; while (my ($i, $word) = each @words) { say "$i: $word"; }
Note: it will need at least Perl 5.012 to work.


A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2016-10-21 21:11 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (291 votes). Check out past polls.