Re: a very simple question

2002-01-29 Thread Jonathan E. Paton
> I assume you want > > $str = $1 if $str =~ /(\d\d\s*$)/; > > always make sure to test for a match before using $1, $2, > etc. If you don't you may get a runtime warning. Only when you try to use $str later when it is undefined. It should be checked, but perhaps not in the same place. Thi

RE: a very simple question

2002-01-29 Thread Jeff 'japhy' Pinyan
On Jan 29, [EMAIL PROTECTED] said: >I am sure we could do it in one step as this: > $str =~ s/(\d\d\s*)$/$1; No, that's missing the last /, and all it does is replace what it matches with itself. ($str) = $str =~ /(\d\d\s*)$/; works, though. >> $str =~ /(\d\d\s*)$/; >> $str = $1; Thi

RE: a very simple question

2002-01-29 Thread Jonathan E. Paton
> Tanton: > > I am sure we could do it in one step as this: > $str =~ s/(\d\d\s*)$/$1/; > > Right? Sorta, that'll take the end of the string according to the match, and REPLACE IT with the end of the string - handy huh. So it matches: '34 ' from: 'JunkJunkJunk34 ' and adds it to

Re: a very simple question

2002-01-29 Thread Chas Owens
I assume you want $str = $1 if $str =~ /(\d\d\s*$)/; always make sure to test for a match before using $1, $2, etc. If you don't you may get a runtime warning. On Tue, 2002-01-29 at 16:12, Dhiraj P Nilange wrote: > > Hello > actually its very simple to answer for who knows basic perl. > > Su

Re: a very simple question

2002-01-29 Thread Tanton Gibbs
yep, that'll work too. - Original Message - From: <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Tuesday, January 29, 2002 4:18 PM Subject: RE: a very simple question > Tanton: > > I am sure we could do i

Re: a very simple question

2002-01-29 Thread Jonathan E. Paton
> Suppose I have a string in $str, I want to extract > some part of it based on regex and store it in the > same string. how do I do that? > > say... > > $str=~ $str /\d\d\s*$/; ($str) = $str =~ /(\d\d)\s*$; # Takes last two digits # off end of string Jonathan

RE: a very simple question

2002-01-29 Thread RArul
Tanton: I am sure we could do it in one step as this: $str =~ s/(\d\d\s*)$/$1; Right? -- Rex > -Original Message- > From: Tanton Gibbs [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, January 29, 2002 4:18 PM > To: Dhiraj P Nilange; [EMAIL PROTECTED] > Subject: Re

Re: a very simple question

2002-01-29 Thread Tanton Gibbs
Just put the part you want to extract in parentheses and then set $str equal to $1...for example: $str =~ /(\d\d\s*)$/; $str = $1; - Original Message - From: "Dhiraj P Nilange" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, January 29, 2002 4:12 PM Subject: a very simple quest