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

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

by prasadbabu (Prior)
on Oct 26, 2004 at 16:05 UTC ( #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? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2022-05-29 07:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (101 votes). Check out past polls.

    Notices?