--- Adriano Ferreira <[EMAIL PROTECTED]> 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
> . " ");
>
Hi Adriano,
The line code you provide doesn't work on my computer
but based on what you say I change it into this line
code and it works.
unshift @data, join (' ',(shift @data, shift @data));
One more question what if I have a file that have
different lines 1) some lines have number only 2) some
lines have more than 2 words at the begining?
my $line1='1 1 1 1 1';
my $line2='group A 2 2 2 2";
my $line3= 'group B and C 3 3 3 3";
Do you think I need a if statement to do the job?
Thanks,
Li
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>