RE: return a regex substitution in one line

2003-03-11 Thread Dan Muey
/^\<|\>$|\n|\r|\s$//g ? return $_[0] : return $_[0]; } sub d { $_[0] =~ s/^\<|\>$|\n|\r|\s$//g;return $_[0]; } sub e { $_[0] =~ s/^\<|\>$|\n|\r|\s$//g,$_[0]; } Thanks Dan > -Original Message- > From: david [mailto:[EMAIL PROTECTED] > Sent: Tuesday, March 11, 2

RE: return a regex substitution in one line

2003-03-11 Thread david
Dan Muey wrote: > Thanks again everyone for the replies. If any one casre here's some > benchmark info I found out about our discussion :: > > Intersting what i found. If the sting is simple they're about even. > If the string is complicated( has more matches/substitutions) it takes a > and b t

Re: return a regex substitution in one line

2003-03-11 Thread david
Dan Muey wrote: > I have this subroutine and it does what I need :: > > print rmgtlt($var); > > sub rmgtlt { > > $_[0] =~ s/^\<|\>$|\n|\r|\s$//g; > return $_[0]; > } > try: #!/usr/bin/perl -w use strict; sub rmgtlt{ $_[0] =~ s/^\<|\>$|\n|\r|\s$//g,$_[0]; } my $s = ""; print scalar

RE: return a regex substitution in one line

2003-03-11 Thread Dan Muey
Thanks again everyone for the replies. If any one casre here's some benchmark info I found out about our discussion :: Intersting what i found. If the sting is simple they're about even. If the string is complicated( has more matches/substitutions) it takes a and b the same ( probably due to h

Re: return a regex substitution in one line

2003-03-11 Thread Rob Dixon
David Olbersen wrote: > Dan, > > return ($_[0] =~ s/^\<|\>$|\n|\r|\s$//g)[0]; > > ? Sorry David. Unlike m//, s// only ever returns the number of substitutions, regardless of context, capturing braces or the /g modifier. You can get the captured strings in $1 etc., but only from the last occurrence

Re: return a regex substitution in one line

2003-03-11 Thread Rob Dixon
Mark Anderson wrote: > > > > Is there a way to so the substitution and return the result in one > > line? > > > > Like :: > > > > sub rmgtlt { > > return ??? $_[0] =~ s/^\<|\>$|\n|\r|\s$//g; > > } > > > > Without more comments or sample data, I'm not really sure what your > function is doing, but h

Re: return a regex substitution in one line

2003-03-11 Thread John W. Krahn
Dan Muey wrote: > > > > sub rmgtlt { join '', split /^<|>$|\n|\r|\s$/, $_[0] } > > Ooohh that works! > > Now that prompts a few other questions : > 1) It works with and with out a semi colon behind $_[0], why and which one is better? The semicolon is optional, neither way is "better". > 2) Is t

RE: return a regex substitution in one line

2003-03-11 Thread Dan Muey
> Dan Muey wrote: > > > > I have this subroutine and it does what I need :: > > > > print rmgtlt($var); > > > > sub rmgtlt { > > > > $_[0] =~ s/^\<|\>$|\n|\r|\s$//g; > > return $_[0]; > > } > > > > Is there a way to so the substitution and return the result in one > > line?

Re: return a regex substitution in one line

2003-03-11 Thread John W. Krahn
Dan Muey wrote: > > I have this subroutine and it does what I need :: > > print rmgtlt($var); > > sub rmgtlt { > > $_[0] =~ s/^\<|\>$|\n|\r|\s$//g; > return $_[0]; > } > > Is there a way to so the substitution and return the result in one line? > > Like :: > > sub rmgtlt { >

RE: return a regex substitution in one line

2003-03-11 Thread Dan Muey
Olbersen > iGuard Engineer > 11415 West Bernardo Court > San Diego, CA 92127 > 1-858-676-2277 x2152 > > > > -Original Message- > > From: Dan Muey [mailto:[EMAIL PROTECTED] > > Sent: Tuesday, March 11, 2003 9:51 AM > > To: Mark Anderson; [EMAIL

RE: return a regex substitution in one line

2003-03-11 Thread Dan Muey
> Dan, > > I can do it in one line. But I'm not convinced it's the > "right" way to do it; i.e. it seems like it's cheating: > > sub rmgtlt { > $_[0] =~ s/^\<|\>$|\n|\r|\s$//g ? return $_[0] : return $_[0]; } > > There's got to be a better way that doesn't use this > if-then-else appr

RE: return a regex substitution in one line

2003-03-11 Thread David Olbersen
1, 2003 9:51 AM > To: Mark Anderson; [EMAIL PROTECTED] > Subject: RE: return a regex substitution in one line > > > > > > I have this subroutine and it does what I need :: > > > > > > print rmgtlt($var); > > > > > > sub rmgtlt { > >

RE: return a regex substitution in one line

2003-03-11 Thread Dan Muey
> Dan Muey wrote: > > I have this subroutine and it does what I need :: > > > > print rmgtlt($var); > > > > sub rmgtlt { > > > > $_[0] =~ s/^\<|\>$|\n|\r|\s$//g; > > return $_[0]; > > } > > > > Is there a way to so the substitution and return the result in one > > line? > > > > Like :: > > > > sub

RE: return a regex substitution in one line

2003-03-11 Thread Dan Muey
> > I have this subroutine and it does what I need :: > > > > print rmgtlt($var); > > > > sub rmgtlt { > > $_[0] =~ s/^\<|\>$|\n|\r|\s$//g; > > return $_[0]; > > } > > > > Is there a way to so the substitution and return the result in one > > line? > > > > Like :: > > > > sub rmgtlt { > >

RE: return a regex substitution in one line

2003-03-11 Thread Pete Emerson
Dan, I can do it in one line. But I'm not convinced it's the "right" way to do it; i.e. it seems like it's cheating: sub rmgtlt { $_[0] =~ s/^\<|\>$|\n|\r|\s$//g ? return $_[0] : return $_[0]; } There's got to be a better way that doesn't use this if-then-else approach. I'd vote for keepi

Re: return a regex substitution in one line

2003-03-11 Thread Rob Dixon
Dan Muey wrote: > I have this subroutine and it does what I need :: > > print rmgtlt($var); > > sub rmgtlt { > > $_[0] =~ s/^\<|\>$|\n|\r|\s$//g; > return $_[0]; > } > > Is there a way to so the substitution and return the result in one > line? > > Like :: > > sub rmgtlt { > return ??? $_[0] =~ s/^

RE: return a regex substitution in one line

2003-03-11 Thread Dan Muey
> > I have this subroutine and it does what I need :: > > > > print rmgtlt($var); > > > > sub rmgtlt { > > $_[0] =~ s/^\<|\>$|\n|\r|\s$//g; > > return $_[0]; > > } > > > > Is there a way to so the substitution and return the result in one > > line? > > > > Like :: > > > > sub rmgtlt { >

RE: return a regex substitution in one line

2003-03-11 Thread Dan Muey
> > Dan, > > Maybe you want to do a series of smaller regexes, rather than > one large one? No it was a series of smaller ones. I want to do a one liner ** > > For example: > > sub rmgtlt { > $_[0] =~ s/^\<|\>$//g; > $_[0] =~ s/[\n\r]//$g; > $_[0] =~ s/\s$//g; > > return $_[0]; >

RE: return a regex substitution in one line

2003-03-11 Thread Mark Anderson
> I have this subroutine and it does what I need :: > > print rmgtlt($var); > > sub rmgtlt { > $_[0] =~ s/^\<|\>$|\n|\r|\s$//g; > return $_[0]; > } > > Is there a way to so the substitution and return the result in one line? > > Like :: > > sub rmgtlt { > return ??? $_[0] =~ s/^\<

RE: return a regex substitution in one line

2003-03-11 Thread David Olbersen
Dan, Maybe you want to do a series of smaller regexes, rather than one large one? For example: sub rmgtlt { $_[0] =~ s/^\<|\>$//g; $_[0] =~ s/[\n\r]//$g; $_[0] =~ s/\s$//g; return $_[0]; } Just a thought that might make it more clear where the problem is. Also, what do you mean by "on