> 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/^\<|\>$|\n|\r|\s$//g;
> > }
> >
> > I tried using parenthesis and using list context ::
> > return my($q) = $_[0] =~ s/(^\<|\>$|\n|\r|\s$)//g; }
> >
> > And you might have figured it returned the number of
> elements matched
> > and not the newly fixed up variable contentes.
> >
> > Is there a way to do this?
> > I know I must be missing something obvious , thanks for any
> guidance!
>
> Hi Dan.
>
> How about:
>
> sub rmgtlt { $_[0] =~ s/^\<|\>$|\n|\r|\s$//g; return $_[0]; }
Ha Ha ! That is a good one, perl humor gotta love it.
>
> ;-D
>
> Seriously though, there's no way to do it apart from
> something like that since, as you've discovered, the
> substitute operator returns the number of substitutions it
> has performed - the modified string isn't available without
> using it explicitly. You can make it a little smaller though:
> the regex could be slightly shorter and the 'return' is
> unnecessary on the last line of the routine.
>
> sub rmgtlt { $_[0] =~ s/^<|[\n\r]|[>\s]$//g; $_[0] }
>
> Did you realise though, that since the substitution is
> changing the element of the @_ array, the actual parameter in
> the call will be modified, so that
>
> my $email = '<[EMAIL PROTECTED]>';
> rmgtlt ($email);
>
> will edit $email for you? There's no need to do
>
> $email = rmgtlt ($email);
>
> as you may be thinking. Also, the parameter must be an
> lvalue. If you call the routine with a constant string as its
> parameter it will fail because the substitution cannot be
> done on a constant.
Ah yes, I can see that, thank you for for that info, I was just doing a
perldoc -f return so that all seals the deal for me then.
Thanks everyone for your time.
Dan
>
> HTH,
>
> Rob
>
>
>
>
> --
> 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]