Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple split

Status
Not open for further replies.

MoshiachNow

IS-IT--Management
Joined
Feb 6, 2002
Messages
1,851
Location
IL
HI,

How do I split all data build of two columns separated by multiple spaces ?

Data:

a d
c v
d e

Need to get @abc=(a,d,c,v,d,e)

Thanks

Long live king Moshiach !
 
Code:
use strict;
use warnings;

my @stuff;

while (<>) {
   chomp;
   push @stuff, split(/\s+/, $_);
}

print join("\n", @stuff);

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::PerlDesignPatterns)[/small]
 
The default split will do that (omitting leading null fields), so you could shorten that to:
Code:
while (<>) {
   chomp;
   push @stuff, split;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top