matching only white space

L

Lack Mr G M

|>
|> > 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/) {
....
 
A

A. Sinan Unur

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
 
M

Marc Bissonnette

Pay attention to


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

Brian Helterline

A. Sinan Unur said:
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
 
M

Matt Garrish

Anno Siegel said:
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
 
B

Ben Morrow

Brian Helterline said:
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
 
A

A. Sinan Unur

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

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

Anno Siegel

Matt Garrish said:
Anno Siegel said:
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
 
M

Matt Garrish

Anno Siegel said:

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
 
A

Anno Siegel

Matt Garrish said:
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
 
B

Brian Helterline

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


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

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

This is just a module that ppm calls. As far as I can tell, it only
rebuilds
the TOC from *existing* html files.

I am referring to the case where a module I want is not available through
PPM
so I have to get it from CPAN and those typically do not come with HTML
docs.

My script simply takes a module, calls pod2html, puts the output into the
appropriate directory under perl\html\... and then calls
ActivePerl::DocTools::WriteTOC to rebuild the TOC which will include the
module.

It tries to do what PPM does, but with a module from CPAN.

Did I miss something in the AS documentation and re-invent a wheel?

-brian
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top