On Oct 26, 3:51 am, [EMAIL PROTECTED] (Jeff Pang) wrote:
> using a regex is may suitable.
>
> $ perl -e '$x= "a;b;c;d;e;f;g;h";@re=$x=~/(\w+;\w+);{0,1}/g;print "@re"'
> a;b c;d e;f g;h
>
> On 10/26/07, Mahurshi Akilla <[EMAIL PROTECTED]> wrote:
>
>
>
> > Is there an easy way (without writing our own proc) to split a string
> > based on number of occurances of a character ?
>
> > for example:
>
> > $my_string = "a;b;c;d;e;f;g;h"
>
> > @regsplitarray = split (/;/, $my_string)   splits based on every 1
> > occurance of ";"
>
> > what if i want it to do 2 at a time ?  e.g. $regsplitarray[0] =
> > "a;b" .. $regsplitarray[1] = "c;d" .. and so on..
>
> > In this example, I used 2..  It could be n in general.  Is there a way
> > to do this without writing our own procedure ?
>
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >http://learn.perl.org/- Hide quoted text -
>
> - Show quoted text -

Great.  This does what I want when I tested it on the command line.
Could you explain me the code, starting from @re= ?

Thanks..


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to