Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Modifying text file

by torres09 (Acolyte)
on Jun 06, 2013 at 03:34 UTC ( #1037353=note: print w/ replies, xml ) Need Help??


in reply to Re: Modifying text file
in thread Modifying text file

Sir

I actually want it , i.e. I want that each word in the text file should be in an array , with a comma in between .Even the spaces


Comment on Re^2: Modifying text file
Re^3: Modifying text file
by hdb (Prior) on Jun 06, 2013 at 07:30 UTC

    Apologies if you perceived my answer as being patronizing.

    If you want to split your text into words AND keep the spaces, split might be an alternative. Using a capture group in the regex in split, the delimiters are not discarded. So splitting on words will give you the words and the characters inbetween:

    use strict; use warnings; use Data::Dumper; my $text = <<EOTEXT; This is a word. Here is another sentence. EOTEXT my @words = split /\b(\w+)\b/, $text; print Dumper \@words;

    results in

    $VAR1 = [ '', 'This', ' ', 'is', ' ', 'a', ' ', 'word', '. ', 'Here', ' ', 'is', ' ', 'another', ' ', 'sentence', '. ' ];

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2015-07-06 00:14 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 (68 votes), past polls