Dec 16, 2005 #1 D 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
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
Dec 20, 2005 #2 L lovelyic Junior Member level 2 Joined Apr 28, 2002 Messages 23 Helped 2 Reputation 4 Reaction score 0 Trophy points 1,281 Activity points 201 Code: chomp $line @tmp_line = split(/\s+/, $line); for($i=0, $i <= $#tmp_line, $i++) { push(@myarray, $tmp_line[$i]); }
Code: chomp $line @tmp_line = split(/\s+/, $line); for($i=0, $i <= $#tmp_line, $i++) { push(@myarray, $tmp_line[$i]); }
Dec 20, 2005 #3 U urslen Member level 2 Joined Aug 10, 2004 Messages 45 Helped 7 Reputation 14 Reaction score 3 Trophy points 1,288 Activity points 493 The simple array declaration also may be done. Here is another possible way: Code: while(<INFILE>) { $line = $_; @a=$line; print @a; }
The simple array declaration also may be done. Here is another possible way: Code: while(<INFILE>) { $line = $_; @a=$line; print @a; }