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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

breaking down a scalar into an array 1

Status
Not open for further replies.

tood

Technical User
Jul 15, 2001
22
US
Hi, newbie to perl here. please be gentle.

how can I get a comma delimited line of text from a scalar into an array.

example text: bnr,KIL,vi,dd,,,,,,dse,sdg,,,,,,

I actually want to use the second field, in this case "KIL". I thought if I could get it into an array I could just index it.



 

I think I worked this out

$x contains: bnr,KIL,vi,dd,,,,,,dse,sdg,,,,,,

@y=split(/,/,$x);
$z=$y[1];
print "$z \n";

output: KIL

this seems to work.
Is there an easier way to do this?
 
There's a module called Text::CSV for working with CSV files

HTH
--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top