Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
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 ( [id://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?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-19 16:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found