Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: putting text into array word by word

by ansh batra (Friar)
on Jan 09, 2012 at 18:29 UTC ( #947049=note: print w/replies, xml ) Need Help??


in reply to putting text into array word by word

firstly your file loading option is wrong.use < instead of +>
secondly split function's first parameter should be \s
use this code
#! /usr/bin/perl open(FILE,"<input.txt"); print "file loaded \n"; my @lines=<FILE>; close(FILE); my @all_words; foreach my $line(@lines) { @temp_arr=split('\s',$line); push(@all_words,@temp_arr); } print "@all_words\n";

Replies are listed 'Best First'.
Re^2: putting text into array word by word
by jms53 (Monk) on Jan 09, 2012 at 18:35 UTC

    I have tried your code, and although I get no syntax errors, it does not print the array

    using the following code

    #! /usr/bin/perl -w use strict; open(FILE,"<input.txt"); print "file loaded \n"; my @lines=<FILE>; my @temp_arr; close(FILE); my @all_words; foreach my $line(@lines) { @temp_arr=split('\s',$line); push(@all_words,@temp_arr); } print "@all_words\n";
      check your file from which you are taking the input.
      since you used +> parameter earlier , perl have deleted its contents.

        PERFECT, Thank you sooo much

        I can now go back to calmly pseudo-geeking.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://947049]
help
Chatterbox?
[Jenda]: The apparent design principle of Perl6 operators was "Let's confuse 'em dudes." Whose braindead idea was this particular operator and the three hundred around it?
[liz]: ^10 is just a short way of saying 0..^10, which is a short way of saying 0..9
[liz]: ^N is a very common idiom in Perl 6 to indicate "N times"

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2018-07-16 16:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (344 votes). Check out past polls.

    Notices?