Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Perl Split lines into array??

Status
Not open for further replies.

davyzhu

Advanced Member level 1
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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top