Adriano Ferreira wrote:
>
> On 9/6/06, chen li <[EMAIL PROTECTED]> wrote:
>
>> I need a regular expression to process some data but
>> get stuck. I wonder if anyone here might have a clue.
>>
>> input:
>> my $line='group A 1 2 3 4';# separated by space
>>
>> results:
>> my @data=("group A ",1,2,3,4);
>
>
> You barely need a regular expression for this. A split followed by a
> join of the first two items would do.
>
> @data = split ' ', $line;
> unshift @data, (shift @data . " " . shift @data . " ");
It's very bad form to post something to the list that simply doesn't work. This
won't even compile:
Type of arg 1 to shift must be array (not concatenation (.) or string) at
E:\Perl\source\xx.pl line 2, near "" ")"
And it's because the concatenation ('.') operator has a higher priority than the
shift operator, so you've written:
unshift @data, (shift(@data . " " . shift(@data . " ")));
which isn't at all what was intended. This fixes it:
unshift @data, shift(@data) . " " . shift(@data) . " ";
(ironically, the outermost parentheses aren't required)
Why did I have to test this code for you?
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>