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

Re^3: text to array

by space_monk (Chaplain)
on Jun 06, 2013 at 08:02 UTC ( #1037402=note: print w/ replies, xml ) Need Help??

in reply to Re^2: text to array
in thread text to array

$names12[$i]=@myNames[$i].','; #should be $names12[$i]=$myNames[$i].',';

Actually there's lots more issues in your program than this one. Its really a case of if you want to solve this properly, don't start from where you are at present! :-)

Why are you splitting on tabs when you indicated you wanted to split out words before? The answers given in your previous question do things much more efficiently than your code, so what is wrong with them?

Please give an example of the text you want to split and what you want it to look like at the end

Something roughly like this will put all your data in @names12:

# execute as perl -n < myTextFile #!/usr/bin/perl # get the words from current text block and push into array.... while (/(\w+)/g) { push @names12, $1; } END { # your array contains words, now add comma to printout print join(',', @names12); }
If you spot any bugs in my solutions, it's because I've deliberately left them in as an exercise for the reader! :-)

Comment on Re^3: text to array
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (11)
As of 2015-11-30 18:42 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (778 votes), past polls