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
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;
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];
}
Just a
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] =~
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;
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 keeping
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] =~
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] =~
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 {
$_[0] =~ s/^\|\$|\n|\r|\s$//g;
return $_[0];
}
Is there a way to so the substitution
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
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 PROTECTED]
Subject: RE: return a regex substitution in one line
I have this subroutine and it does what I
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 ???
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
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 that the same
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 here are some things to
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 of
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
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 = abcd;
print scalar
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 the
|\r|\s$//g,$_[0]; }
Thanks
Dan
-Original Message-
From: david [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 11, 2003 4:15 PM
To: [EMAIL PROTECTED]
Subject: RE: return a regex substitution in one line
Dan Muey wrote:
Thanks again everyone for the replies. If any one casre
20 matches
Mail list logo