/^\<|\>$|\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
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
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
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
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
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
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
> 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?
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 {
>
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
> 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
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 {
> >
> 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
> > 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 {
> >
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
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/^
> > 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 {
>
>
> 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];
>
> 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/^\<
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
20 matches
Mail list logo