[19364] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1559 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 18 11:10:31 2001

Date: Sat, 18 Aug 2001 08:10:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <998147413-v10-i1559@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 18 Aug 2001     Volume: 10 Number: 1559

Today's topics:
        Removing all white space from a string <killspam@redyonder.co.uk>
    Re: Removing all white space from a string <killspam@redyonder.co.uk>
    Re: Removing all white space from a string <Tassilo.Parseval@post.rwth-aachen.de>
    Re: Removing all white space from a string <Tassilo.Parseval@post.rwth-aachen.de>
    Re: Removing all white space from a string <godzilla@stomp.stomp.tokyo>
    Re: Removing all white space from a string <james@zephyr.org.uk>
    Re: Removing all white space from a string <Tassilo.Parseval@post.rwth-aachen.de>
    Re: Removing all white space from a string <pne-news-20010818@newton.digitalspace.net>
    Re: Removing all white space from a string <killspam@redyonder.co.uk>
    Re: Removing all white space from a string <Tassilo.Parseval@post.rwth-aachen.de>
    Re: Removing all white space from a string <ilya@martynov.org>
    Re: Removing all white space from a string <Tassilo.Parseval@post.rwth-aachen.de>
    Re: Update: (Perl) programming contest loosely based on <tsee@gmx.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sat, 18 Aug 2001 11:14:27 GMT
From: "Alan Farrington" <killspam@redyonder.co.uk>
Subject: Removing all white space from a string
Message-Id: <n6sf7.12358$EV3.956899@news1.cableinet.net>

Hi

I wonder if anyone could tell me if it is possible to remove all white space
from a string i.e. not just the ends but also any in the middle?

What I am attempting to do is compare two perl variables (one from a file
the other looked up in a database) to see if they match. I will change all
the letters to lower case but in case the values have been entered slightly
differently i.e. additional spaces I want to remove all white space.

Cheers

Alan

--
To reply change red to blue.
alan_farrington@redyonder.co.uk




------------------------------

Date: Sat, 18 Aug 2001 12:03:21 GMT
From: "Alan Farrington" <killspam@redyonder.co.uk>
Subject: Re: Removing all white space from a string
Message-Id: <dQsf7.12663$EV3.988587@news1.cableinet.net>

Forget it found it on Google groups - and having read some of the "spicier"
replies don't shout at me for posting it in the first place.


if, for example, $line = "     blablabla     ";

# globally substitute all white space characters with nothing
$line =~ s/\s//g;

:-)

Alan

--
To reply change red to blue.
alan_farrington@redyonder.co.uk
"Alan Farrington" <killspam@redyonder.co.uk> wrote in message
news:n6sf7.12358$EV3.956899@news1.cableinet.net...
> Hi
>
> I wonder if anyone could tell me if it is possible to remove all white
space
> from a string i.e. not just the ends but also any in the middle?
>
> What I am attempting to do is compare two perl variables (one from a file
> the other looked up in a database) to see if they match. I will change all
> the letters to lower case but in case the values have been entered
slightly
> differently i.e. additional spaces I want to remove all white space.
>
> Cheers
>
> Alan
>
> --
> To reply change red to blue.
> alan_farrington@redyonder.co.uk
>
>




------------------------------

Date: Sat, 18 Aug 2001 14:05:59 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Removing all white space from a string
Message-Id: <3B7E5A27.9090907@post.rwth-aachen.de>

Alan Farrington wrote:
> Hi
> 
> I wonder if anyone could tell me if it is possible to remove all white space
> from a string i.e. not just the ends but also any in the middle?

That's actually extremely simple:

my $n = "  this            is a string       ";
$n =~ s/\s+//g;
print $n;
__END__
thisisastring


Tassilo

-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



------------------------------

Date: Sat, 18 Aug 2001 14:20:04 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Removing all white space from a string
Message-Id: <3B7E5D74.6060305@post.rwth-aachen.de>

James Coupe wrote:
> In message <n6sf7.12358$EV3.956899@news1.cableinet.net>, Alan Farrington
> <killspam@redyonder.co.uk> writes
> 
>>I wonder if anyone could tell me if it is possible to remove all white space
>>
>>from a string i.e. not just the ends but also any in the middle?
> 
> s/\w//g
> 
> ?


ethan@ethan: ~$ perl
$n = "  this is  a string   ";
$n =~ s/\w//g;
print $n;
^D
          ethan@ethan:~$

Hmmh....try again!

Tassilo

-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



------------------------------

Date: Sat, 18 Aug 2001 05:37:22 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Removing all white space from a string
Message-Id: <3B7E6182.7F193FF1@stomp.stomp.tokyo>

Alan Farrington wrote:

(snipped)

> I wonder if anyone could tell me if it is possible to remove all white space
> from a string i.e. not just the ends but also any in the middle?

Why do you believe this to possibly be, not possible?

You could learn how to do this within five minutes
via available resources on our internet. It is more
appropriate and more beneficial to do your homework
rather than seek simple solutions from others.

Should you elect to motivate yourself into taking
care of your own homework and, do your homework
with adequacy, you will discover use of Perl's
transliteration function for this will be a
most quick and, a most efficient methodology.

 
Godzilla!


------------------------------

Date: Sat, 18 Aug 2001 13:41:31 +0100
From: James Coupe <james@zephyr.org.uk>
Subject: Re: Removing all white space from a string
Message-Id: <zpZsndJ7Jmf7EwoI@gratiano.zephyr.org.uk>

In message <3B7E5D74.6060305@post.rwth-aachen.de>, Tassilo von Parseval
<Tassilo.Parseval@post.rwth-aachen.de> writes
>Hmmh....try again!

A typo, and the message was (as a result) cancelled.

-- 
James Coupe                                                PGP Key: 0x5D623D5D
Close your eyes so you don't feel them                           EBD690ECD7A1F
They don't need to see you cry                                   B457CA213D7E6
I can't promise I will heal you, but if you want to I will try  68C3695D623D5D


------------------------------

Date: Sat, 18 Aug 2001 15:29:06 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Removing all white space from a string
Message-Id: <3B7E6DA2.3000501@post.rwth-aachen.de>

James Coupe wrote:

> In message <3B7E5D74.6060305@post.rwth-aachen.de>, Tassilo von Parseval
> <Tassilo.Parseval@post.rwth-aachen.de> writes
> 
>>Hmmh....try again!
>>
> 
> A typo, and the message was (as a result) cancelled.

Ah, sorry....I was too quick with my reply. :-)
I'll cancel mine as well then.


Tassilo


-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



------------------------------

Date: Sat, 18 Aug 2001 15:56:53 +0200
From: Philip Newton <pne-news-20010818@newton.digitalspace.net>
Subject: Re: Removing all white space from a string
Message-Id: <4vssnt4opg5nd74idvk7p2p3kpg1pe5icg@4ax.com>

On Sat, 18 Aug 2001 12:03:21 GMT, "Alan Farrington"
<killspam@redyonder.co.uk> top-posted full-quoted:

> # globally substitute all white space characters with nothing
> $line =~ s/\s//g;

s/\s+//g should be faster -- then you won't replace every single space
with nothing but can replace whole stretches of whitespace at a go. (But
what you *shouldn't* do is use s/\s*//g.)

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


------------------------------

Date: Sat, 18 Aug 2001 14:10:25 GMT
From: "Alan Farrington" <killspam@redyonder.co.uk>
Subject: Re: Removing all white space from a string
Message-Id: <lHuf7.13808$EV3.1053832@news1.cableinet.net>


> You could learn how to do this within five minutes
> via available resources on our internet. It is more
> appropriate and more beneficial to do your homework
> rather than seek simple solutions from others.
>
> Should you elect to motivate yourself into taking
> care of your own homework and, do your homework
> with adequacy, you will discover use of Perl's
> transliteration function for this will be a
> most quick and, a most efficient methodology.


and my second posting, sent half an hour before you posting says .....

"Forget it found it on Google groups - and having read some of the "spicier"
replies don't shout at me for posting it in the first place."

Alan

(trying to run before he can walk)




------------------------------

Date: Sat, 18 Aug 2001 16:15:03 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Removing all white space from a string
Message-Id: <3B7E7867.1070901@post.rwth-aachen.de>

Alan Farrington wrote:

>>You could learn how to do this within five minutes
>>via available resources on our internet. It is more
>>appropriate and more beneficial to do your homework
>>rather than seek simple solutions from others.
>>
>>Should you elect to motivate yourself into taking
>>care of your own homework and, do your homework
>>with adequacy, you will discover use of Perl's
>>transliteration function for this will be a
>>most quick and, a most efficient methodology.
>>
> 
> 
> and my second posting, sent half an hour before you posting says .....
> 
> "Forget it found it on Google groups - and having read some of the "spicier"
> replies don't shout at me for posting it in the first place."

Don't worry about Godzilla and never let yourself be pissed off by her. 
In this group it is generally considered a good thing to not pay 
attention to her insultings.

PS: If you replace \s with \s+ in the regex you have found, you make it 
quicker. I just benchmarked it. After 200000 iterations, it has been 
about 38% quicker.


Tassilo
-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



------------------------------

Date: 18 Aug 2001 18:20:05 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Removing all white space from a string
Message-Id: <87bsldo3fu.fsf@abra.ru>


TvP> Don't worry about Godzilla and never let yourself be pissed off by
TvP> her. In this group it is generally considered a good thing to not pay
TvP> attention to her insultings.

What good about Godzilla is that she forced me to study how setup
scoring and kill lists in my newsreader :)

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


------------------------------

Date: Sat, 18 Aug 2001 16:56:17 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Removing all white space from a string
Message-Id: <3B7E8211.7080907@post.rwth-aachen.de>

Ilya Martynov wrote:

> What good about Godzilla is that she forced me to study how setup
> scoring and kill lists in my newsreader :)

I guess I am still in my masochist mood by reading her stuff.
But now you gave me a point to think about. :-)




------------------------------

Date: Sat, 18 Aug 2001 14:23:27 +0200
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: Update: (Perl) programming contest loosely based on the prisoners' dilemma
Message-Id: <9llmhd$eer$06$1@news.t-online.com>

[snipped helpful comments]

Thanks a lot for your input and your showing interest.
I'm still working on the rules and will advertise as you suggested once
they're somewhat complete. Additionally, I will create a simple web page
with infos about the contest.

Right now, I've got a bunch of paying projects but I'm eager to start with
the contest. If anybody would like to get involved in the development of the
project (as thinker, coder, webmaster, whatever) and would like to be part
of a mailing list on this topic, please send me an email.

Steffen






------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 1559
***************************************


home help back first fref pref prev next nref lref last post