• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 155
  • Last Modified:

Printing Mutliple Fields from Split

This is not a homework assignment.
I have the following statements within a script:
  @fields=split /\s+/,$line;  ;  #Split the line at semicolons
  print FH "$fields[0]\n"; #Print the first field

How is it that I would alter the print statment so that it prints multiple fields.  I tried the following but they failed:
  print FH "$fields[0,2] \n"; #Print the first field
  print FH "$fields[0...5] \n"; #Print the first field

Thanks for your help.
0
uluttrell
Asked:
uluttrell
1 Solution
 
ozoCommented:
print FH "@fields[0,2] \n";
print FH "@fields[0...5] \n";
0
 
prady_21Commented:
ozo has already given you the solution
@fields=split /\s+/,$line;  ;  #Split the line at semicolons

but the above line dosent split on semicolons, it splits on spaces
to split a line on semicolons ->
@fields=split(/;/,$line);

0
 
uluttrellAuthor Commented:
prady_21, you are correct.  I was thinking of semicolons when I typed the comment.  I did want it to split on whitespaces.

Ozo, I am awarding the points to you.  Thank you both.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now