Perl Split lines into array??

Status
Not open for further replies.

davyzhu

Advanced Member level 1
Joined
May 23, 2004
Messages
494
Helped
5
Reputation
10
Reaction score
2
Trophy points
1,298
Location
oriental
Activity points
4,436
split lines into array perl

Hi all,

I am new to perl.

I use
#------------------
while(<INFILE>) {
$line = $_;
}
#------------------
to get one line from the file,

The line may like: sum 11 32
How to split lines into array like @myarray = {"sum","11","32"}; which knowing how many space between the words?

Any suggestions will be appreciated!
Davy
 

Code:
chomp $line
@tmp_line = split(/\s+/, $line);
for($i=0, $i <= $#tmp_line, $i++)
{
  push(@myarray, $tmp_line[$i]);
}
 

    davyzhu

    Points: 2
    Helpful Answer Positive Rating
The simple array declaration also may be done. Here is another possible way:

Code:
while(<INFILE>) {
$line = $_;
@a=$line;
print @a;
}
 

    davyzhu

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…