Strings

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
FJRussonc [ Mi, 18 Januar 2006 22:57 ] [ ID #1147538 ]

Re: Strings

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
Paul Lalli [ Mi, 18 Januar 2006 23:52 ] [ ID #1147539 ]

Re: Strings

On Wed, 18 Jan 2006 21:57:59 GMT, "Frank J. Russo"
<FJRussonc [at] earthlink.net> 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?
>
>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+$//;
}
Fred [ So, 22 Januar 2006 01:48 ] [ ID #1153463 ]

Re: Strings

On 2006-01-22, Fred [at] fred.net <Fred [at] fred.net> wrote:
>
> 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 [ So, 22 Januar 2006 02:18 ] [ ID #1153464 ]

Re: Strings

Justin C wrote:
> On 2006-01-22, Fred [at] fred.net <Fred [at] fred.net> wrote:
>>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
Joe Smith [ So, 22 Januar 2006 09:17 ] [ ID #1153465 ]

Re: Strings

<Fred [at] fred.net> wrote in message
news:gok5t1d8h32founq90fn4u6pjsc6uua1u9 [at] 4ax.com...
> On Wed, 18 Jan 2006 21:57:59 GMT, "Frank J. Russo"
> <FJRussonc [at] earthlink.net> 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?
>>
>>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
Matt Garrish [ So, 22 Januar 2006 16:22 ] [ ID #1153466 ]

Re: Strings

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 [ So, 05 Februar 2006 19:17 ] [ ID #1173825 ]

Re: Strings

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 [ Mo, 06 Februar 2006 14:42 ] [ ID #1175561 ]

Re: Strings

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 [ Do, 23 Februar 2006 21:49 ] [ ID #1201898 ]

Re: Strings

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
Paul Lalli [ Fr, 24 Februar 2006 14:57 ] [ ID #1203409 ]
Perl » alt.perl » Strings

Vorheriges Thema: Needed Regular Expression
Nächstes Thema: need some help here