Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: How do you place words from a sentence into an array?

by prasadbabu (Prior)
on Oct 26, 2004 at 16:05 UTC ( [id://402670]=note: print w/replies, xml ) Need Help??


in reply to How do you place words from a sentence into an array?

open FILE, "bingo_in.txt"; undef $/; $file = <FILE>; @lines = split /\n/, $file; for (@lines ) { @words = split; }

TIMTOWTDI

--Prasad

Replies are listed 'Best First'.
Re^2: How do you place words from a sentence into an array?
by pg (Canon) on Oct 26, 2004 at 16:25 UTC

    There is a bug, @words ends up only containing the "words" in the last line ;-) as you are resetting it for each line.

    Also there was no need for two splits, just one is good enough, and better use strict ;-)

    use Data::Dumper; use strict; use warnings; open FILE, "a.txt"; undef $/; $_ = <FILE>; close(FILE); my @words = split; print Dumper(\@words);

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-03-29 15:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found