Strings
am 18.01.2006 22:57:59 von FJRussoncI am comparing 2 strings. One might have leading spaces in it. How do you
recommend I remove the leading spaces? Or got a better idea?
Frank
NC
I am comparing 2 strings. One might have leading spaces in it. How do you
recommend I remove the leading spaces? Or got a better idea?
Frank
NC
Frank J. Russo wrote:
> I am comparing 2 strings. One might have leading spaces in it. How do you
> recommend I remove the leading spaces? Or got a better idea?
I recommend the same way suggested in the FAQ.
perldoc -q space
"How do I strip blank space from the beginning/end of a string?"
Please make an *attempt* at helping yourself before asking thousands of
people around the world to read the documentation to you.
Paul Lalli
On Wed, 18 Jan 2006 21:57:59 GMT, "Frank J. Russo"
>I am comparing 2 strings. One might have leading spaces in it. How do you
>recommend I remove the leading spaces? Or got a better idea?
>
>Frank
>NC
>
I do apologize for the likely absurdly rude replies you will get to
this post. You asked a fair question. It's not every programming
language that has a peculiar system of documentation that features
assorted bad examples, wandering topics and other unprofessional
characteristics such as a very unreliable way to find out about a
question without having to first learn yet another dialect of BS. (The
help system for perl.aka perldoc)
The fact is there are MUCH BETTER resources for perl on the (HTML) net
than about anywhere. There isn't anything more than a bunch of horses
asses here.
(Go to Google. Try searching 'perl' )
As such, please allow me answer your post and provide the "built-in"
documentation (That for you would have been a separate subject of
study to engage.) and the answers to the questions you posed.
Fred.
PS. Rest of 'yall go straight to hell.
C:\>perldoc -q space
Found in C:\Perl\lib\pod\perlfaq4.pod
How do I strip blank space from the beginning/end of a string?
Although the simplest approach would seem to be
$string =~ s/^\s*(.*?)\s*$/$1/;
not only is this unnecessarily slow and destructive, it also fails
with embedded newlines. It is much faster to do this operation in two
steps:
$string =~ s/^\s+//;
$string =~ s/\s+$//;
Or more nicely written as:
for ($string) {
s/^\s+//;
s/\s+$//;
}
On 2006-01-22, Fred@fred.net
>
> C:\>perldoc -q space
Please, Sir, what does C:\> mean?
I understand that you are "escaping" the greater-than sign but I don't
understand the "C colon" part of the command.... Oh, the "perldoc -q" is
more than straight forward.
Thank you for your reply.
Justin.
--
Justin C, by the sea.
Justin C wrote:
> On 2006-01-22, Fred@fred.net
>>C:\>perldoc -q space
>
> Please, Sir, what does C:\> mean?
I can't tell if you're being sarcastic, or just plain ________.
bash-2.05$ perldoc -q space
news:gok5t1d8h32founq90fn4u6pjsc6uua1u9@4ax.com...
> On Wed, 18 Jan 2006 21:57:59 GMT, "Frank J. Russo"
>
>
>>I am comparing 2 strings. One might have leading spaces in it. How do
>>you
>>recommend I remove the leading spaces? Or got a better idea?
>>
>>Frank
>>NC
>>
>
>
> I do apologize for the likely absurdly rude replies you will get to
> this post. You asked a fair question. It's not every programming
> language that has a peculiar system of documentation that features
> assorted bad examples, wandering topics and other unprofessional
> characteristics such as a very unreliable way to find out about a
> question without having to first learn yet another dialect of BS. (The
> help system for perl.aka perldoc)
> The fact is there are MUCH BETTER resources for perl on the (HTML) net
> than about anywhere. There isn't anything more than a bunch of horses
> asses here.
>
> (Go to Google. Try searching 'perl' )
>
> As such, please allow me answer your post and provide the "built-in"
> documentation (That for you would have been a separate subject of
> study to engage.) and the answers to the questions you posed.
>
Well, look who came back to cry again! What's wrong now, mommy didn't change
your diapers?
If your knowledge of perl were sound - which it obviously isn't - you would
have discovered by now that the html documentation is installed on your hard
drive. You might also know that it's faster to get faq answers using perldoc
than it is to look them up in an html page.
But since you like Google so much, perhaps you might want to use it to look
up the meaning of the word hypocrisy as it relates to your silly postings.
Matt
Frank J. Russo wrote:
> I am comparing 2 strings. One might have leading spaces in it. How do you
> recommend I remove the leading spaces? Or got a better idea?
# remove leading and trailing spaces
$s =~ s/(^\s+|\s+$)//g;
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Rich wrote:
> Frank J. Russo wrote:
> > I am comparing 2 strings. One might have leading spaces in it. How do you
> > recommend I remove the leading spaces? Or got a better idea?
>
> # remove leading and trailing spaces
> $s =~ s/(^\s+|\s+$)//g;
If you're going to respond to a 2-week old thread, you could at least
have the decency to *read* the thread first. If you had, you would
have seen the FAQ that was pointed to by pretty much every responder,
and you would have read why you should *NOT* do what you just typed.
Paul Lalli
Paul Lalli wrote:
> Rich wrote:
>
>>Frank J. Russo wrote:
>>
>>>I am comparing 2 strings. One might have leading spaces in it. How do you
>>>recommend I remove the leading spaces? Or got a better idea?
>>
>> # remove leading and trailing spaces
>> $s =~ s/(^\s+|\s+$)//g;
>
>
> If you're going to respond to a 2-week old thread, you could at least
> have the decency to *read* the thread first. If you had, you would
> have seen the FAQ that was pointed to by pretty much every responder,
> and you would have read why you should *NOT* do what you just typed.
>
> Paul Lalli
>
Hmm...
perl -le '$s=" sss\nsss";print $s'
sss
sss
perl -le '$s=" sss\nsss";$s=~s/(^\s+|\s+$)//g;print $s'
sss
sss
This $string =~ s/^\s*(.*?)\s*$/$1/;
is not equivalent to $s =~ s/(^\s+|\s+$)//g;
From the perldoc:
It is much faster to do this operation in two steps:
$string =~ s/^\s+//;
$string =~ s/\s+$//;
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Rich wrote:
> Paul Lalli wrote:
> > Rich wrote:
> >
> >>Frank J. Russo wrote:
> >>
> >>>I am comparing 2 strings. One might have leading spaces in it. How do you
> >>>recommend I remove the leading spaces? Or got a better idea?
> >>
> >> # remove leading and trailing spaces
> >> $s =~ s/(^\s+|\s+$)//g;
> >
> >
> > If you're going to respond to a 2-week old thread, you could at least
> > have the decency to *read* the thread first. If you had, you would
> > have seen the FAQ that was pointed to by pretty much every responder,
> > and you would have read why you should *NOT* do what you just typed.
>
> Hmm...
>
> perl -le '$s=" sss\nsss";print $s'
> sss
> sss
>
>
> perl -le '$s=" sss\nsss";$s=~s/(^\s+|\s+$)//g;print $s'
> sss
> sss
>
>
> This $string =~ s/^\s*(.*?)\s*$/$1/;
> is not equivalent to $s =~ s/(^\s+|\s+$)//g;
I fail to see your point, as no where did I suggest using the first
approach.
> From the perldoc:
>
> It is much faster to do this operation in two steps:
>
> $string =~ s/^\s+//;
> $string =~ s/\s+$//;
Exactly. Do it in two steps. Not the one step you recommended.
Paul Lalli