How can I split a string into only two parts with Perl?

In order to get that, you need to use the 3rd parameter to split() which gives the function a maximum number of fields to split into (if positive): my($first, $rest) = split(/\t/, $string, 2).

In order to get that, you need to use the 3rd parameter to split(), which gives the function a maximum number of fields to split into (if positive): my($first, $rest) = split(/\t/, $string, 2).

What if the value's length is uncertain, and I want to capture all of it in $v. $v's format is going to look like date_1\tvalue_1\tdate_2\tvalue_2\tdate_3\tvalue_3... – biznez Sep 11 '09 at 18:37 1 This will capture "date_1" in $k, and "value_1\tdate_2\tvalue_2\tdate_3\tvalue_3..." in $v. For more information, I linked to the perldoc reference page on the split() function - it will explain how it works in all the detail you could ever want.

I suggest you read it. Perldoc is very informative. – Chris Lutz Sep 11 '09 at 18:39.

No. It will give you the first two items and toss the rest. Try this: my ($k, $v) = split(/\t/, $string, 2).

What if the value's length is uncertain, and I want to capture all of it in $v. $v's format is going to look like date_1\tvalue_1\tdate_2\tvalue_2\tdate_3\tvalue_3... – biznez Sep 11 '09 at 18:36 Like Chris Lutz said in his comment, the number tells Perl how many parts to split into. So, with a value of 2, the first part goes in $v, the first \t in consumed in the split, and the remainder of the string goes unaltered into $v.

– jbourque Sep 11 '09 at 18:44.

Another option would be to use a simple regex. My($k,$v) = $str =~ /(^\t+)\t(.+).

I want to split it up only on the first tab, so that "Hello" ends up in $k and and rest ends up in $v. How can I do that?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions