Front page | perl.beginners |
Postings from March 2003
Re: substring problems
Thread Previous
|
Thread Next
From:
tao wang
Date:
March 19, 2003 14:51
Subject:
Re: substring problems
Message ID:
20030319225121.86513.qmail@web14203.mail.yahoo.com
thanks a lot. But there is one problem - this is my
fault. The KEY1, KEY2 don't exactly look like this.
There are six KEYS. Three are related to KEYS, but the
rest of them are A_BEG A_END, B_OPTIONS, and I need to
extract information between them. I used one variable
$op=KEY1|KEY2|KEY3|A_BEG|A_END|B_OPTIONS to store all
the alternatives, and tried to use
my @values = $line =~ /$op.*$op/g;
But didn't work as i expected. Are there any
problems. please help me with it. thanks again.
- tao
--- Rob Dixon <rob@dixon.nildram.co.uk> wrote:
> Tao Wang wrote:
> > Hi Everyone,
> >
> > I'm having a problem with extracting certain
> strings
> > within a line. I tried several ways, but not very
> > inefficient. Can somebody help me with it? thanks
> a
> > lot.
> >
> > The line might be one of the following:
> > KEY1 3 4 T KEY2
> >
> > KEY1 3 4 T KEY2 456 67 KEY3
> >
> > KEY1 3 4 T KEY2 456 67 KEY3
> >
> > And I need to extract the information between
> KEYS.
> >
> > I'm using substr and pos to extract the
> information
> > now, but very complicated. Are there any better
> ways
> > to do it. please help me with it. I really
> appreciate
> > it. - tao
>
> Hi Tao.
>
> Does this do what you want? Forgive me for not
> explaining it,
> but it 00:40 here - I'm off to bed!
>
> HTH,
>
> Rob
>
>
> use strict;
> use warnings;
>
> while (<DATA>) {
> chomp;
> my @values = /KEY\d\s+(.+?)(?=\s+KEY)/g;
> print join (", ", @values), "\n";
> }
>
> __DATA__
> KEY1 3 4 T KEY2
> KEY1 3 4 T KEY2 456 67 KEY3
> KEY1 3 4 T KEY2 456 67 KEY3
>
> output:
>
> 3 4 T
> 3 4 T, 456 67
> 3 4 T, 456 67
>
>
>
>
> --
> To unsubscribe, e-mail:
> beginners-unsubscribe@perl.org
> For additional commands, e-mail:
> beginners-help@perl.org
>
__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com
Thread Previous
|
Thread Next