Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I have this small code to do in perl and i am now very sure of how to do it. I have read a line from the csv file int0 $_and now i need to extract a part of the string from it.

Ex line in csv file would be
one;two;three;four;five;six

and i need to have a variable (a scalar) to have the value
fourfive

(without the semicolon between four and five)
i tried with pattern matching but didnt get the proper results
can any one help.
Posted

1 solution

What you need is this:

$info = "one;two;three;four;five;six;"
@items = split(/;/, $info);
$extract = @items[3] + @items[4];


Now extract should contain the string "fourfive".
Arrays in perl are normally zero based, but I think there was something
to change that if you really needed it.
(Sorry I didn't do any Perl for quite some time now. :) )


Cheers

Manfred
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900