Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   matching only white space (http://www.velocityreviews.com/forums/t884602-matching-only-white-space.html)

Robin 01-14-2004 01:06 AM

matching only white space
 
I dunno, would this match only white space: / */ . ... ?
or would it match somethin else with the white space?

--
Regards,
Robin
--
robin@csf.edu
--




A. Sinan Unur 01-14-2004 01:17 AM

Re: matching only white space
 
"Robin" <robin@csf.edu> wrote in news:bu25j2$uqk$1@reader2.nmix.net:

> I dunno, would this match only white space: / */ . ... ?
> or would it match somethin else with the white space?


What happened when you tried it?

use strict;
use warnings;

my @strings = (' ', ' another', 'another one', 'o n e m o r e');

for (@strings) {
print "$_: matched\n" if / */;
}

If you want to match a line containing nothing but whitespace, then say so:

print "$_: matched\n" if /^\s*$/;

Feel free to read the docs: perldoc perlre

Sinan.

--
A. Sinan Unur
1usa@llenroc.ude (reverse each component for email address)

Robin 01-14-2004 01:23 AM

Re: matching only white space
 

> > I dunno, would this match only white space: / */ . ... ?
> > or would it match somethin else with the white space?

>
> What happened when you tried it?
>
> use strict;
> use warnings;
>
> my @strings = (' ', ' another', 'another one', 'o n e m o r e');
>
> for (@strings) {
> print "$_: matched\n" if / */;
> }


Thanks, that's all I needed to know, I'll have to read that perldoc...
peace,
-Robin



Robin 01-14-2004 01:24 AM

Re: matching only white space + site
 
I suppose I'll just skip doing that site, I don't quite have ADD, although
I'm still working on it, check out the beginning of the site anyway...
http://www.reachcac.org/robin/perl/index.html is it still too official to
say "a homepage"? If anyone is interested in co-designing it or posting
tutorials/scripts, let me know...

-Thanks,
Robin

PS. I don't like being killfiled and flamed, just trying to help a starving
newsgroup :-), yeah, right...





Sherm Pendley 01-14-2004 01:27 AM

Re: matching only white space
 
On Tue, 13 Jan 2004 18:06:32 -0700, Robin wrote:

> I dunno, would this match only white space: / */ . ... ?
> or would it match somethin else with the white space?


No. It matches zero or more occurences of a space character. To match
white space, use \s, which includes tabs, newlines, and other characters
along with literal space characters.

See also:

perldoc perlretut

It occurs to me that you've often been told "perldoc this", but may not
have been told what "perldoc" is...

"perldoc" is a utility that's used to view the documentation that's
bundled with Perl. To use it, open up a terminal window and type "perldoc
whatever". Some good places to start are "perldoc perlfaq", "perldoc
perl", and "perldoc intro". The same documentation can also be found in
HTML format at <http://www.perldoc.com>.

I *think* perldoc is available on WinDOS systems too, but I don't have one
handy to check.

sherm--

Jürgen Exner 01-14-2004 01:29 AM

Re: matching only white space
 
Robin wrote:
> I dunno, would this match only white space: / */ . ... ?
> or would it match somethin else with the white space?


Why do you think a plain blank character would match any arbitrary white
space?
If you want to match white space then say so
/\s*/

For further details please Read The Fine Manual: perldoc perlre

jue



Marc Bissonnette 01-14-2004 02:21 AM

Re: matching only white space
 
Sherm Pendley <spamtrap@dot-app.org> wrote in
news:pan.2004.01.14.01.27.37.295091@dot-app.org:

> On Tue, 13 Jan 2004 18:06:32 -0700, Robin wrote:
>
>> I dunno, would this match only white space: / */ . ... ?
>> or would it match somethin else with the white space?

>
> No. It matches zero or more occurences of a space character. To match
> white space, use \s, which includes tabs, newlines, and other
> characters along with literal space characters.
>
> See also:
>
> perldoc perlretut
>
> It occurs to me that you've often been told "perldoc this", but may
> not have been told what "perldoc" is...
>
> "perldoc" is a utility that's used to view the documentation that's
> bundled with Perl. To use it, open up a terminal window and type
> "perldoc whatever". Some good places to start are "perldoc perlfaq",
> "perldoc perl", and "perldoc intro". The same documentation can also
> be found in HTML format at <http://www.perldoc.com>.
>
> I *think* perldoc is available on WinDOS systems too, but I don't have
> one handy to check.


Yup, I've got ActiveState perl (build 807) on an WinXP box and the
perldoc functions fine in a dos window.

If (s)he finds it inconvenient to read the perldocs in the dos window,
perldoc whatever >whatever.txt
dumps the output of the 'perldoc whatever' into whatever.txt for printing
/ bathroom reading / etc.


--
Marc Bissonnette
CGI / Database / Web Management Tools: http://www.internalysis.com
Something To Sell? Looking To Buy? http://www.whitewaterclassifieds.ca
Looking for a new ISP? http://www.canadianisp.com

A. Sinan Unur 01-14-2004 03:01 AM

Re: matching only white space
 
Marc Bissonnette <dragnet@internalysis.com> wrote in
news:Xns946FD948EEE96dragnetinternalysisc@207.35.1 77.135:

> Sherm Pendley <spamtrap@dot-app.org> wrote in
> news:pan.2004.01.14.01.27.37.295091@dot-app.org:
>
>> On Tue, 13 Jan 2004 18:06:32 -0700, Robin wrote:
>>
>>> I dunno, would this match only white space: / */ . ... ?
>>> or would it match somethin else with the white space?


....

>> perldoc perlretut
>>
>> It occurs to me that you've often been told "perldoc this", but may
>> not have been told what "perldoc" is...


....

>> I *think* perldoc is available on WinDOS systems too, but I don't
>> have one handy to check.


....

> If (s)he finds it inconvenient to read the perldocs in the dos window,
> perldoc whatever >whatever.txt
> dumps the output of the 'perldoc whatever' into whatever.txt for
> printing / bathroom reading / etc.


There is also HTML documentation, you know:

C:\Perl\html\perltoc.html

Change C:\Perl to the directory where Perl is installed.

--
A. Sinan Unur
1usa@llenroc.ude (reverse each component for email address)

Matt Garrish 01-14-2004 03:43 AM

Re: matching only white space
 

"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:JX0Nb.10544$et1.3811@nwrddc03.gnilink.net...
> Robin wrote:
> > I dunno, would this match only white space: / */ . ... ?
> > or would it match somethin else with the white space?

>
> Why do you think a plain blank character would match any arbitrary white
> space?
> If you want to match white space then say so
> /\s*/
>
> For further details please Read The Fine Manual: perldoc perlre
>


Everyone seems to be missing a fundemental point about optional content:

my $line = 'IHAVENOWHITESPACE';

if ($line =~ /\s*/) {
print "D'oh!";
}


Matt



Matt Garrish 01-14-2004 03:43 AM

Re: matching only white space
 

"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:JX0Nb.10544$et1.3811@nwrddc03.gnilink.net...
> Robin wrote:
> > I dunno, would this match only white space: / */ . ... ?
> > or would it match somethin else with the white space?

>
> Why do you think a plain blank character would match any arbitrary white
> space?
> If you want to match white space then say so
> /\s*/
>
> For further details please Read The Fine Manual: perldoc perlre
>


Everyone seems to be missing a fundemental point about optional content:

my $line = 'IHAVENOWHITESPACE';

if ($line =~ /\s*/) {
print "D'oh!";
}


Matt




All times are GMT. The time now is 01:52 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57