Z
ZZT
Hi,
is there a way to shorten this expression?
$host=~/^(\S*)\s*/; $host=$1;
thanks!
is there a way to shorten this expression?
$host=~/^(\S*)\s*/; $host=$1;
thanks!
is there a way to shorten this expression?
$host=~/^(\S*)\s*/; $host=$1;
$host=~s/\s.*//;
$host =~ s/\s+$//;
That won't remove a trailing newline, which WILL be a problem. Even if
there's nothing after the newline, the original code will give you a
string with NO WHITESPACE at all; yours will keep a newline at the end of
$host.
Either add the /s modifier to the substitution, or take a different
approach like
($host) = $host =~ /(\S*)/;
several ways but how aboutZZT said:Hi,
is there a way to shorten this expression?
$host=~/^(\S*)\s*/; $host=$1;
thanks!
several ways but how about
$host=~s/\s+.+//;
or
($host)=$host=~/^(\S*)\s*/;
Jeff 'japhy' Pinyan ([email protected]) wrote on MMMDCV September MCMXCIII
in <URL) On Tue, 15 Jul 2003, ZZT wrote:
))
)) >is there a way to shorten this expression?
)) >
)) >$host=~/^(\S*)\s*/; $host=$1;
))
)) Well, as it stands, even if the regex FAILS, $host will be set to whatever
)) $1 was before the regex.
But the only string on which the regexp can fail is a string that
doesn't have a beginning. Now, in perl6, with lazy evaluation, we
might be able to construct strings without an end.
But how do I make a string without a beginning?
Abigail said:Jeff 'japhy' Pinyan ([email protected]) wrote on MMMDCV September MCMXCIII
in
<URL) On Tue, 15 Jul 2003, ZZT wrote:
))
)) >is there a way to shorten this expression?
)) >
)) >$host=~/^(\S*)\s*/; $host=$1;
))
)) Well, as it stands, even if the regex FAILS, $host will be set to
whatever
)) $1 was before the regex.
But the only string on which the regexp can fail is a string that
doesn't have a beginning. Now, in perl6, with lazy evaluation, we
might be able to construct strings without an end.
But how do I make a string without a beginning?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.