Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > matching only white space

Reply
Thread Tools

matching only white space

 
 
Lack Mr G M
Guest
Posts: n/a
 
      01-14-2004
In article <bu37e5$3p2$(E-Mail Removed)-Berlin.DE>, http://www.velocityreviews.com/forums/(E-Mail Removed)-berlin.de (Anno Siegel) writes:
|>
|> > my $line = 'IHAVENOWHITESPACE';
|> >
|> > if ($line =~ /\s*/) {
|> > print "D'oh!";
|> > }
|>
|> So? It still didn't match anything but spaces.

Well, I suggest your try looking for 1, rather than any number,
including 0.

....
if ($line =~ /\s/) {
....

--
--------- Gordon Lack --------------- http://www.velocityreviews.com/forums/(E-Mail Removed) ------------
This message *may* reflect my personal opinion. It is *not* intended
to reflect those of my employer, or anyone else.
 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      01-14-2004
Marc Bissonnette <(E-Mail Removed)> wrote in
news:Xns94706C91E9B3Fdragnetinternalysisc@207.35.1 77.134:

> Tad McClellan <(E-Mail Removed)> wrote in
> news:(E-Mail Removed):
>
>> 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...


Pay attention to

> - podpath=c:/perl/lib/pod/ -podroot c:/perl/lib/pod/


The space between the - and podpath causes pod2html to wait for input
from STDIN. However, I did not get that error message above, so I don't
know exactly want is going on with your system.

There is an extra little problem in that the script thinks ":" is a path
separator (as it is on *nix systems), so:

C:\Perl\lib\Pod> pod2html -infile=c:/perl/lib/pod/perlretut.pod \
-outfile=perlretut.html -podpath=c:/perl/lib/pod/ \
-podroot= c:/perl/lib/pod/

C:\Perl\bin/pod2html.bat: error opening directory c: No such file or
directory

In fact, pod2html --help yields:

--podpath - colon-separated list of directories containing library
pods (empty by default).
--podroot - filesystem base directory from which all relative paths
in podpath stem (default is .).

Now, why didn't you check that?

So, if you really want to use those options, try:

C:\Temp> pod2html -infile=c:/perl/lib/pod/perlretut.pod \
-outfile=perlretut.html -podpath=/perl/lib/pod/ \
-podroot=/perl/lib/pod/

Also, do you have C:\Perl\bin in your path? In that case, there should
not be any need for the extra options.

On my system, both

C:\Perl\lib\pod> pod2html perlretut.pod

and

pod2html -infile=c:/perl/lib/pod/perlretut.pod -outfile=perlretut.html

work. The first one sends output to STDOUT and the other one creates
perlretut.html. OTOH, as I mentioned before, AS Perl already comes with
all docs in HTML format.

Sinan

--
A. Sinan Unur
(E-Mail Removed) (reverse each component for email address)
 
Reply With Quote
 
 
 
 
Marc Bissonnette
Guest
Posts: n/a
 
      01-14-2004
"A. Sinan Unur" <(E-Mail Removed)> wrote in
news:Xns947074C9814DCasu1cornelledu@132.236.56.8:

> Marc Bissonnette <(E-Mail Removed)> wrote in
> news:Xns94706C91E9B3Fdragnetinternalysisc@207.35.1 77.134:
>
>> Tad McClellan <(E-Mail Removed)> wrote in
>> news:(E-Mail Removed):
>>
>>> 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...

>
> Pay attention to
>
>> - podpath=c:/perl/lib/pod/ -podroot c:/perl/lib/pod/

>
> The space between the - and podpath causes pod2html to wait for input
> from STDIN. However, I did not get that error message above, so I
> don't know exactly want is going on with your system.


arg. thanks for noticing that - the space.

>
> There is an extra little problem in that the script thinks ":" is a
> path separator (as it is on *nix systems), so:
>
> C:\Perl\lib\Pod> pod2html -infile=c:/perl/lib/pod/perlretut.pod \
> -outfile=perlretut.html -podpath=c:/perl/lib/pod/ \
> -podroot= c:/perl/lib/pod/
>
> C:\Perl\bin/pod2html.bat: error opening directory c: No such file or
> directory
>
> In fact, pod2html --help yields:
>
> --podpath - colon-separated list of directories containing
> library
> pods (empty by default).
> --podroot - filesystem base directory from which all relative
> paths
> in podpath stem (default is .).
>
> Now, why didn't you check that?


First thing I did check, actually, but I got an error. Now that I go
back and double-check, pod2html --help works as supposed to. I must have
made an error the first time I hit it :/

> So, if you really want to use those options, try:
>
> C:\Temp> pod2html -infile=c:/perl/lib/pod/perlretut.pod \
> -outfile=perlretut.html -podpath=/perl/lib/pod/ \
> -podroot=/perl/lib/pod/
>
> Also, do you have C:\Perl\bin in your path?


Yup

> In that case, there should
> not be any need for the extra options.
>
> On my system, both
>
> C:\Perl\lib\pod> pod2html perlretut.pod


Interesting ; the above gives me:

Can't open perlretut.pod: No such file or directory at
C:/Perl/lib/Pod/Html.pm line 363.

> and
>
> pod2html -infile=c:/perl/lib/pod/perlretut.pod -outfile=perlretut.html


Whereas this one works fine (created the HTML files, et al).

(Note: I closed the dos session and opened a new one, which seems to
have fixed it - dunno why that is)

> work. The first one sends output to STDOUT and the other one creates
> perlretut.html. OTOH, as I mentioned before, AS Perl already comes
> with all docs in HTML format.


Yeah, I know, this was just an excercise in curiosity, since Tad asked
if pod2html worked on a winbox. Thanks for taking a look.

--
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
 
Reply With Quote
 
Brian Helterline
Guest
Posts: n/a
 
      01-14-2004

"A. Sinan Unur" <(E-Mail Removed)> wrote in message
> On my system, both
>
> C:\Perl\lib\pod> pod2html perlretut.pod
>
> and
>
> pod2html -infile=c:/perl/lib/pod/perlretut.pod -outfile=perlretut.html
>
> work. The first one sends output to STDOUT and the other one creates
> perlretut.html. OTOH, as I mentioned before, AS Perl already comes with
> all docs in HTML format.


Unless you install something directly from CPAN and it does not have HTML
formatted docs.
I enjoy using the HTML version from AS so I crafted a script, similar to
pod2html
called as_pod2html which turns POD into HTML using the AS template and then
rebuilds the Table of Contents so the new docs show up.

It isn't ready for release (don't know if it every will be) since I am
struggling
with relative paths and x-ref to other docs being correctly linked.

If you'd like a copy, I'll email it to you.

-brian


 
Reply With Quote
 
Matt Garrish
Guest
Posts: n/a
 
      01-14-2004

"Anno Siegel" <(E-Mail Removed)-berlin.de> wrote in message
news:bu3i32$d70$(E-Mail Removed)-Berlin.DE...
> Matt Garrish <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> >
> > 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.
>


Any regex that does not define at least some definite match criteria will
never match what you intend. / */ is exactly the same thing as /(<[^>]*>)*/
or any other example you could come up with. Both will always return a match
(regardless of whether the string being compared is defined or not), and
were you to use either in a foreach loop they would return the same count.
The only possible use I can see would be to count characters, but as I noted
you're not going to get what you think. For example:

my $str = 'this is a test';

my $cnt1;
foreach ($str =~ / */g) { $cnt1++; }
print "$cnt1\n";

my $cnt2;
foreach ($str =~ /(<[^>]*>)*/g) { $cnt2++; }
print "$cnt2\n";

What you are matching is the "space in between" (I'm sure Mr. Friedl would
have a better term for it, but I don't know where his book disappeared off
to). In other words (if you don't mind a little graphical representation)
the above example matches all of the # in the following:

'#t#h#i#s# #i#s# #a# #t#e#s#t#'

I don't know what other use an expression like this would have but for the
length, and not even for that (I was simply trying to think positive!). It's
easy to verify:

my $str = 'this is a test';

my $cnt1;
foreach ($str =~ /( )*/g) { print "<$1>\n" }

As you'll no doubt see, you get a whole lot of nothing...

Matt


 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      01-15-2004

"Brian Helterline" <(E-Mail Removed)> wrote:
>
> "A. Sinan Unur" <(E-Mail Removed)> wrote in message
> > On my system, both
> >
> > C:\Perl\lib\pod> pod2html perlretut.pod
> >
> > and
> >
> > pod2html -infile=c:/perl/lib/pod/perlretut.pod -outfile=perlretut.html
> >
> > work. The first one sends output to STDOUT and the other one creates
> > perlretut.html. OTOH, as I mentioned before, AS Perl already comes with
> > all docs in HTML format.

>
> Unless you install something directly from CPAN and it does not have HTML
> formatted docs.
> I enjoy using the HTML version from AS so I crafted a script, similar to
> pod2html
> called as_pod2html which turns POD into HTML using the AS template and then
> rebuilds the Table of Contents so the new docs show up.
>
> It isn't ready for release (don't know if it every will be) since I am
> struggling
> with relative paths and x-ref to other docs being correctly linked.


Err... hate to disappoint, but I'm *fairly* sure AS already provide
one, which goes through the whole of @INC and redoes all the docs. ppm
calls it just after its finished installing something.

Ben

--
Every twenty-four hours about 34k children die from the effects of poverty.
Meanwhile, the latest estimate is that 2800 people died on 9/11, so it's like
that image, that ghastly, grey-billowing, double-barrelled fall, repeated
twelve times every day. Full of children. [Iain Banks] (E-Mail Removed)
 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      01-15-2004
Ben Morrow <(E-Mail Removed)> wrote in
news:bu4nkm$loh$(E-Mail Removed):

> "Brian Helterline" <(E-Mail Removed)> wrote:
>> Unless you install something directly from CPAN and it does not have
>> HTML formatted docs.


We are talking about ActiveState Perl for Windows. I generally install
modules using ppm and automatically get the HTML docs as well.

>> I enjoy using the HTML version from AS so I crafted a script, similar
>> to pod2html called as_pod2html which turns POD into HTML using the AS
>> template and then rebuilds the Table of Contents so the new docs show
>> up.

....

> Err... hate to disappoint, but I'm *fairly* sure AS already provide
> one, which goes through the whole of @INC and redoes all the docs. ppm
> calls it just after its finished installing something.


Ben is right. The required modules etc can be found in

C:\Perl\site\lib\ActivePerl\DocTools

Sinan.
--
A. Sinan Unur
(E-Mail Removed) (reverse each component for email address)
 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      01-15-2004
Matt Garrish <(E-Mail Removed)> wrote in comp.lang.perl.misc:
>
> "Anno Siegel" <(E-Mail Removed)-berlin.de> wrote in message
> news:bu3i32$d70$(E-Mail Removed)-Berlin.DE...
> > Matt Garrish <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> > >
> > > 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.
> >

>
> Any regex that does not define at least some definite match criteria will
> never match what you intend. / */ is exactly the same thing as /(<[^>]*>)*/
> or any other example you could come up with. Both will always return a match
> (regardless of whether the string being compared is defined or not), and
> were you to use either in a foreach loop they would return the same count.


Sure?

$_ = 'a bb cccc';
my $n1 = () = / */g;
my $n2 = () = /(<[^>]*>)*/g;

print "n1: $n1, n2: $n2\n";

/ */ matches 10 times, /(<[^>]*>)*/ matches 12 times.

Those patterns will always match anywhere in a string, that much is true.
But given a chance to match more than an empty string, they will, and
that will decide how much of the string they skip. So the total number
of matches may be different.

> The only possible use I can see would be to count characters, but as I noted
> you're not going to get what you think. For example:


[snip]

They don't count characters, they don't even count gaps between characters.
It isn't easy to say in a few words what they count, because one more
empty match happens after each non-empty match, but none between the
characters that were matched.

Anno
 
Reply With Quote
 
Matt Garrish
Guest
Posts: n/a
 
      01-15-2004

"Anno Siegel" <(E-Mail Removed)-berlin.de> wrote in message
news:bu5j5v$krb$(E-Mail Removed)-Berlin.DE...
>
> Sure?
>


I guess not...

I suppose I should make a better effort to find that regex book. My
understanding of an optional pattern was that it would always match // over
whatever pattern was specified. Mea culpa.

And I never meant to imply that it was counting characters or matching
characters. In fact, I was trying to assert completely the opposite. In a
string that doesn't match the pattern in any way, the count returned will
always equal one more than the number of characters in the string (not
because it's counting them, but because of the way the pattern matches). The
only usefulness I could see for this number is as a bad approximation of the
length, but as it's not the rule...

I will stick to my guns and say that they *generally* don't serve any
purpose, and in *almost* all cases should be avoided (99.999% sound
reasonable... : )

Matt


 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      01-15-2004
Matt Garrish <(E-Mail Removed)> wrote in comp.lang.perl.misc:
>
> "Anno Siegel" <(E-Mail Removed)-berlin.de> wrote in message
> news:bu5j5v$krb$(E-Mail Removed)-Berlin.DE...
> >
> > Sure?
> >

>
> I guess not...
>
> I suppose I should make a better effort to find that regex book. My
> understanding of an optional pattern was that it would always match // over
> whatever pattern was specified. Mea culpa.


It *can* always match an empty string ("//" is misleading here), but
it will prefer to match more.

[what they count]

> I will stick to my guns and say that they *generally* don't serve any
> purpose, and in *almost* all cases should be avoided (99.999% sound
> reasonable... : )


No. There is absolutely nothing wrong with patterns that can match an
empty string. What you say may be true for non-greedy such expressions,
because they will indeed match the empty string first. In general,
the ability to match an empty string is an essential feature of regular
expressions. You wouldn't want to work with a system that didn't allow it.

Anno
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Matching horizontal white space Magnus.Moraberg@gmail.com Python 2 09-12-2008 08:01 PM
Any programs to trim white space/ remove all white space in HTML file? Ben C HTML 6 01-28-2007 11:41 PM
matching a pattern with a space or no space?? erik Perl Misc 10 11-11-2005 12:43 PM
Why Python style guide (PEP-8) says 4 space indents instead of 8 space??? 8 space indents ever ok?? Christian Seberino Python 21 10-27-2003 04:20 PM
Stack space, global space, heap space Shuo Xiang C Programming 10 07-11-2003 07:30 PM



Advertisments