How to a parse a string in perl

2002-05-10 Thread FLAHERTY, JIM-CONT

 I want to slice up this variable into a single variable and loop until its
empty
The variable is seperated via  !  explnation points and I want the numbers.
This string can be various in length ? Note it doesnt end with that
delimiter. Help
 
example 
 
  $jims = "!23!45!67



Re: How to a parse a string in perl

2002-05-10 Thread Jeff 'japhy' Pinyan

On May 10, FLAHERTY, JIM-CONT said:

>This string can be various in length ? Note it doesnt end with that
>delimiter. Help
> 
>  $jims = "!23!45!67

You could use split(), but you'd have to get rid of the first
(empty) element.  Instead, I would suggest the following regex:

  while ($string =~ /!([^!]*)/g) {
my $num = $1;
# ...
  }

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: How to a parse a string in perl

2002-05-10 Thread David Gray

>  I want to slice up this variable into a single variable and 
> loop until its empty The variable is seperated via  !  
> explnation points and I want the numbers. This string can be 
> various in length ? Note it doesnt end with that delimiter. Help
>  
> example 
>  
>   $jims = "!23!45!67

How about:

my $jims = "!23!45!67";
my @nums = ();
push @nums,$1 while $jims =~ /!?(\d+)/g;

If that doesn't solve your problem, could you please post more data or
examples of what you've tried that hasn't worked?

Cheers,

 -dave



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: How to a parse a string in perl

2002-05-10 Thread Eric Wang

Can you explain what all that means?
specifically the /!([^!]*)/g part
and the $1 part

I only had limited automaton experience
thanks for your time

Eric

> You could use split(), but you'd have to get rid of the first
> (empty) element.  Instead, I would suggest the following regex:
>
>   while ($string =~ /!([^!]*)/g) {
> my $num = $1;
> # ...
>   }
>
> --
> Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
> RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
> ** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
>  what does y/// stand for?   why, yansliterate of course.
> [  I'm looking for programming work.  If you like my work, let me know.  ]
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: How to a parse a string in perl

2002-05-10 Thread drieux


On Friday, May 10, 2002, at 10:52 , Eric Wang wrote:

> Can you explain what all that means?
> specifically the /!([^!]*)/g part
> and the $1 part
>
> I only had limited automaton experience
> thanks for your time

the scary part is that this is part of the Regular Expression Game,
and less to do with 'automaton' - but as we all know RegEx is dead
since this can 'all be done so much simpler in XML'

david grays may be easier to explain:

my $jims = "!23!auntie45!67";
my @nums = ();
#push @nums,$1 while $jims =~ /!?(\d+)/g;   # the '?' is extraneous

while ($jims =~ /!  #find a ! token
(\d+)   # find one or more digits -
# put in $1 special variable 
if we match
/gx ) { # do this globally through the string
# enter the loop any time we have a match
push @nums,$1 ; # accumulate the matched things in @nums
}



ciao
drieux

---


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]