[EMAIL PROTECTED] wrote:
Hello
Hello,
I have a string that I am trying to parse out into separate variables.
I am having problems getting the first field extracted. I want to extract
fields using period (.) and underline (_) delimineters.
Here is the string
aaa_b_ccccc_.ddd
The string is contained in $_.
Here is my code
($a, $b, $c, $d, $e, $e) = (split /_|\./)[1,2,3,4,5,6];
I am not getting the "aaa". I am getting b when I should be getting a.
That is because you are starting at 1 while Perl's arrays and lists
start at 0.
( $a, $b, $c, $d, $e, $f ) = ( split /[_.]/ )[ 0 .. 5 ];
Or just:
( $a, $b, $c, $d, $e, $f ) = split /[_.]/;
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/