Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

by Happy-the-monk (Canon)
on Oct 26, 2004 at 15:58 UTC ( #402664=note: print w/replies, xml ) Need Help??


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

You are looking for split:

open( FILE, "bingo_in.txt" ) or die $!;
while (<FILE>) {
    # chomp; - isn't needed as pg points out in the node following up.
    my @words = split; #
no arguments: split $_ on white space
    foreach my $word (@words) { ...

Cheers, Sören

Update: chomp-line commented out

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

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:21 UTC

    chomp is not needed here, you can see this through this demo:

    use Data::Dumper; use strict; use warnings; $_ = "1 2\n3\t4\r\n5\n"; my @words = split; print Dumper(\@words);

    It gives you:

    $VAR1 = [ '1', '2', '3', '4', '5' ];

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2022-05-28 20:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (101 votes). Check out past polls.

    Notices?