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

Re^2: putting text into array word by word

by jms53 (Monk)
on Jan 09, 2012 at 18:35 UTC ( #947054=note: print w/replies, xml ) Need Help??

in reply to Re: putting text into array word by word
in thread putting text into array word by word

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";

Replies are listed 'Best First'.
Re^3: putting text into array word by word
by ansh batra (Friar) on Jan 09, 2012 at 18:39 UTC
    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.

        OK, now that's solved, let's look at the definition of 'word' (yes, things are going to get hairy...). Take this sentence, for example:

        "No, he said."

        The 'words' that your current code would extract are:

        "No, he said."

        Is that really what you want? Or would you prefer:

        No # or, better, 'no' he said


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://947054]
[Corion]: So Hyperboria is an envrypted, decentralized IPv6 mesh network. I'm interested and want to look how good coverage is in my area. But the API for querying Hyperboria is only reachable over Hyperboria itself. Thanks but no thanks.

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2017-06-23 07:23 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (536 votes). Check out past polls.