matching only white space

Discussion in 'Perl Misc' started by Robin, Jan 14, 2004.

  1. Robin

    Robin Guest

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

    --
    Regards,
    Robin
    --

    --
     
    Robin, Jan 14, 2004
    #1
    1. Advertising

  2. "Robin" <> wrote in news:bu25j2$uqk$:

    > 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
    (reverse each component for email address)
     
    A. Sinan Unur, Jan 14, 2004
    #2
    1. Advertising

  3. Robin

    Robin Guest


    > > 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, Jan 14, 2004
    #3
  4. Robin

    Robin Guest

    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...
     
    Robin, Jan 14, 2004
    #4
  5. 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--
     
    Sherm Pendley, Jan 14, 2004
    #5
  6. 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
     
    Jürgen Exner, Jan 14, 2004
    #6
  7. Sherm Pendley <> wrote in
    news:p:

    > 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
     
    Marc Bissonnette, Jan 14, 2004
    #7
  8. Marc Bissonnette <> wrote in
    news:Xns946FD948EEE96dragnetinternalysisc@207.35.177.135:

    > Sherm Pendley <> wrote in
    > news:p:
    >
    >> 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
    (reverse each component for email address)
     
    A. Sinan Unur, Jan 14, 2004
    #8
  9. Robin

    Matt Garrish Guest

    "Jürgen Exner" <> wrote in message
    news:JX0Nb.10544$...
    > 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, Jan 14, 2004
    #9
  10. Robin

    Matt Garrish Guest

    "Jürgen Exner" <> wrote in message
    news:JX0Nb.10544$...
    > 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, Jan 14, 2004
    #10
  11. Robin

    Matt Garrish Guest

    My apologies for the duplicate posting. My news server crapped out while I
    was trying to send, but seems to have sent the first copy anyway...

    Matt
     
    Matt Garrish, Jan 14, 2004
    #11
  12. Robin <> wrote:

    > I dunno, would this match only white space: / */ . ... ?



    What happened when you tried it?


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Jan 14, 2004
    #12
  13. Marc Bissonnette <> wrote:

    > 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.



    Do the pod2* converters (eg: pod2html) work?


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Jan 14, 2004
    #13
  14. Re: matching only white space + site

    Robin <> wrote:

    > PS. I don't like being killfiled and flamed,



    Do you expect folks to remain silent when you take cuts in line?

    That is a pretty unreasonable expectation...


    In article <>,
    (Larry Wall) wrote: ...

    [snip] I view a programming language as a place to be
    explored, like Disneyland. You don't need to have a lot of preparation
    to explore a theme park. You do have to go along with the crowd
    control measures, though. In a sense, each ride has its own
    prerequisites--if you cut in line, you risk getting tossed out of the
    park.

    What we have here in this newsgroup is a failure in crowd control.
    Reading the FAQ is like staying in line--it's something you should
    learn in kindergarten. Usenet needs a better kindergarten.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Jan 14, 2004
    #14
  15. Robin

    Anno Siegel Guest

    Matt Garrish <> wrote in comp.lang.perl.misc:
    >
    > "Jürgen Exner" <> wrote in message
    > news:JX0Nb.10544$...
    > > 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!";
    > }


    So? It still didn't match anything but spaces.

    Anno
     
    Anno Siegel, Jan 14, 2004
    #15
  16. Robin

    Matt Garrish Guest

    "Anno Siegel" <-berlin.de> wrote in message
    news:bu37e5$3p2$-Berlin.DE...
    > Matt Garrish <> wrote in comp.lang.perl.misc:
    > >
    > > Everyone seems to be missing a fundemental point about optional content:
    > >
    > > my $line = 'IHAVENOWHITESPACE';
    > >
    > > if ($line =~ /\s*/) {
    > > print "D'oh!";
    > > }

    >
    > So? It still didn't match anything but spaces.
    >


    The spaces between spaces, I suppose, but not what the OP wanted to know
    (and not \s solutions that have been posted). Writing a regex with nothing
    but optional content is just pointless in so many ways it boggles my poor
    mind...

    Matt
     
    Matt Garrish, Jan 14, 2004
    #16
  17. Robin

    Anno Siegel Guest

    Matt Garrish <> wrote in comp.lang.perl.misc:
    >
    > "Anno Siegel" <-berlin.de> wrote in message
    > news:bu37e5$3p2$-Berlin.DE...
    > > Matt Garrish <> wrote in comp.lang.perl.misc:
    > > >
    > > > Everyone seems to be missing a fundemental point about optional content:
    > > >
    > > > my $line = 'IHAVENOWHITESPACE';
    > > >
    > > > if ($line =~ /\s*/) {
    > > > print "D'oh!";
    > > > }

    > >
    > > So? It still didn't match anything but spaces.
    > >

    >
    > The spaces between spaces, I suppose, but not what the OP wanted to know
    > (and not \s solutions that have been posted). Writing a regex with nothing
    > but optional content is just pointless in so many ways it boggles my poor
    > mind...


    As a stand-alone regex it wouldn't do much, though with /g it may serve
    a purpose. As part of a larger regex it is perfectly useful.

    I'm not sure what the OPs original question was.

    Anno
     
    Anno Siegel, Jan 14, 2004
    #17
  18. Robin

    Matt Garrish Guest

    "Anno Siegel" <-berlin.de> wrote in message
    news:bu3e60$9r6$-Berlin.DE...
    > Matt Garrish <> wrote in comp.lang.perl.misc:
    > >
    > > The spaces between spaces, I suppose, but not what the OP wanted to know
    > > (and not \s solutions that have been posted). Writing a regex with

    nothing
    > > but optional content is just pointless in so many ways it boggles my

    poor
    > > mind...

    >
    > As a stand-alone regex it wouldn't do much, though with /g it may serve
    > a purpose. As part of a larger regex it is perfectly useful.
    >


    True enough, though I personally can't think of any reason why you would
    want to match/count these "spaces" in a string (but I suppose everything has
    its purpose). length() would be the function most people would be looking
    for, or so I would assume, as a count based on an optional pattern like the
    above will always return the actual length plus one (that pesky "space" at
    the beginning of the string).

    >
    > I'm not sure what the OPs original question was.
    >


    My understanding, at any rate, was that he had stumbled upon the above
    nuance of regexes. In the lingo of today's youth he wrote:

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

    I will be so bold as to suggest that his understanding of whitespace is not
    on par with yours... : )

    Matt
     
    Matt Garrish, Jan 14, 2004
    #18
  19. Robin

    Anno Siegel Guest

    Matt Garrish <> wrote in comp.lang.perl.misc:
    >
    > "Anno Siegel" <-berlin.de> wrote in message
    > news:bu3e60$9r6$-Berlin.DE...
    > > Matt Garrish <> wrote in comp.lang.perl.misc:
    > > >
    > > > The spaces between spaces, I suppose, but not what the OP wanted to know
    > > > (and not \s solutions that have been posted). Writing a regex with

    > nothing
    > > > but optional content is just pointless in so many ways it boggles my

    > poor
    > > > mind...

    > >
    > > As a stand-alone regex it wouldn't do much, though with /g it may serve
    > > a purpose. As part of a larger regex it is perfectly useful.
    > >

    >
    > True enough, though I personally can't think of any reason why you would
    > want to match/count these "spaces" in a string (but I suppose everything has
    > its purpose). length() would be the function most people would be looking
    > for, or so I would assume, as a count based on an optional pattern like the
    > above will always return the actual length plus one (that pesky "space" at
    > the beginning of the string).


    The length? You mean it matches once for every character, and then one
    more? / */ is greedy, it will still match consecutive blanks in one
    go. I wouldn't know how to characterize what it counts in a few words,
    but it's not simply related to string length.

    Anno
     
    Anno Siegel, Jan 14, 2004
    #19
  20. Tad McClellan <> wrote in
    news::

    > Marc Bissonnette <> wrote:
    >
    >> 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.

    >
    >
    > Do the pod2* converters (eg: pod2html) work?


    I suspect that they do, but when I try it:
    ############################################
    pod2html -infile=c:/perl/lib/pod/perlretut.pod -outfile=perlretut.html -
    podpath=c:/perl/lib/pod/ -podroot c:/perl/lib/pod/
    ############################################

    I get "No perl script found in input"

    Now that you've made me think of it and try it - I'd be curious if someone
    could point me in the right direction as to why the above doesn't work...

    --
    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
     
    Marc Bissonnette, Jan 14, 2004
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shuo Xiang

    Stack space, global space, heap space

    Shuo Xiang, Jul 9, 2003, in forum: C Programming
    Replies:
    10
    Views:
    2,955
    Bryan Bullard
    Jul 11, 2003
  2. Christian Seberino
    Replies:
    21
    Views:
    1,766
    Stephen Horne
    Oct 27, 2003
  3. Ben C
    Replies:
    6
    Views:
    2,227
    Leif K-Brooks
    Jan 28, 2007
  4. Replies:
    2
    Views:
    266
    John Machin
    Sep 12, 2008
  5. erik
    Replies:
    10
    Views:
    188
    Anno Siegel
    Nov 11, 2005
Loading...

Share This Page