[24530] in Perl-Users-Digest
Perl-Users Digest, Issue: 6710 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jun 20 14:05:47 2004
Date: Sun, 20 Jun 2004 11:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 20 Jun 2004 Volume: 10 Number: 6710
Today's topics:
(?{..}) and lexical scoping issues. <sourceror@front.ru>
Re: (?{..}) and lexical scoping issues. (Anno Siegel)
Re: Help with a "Post" procedure. <Joe.Smith@inwap.com>
Re: Help with a "Post" procedure. <jimsimpson@cox.net>
Help: Delete a single carriage return in a file, but no <steveo@member.fsf.org>
Re: Help: Delete a single carriage return in a file, bu <usenet@morrow.me.uk>
Re: Help: Delete a single carriage return in a file, bu (Anno Siegel)
Re: instance of class into sub? <Joe.Smith@inwap.com>
Re: KeepCDATA => 1 in XML::DOM (0/1) <markus.mohr@mazimoi.de>
Re: KeepCDATA => 1 in XML::DOM - 5.anf (0/1) <markus.mohr@mazimoi.de>
Re: KeepCDATA => 1 in XML::DOM <markus.mohr@mazimoi.de>
multiline comments don't work as explained in the FAQ <fake@nowhere.com>
Re: multiline comments don't work as explained in the F <lord-jacob-not-really@comcast-possibly.net>
Re: multiline comments don't work as explained in the F <matthew.garrish@sympatico.ca>
Re: permonks: random images/texts for web page <Joe.Smith@inwap.com>
Re: Port forwarding utility in perl <Joe.Smith@inwap.com>
print a hash ordered by value <yzhan@andrew.cmu.edu>
range as in MATLAB/octave (Caj Zell)
Re: range as in MATLAB/octave (Anno Siegel)
Re: search /\/.*[^.].*$/ <ken_sington@nospam_abcdefg.com>
the classic out of memory during large request (Tim)
Re: the classic out of memory during large request <usenet@morrow.me.uk>
unbuffered pipe (Oliver)
Re: unbuffered pipe <usenet@morrow.me.uk>
Re: unbuffered pipe <usenet@morrow.me.uk>
WMI and boolean values from Win32_Processor (Daniel Berger)
Re: WMI and boolean values from Win32_Processor (Anno Siegel)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 20 Jun 2004 16:24:35 +0400
From: "Aronaxis, the Sourceror" <sourceror@front.ru>
Subject: (?{..}) and lexical scoping issues.
Message-Id: <opr9v7e91ila67zl@s>
# ind_compare($string1,$string2 [,accuracy] )
# calculates strings "similarity"
# algorithm is cutted from some old Pascal code, and rewritten to use
# perl RE-engine backtracking for speed.
use warnings;
use strict;
sub DEBUG () {1}
our ($cnt, $match);
sub ind_compare ($$;$) {
my $max_len = $_[2];
# numification for security reasons.
$max_len="" unless $max_len +=0;
# WHY NOT?!
# my ($cnt,$match)=(0,0);
($cnt, $match) = (0,0);
use re 'eval'; # because of $max_len interpolation
# in regex below. But we cleaned it.
# loop for comparing $_[0] against $_[1], and $_[1] against $_[0] too
for my $i (0,1) {
$_[$i] =~ m{
( .{1,$max_len} )
(?{
$cnt++;
$match++ if index( $_[1-$i], $1 ) != -1;
})
(?!) # that always fail and force backtracking.
}x;
}
print "$match/$cnt\n" if DEBUG;
return 0 unless $cnt;
$match/$cnt;
}
print ind_compare( "abcdefgh","abcdefgh" ), "\n\n";
print ind_compare( "abcdefg!","abcdefgh" ), "\n\n";
__END__
Results:
1) if $match and $cnt in function &ind_compare declared as "our":
72/72
1
64/72
0.888888888888889
2) if $match and $cnt in function &ind_compare declared as "my":
72/72
1
0/0
0
......................
I found, that if I declare theese vars as "my", then code inside (?{...})
always uses _first_ instances of theese vars, created on _first_ sub
invocation. (strange, they still cleared on sub exit, but on second
invocation $cnt inside regex and $cnt outside are not the same!)..
So it works correctly only once!
dammit, why?!
looks like some scoping issues, but then why there are no problems with
lexical scoped $i, or @_ (which AFAIK is also lexical) ?
oh, yeah, that's an ActiveState port of perl 5.8.0 for Windows;
------------------------------
Date: 20 Jun 2004 17:10:56 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: (?{..}) and lexical scoping issues.
Message-Id: <cb4gf0$ps2$1@mamenchi.zrz.TU-Berlin.DE>
Aronaxis, the Sourceror <sourceror@front.ru> wrote in comp.lang.perl.misc:
> # ind_compare($string1,$string2 [,accuracy] )
> # calculates strings "similarity"
> # algorithm is cutted from some old Pascal code, and rewritten to use
> # perl RE-engine backtracking for speed.
>
> use warnings;
> use strict;
>
> sub DEBUG () {1}
>
> our ($cnt, $match);
> sub ind_compare ($$;$) {
> my $max_len = $_[2];
>
> # numification for security reasons.
> $max_len="" unless $max_len +=0;
>
> # WHY NOT?!
> # my ($cnt,$match)=(0,0);
> ($cnt, $match) = (0,0);
>
> use re 'eval'; # because of $max_len interpolation
> # in regex below. But we cleaned it.
>
> # loop for comparing $_[0] against $_[1], and $_[1] against $_[0] too
> for my $i (0,1) {
> $_[$i] =~ m{
> ( .{1,$max_len} )
> (?{
> $cnt++;
> $match++ if index( $_[1-$i], $1 ) != -1;
> })
> (?!) # that always fail and force backtracking.
> }x;
> }
>
> print "$match/$cnt\n" if DEBUG;
>
> return 0 unless $cnt;
> $match/$cnt;
> }
>
>
> print ind_compare( "abcdefgh","abcdefgh" ), "\n\n";
> print ind_compare( "abcdefg!","abcdefgh" ), "\n\n";
>
>
> __END__
> Results:
> 1) if $match and $cnt in function &ind_compare declared as "our":
>
> 72/72
> 1
>
> 64/72
> 0.888888888888889
>
>
> 2) if $match and $cnt in function &ind_compare declared as "my":
>
> 72/72
> 1
>
> 0/0
> 0
>
> ......................
> I found, that if I declare theese vars as "my", then code inside (?{...})
> always uses _first_ instances of theese vars, created on _first_ sub
> invocation. (strange, they still cleared on sub exit, but on second
> invocation $cnt inside regex and $cnt outside are not the same!)..
> So it works correctly only once!
> dammit, why?!
I don't have a pat explanation, except to point out that "(?{ ... })"
is still experimental. It has had scoping issues from day one and
still has.
> looks like some scoping issues, but then why there are no problems with
> lexical scoped $i, or @_ (which AFAIK is also lexical) ?
@_ is most definitely a package variable.
The distinction is not with lexical vs. local. If you change "our" to
"my", but keep the declarations out of the sub, you'll see the same
difference.
I also believe you are mistaken about there being no problems with $i.
In fact, its behavior can also be described as it having a different
value inside the regex and outside. This means that in effect you are
doing "index( $_[1], $1)" both times through the loop, though the regex
is first matched against $_[0] and then against $_[1].
Check this by removing "my" in front of "$i" and adding "$i" to the list
of "our" variables outside the loop. You will find that the match count
changes from 64 to 56 in the second case, which, I think, is correct.
(You are counting how many substrings of each string are also substrings
of the other, right?)
On a more general note, why are you doing this? As far as I can see,
there is no advantage in using the regex backtracking mechanism and
(?{ ... }) against a more conventional method of calling Perl code.
What you are really using it for is a mechanism to walk through
all substrings of a string. That's somewhat neat, but not necessarily
a speed gain. If the original Pascal program is anything like I imagine
it to be, it will be hard to beat with a Perl program.
To do it in Perl, I wouldn't employ the regex engine at all. Instead
I'd base it on a procedure to extract all non-empty substrings from
a string. Ignoring the requirement for a maximal string length for
simplicity, something like this would do:
use constant DEBUG => 1;
print ind_compare( "abcdefgh","abcdefgh" ), "\n\n";
print ind_compare( "abcdefg!","abcdefgh" ), "\n\n";
sub ind_compare {
my ( $s, $t) = @_;
my ( $count, $match);
for ( 1, 2 ) {
my @sub = all_substr( $s);
$count += @sub;
$match += grep 1 + index( $t, $_), @sub;
( $s, $t) = ( $t, $s);
}
print "$match/$count\n" if DEBUG;
$count ? $match/$count : 0;
}
sub all_substr {
my $s = shift;
my @sub;
while ( length $s ) {
push @sub, map substr( $s, $_), 0 .. length( $s) - 1;
chop $s;
}
@sub;
}
Anno
------------------------------
Date: Sun, 20 Jun 2004 09:41:11 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Help with a "Post" procedure.
Message-Id: <XYcBc.61529$Hg2.4441@attbi_s04>
Jim Simpson wrote:
> The source code includes the following:
> "<input type=text name="username" size="15" maxlength="35"
> AUTOCOMPLETE="off">"
> That's why I used "text" in my script.
That's part of your problem. The name of this textfield is "username",
not "text".
> For the button it includes the following:
> "<input type="image" name="submit" value="Submit"
> SRC="/images/login/log_on.gif" border="0">"
> I'm not at all sure that the button variable is correct or how the "post"
> line of script should indicate that the button is "on".
Unless the program is doing something fancy with X and Y values,
just use name="submit" and value="Submit".
-Joe
------------------------------
Date: Sun, 20 Jun 2004 10:14:44 -0400
From: "Jim Simpson" <jimsimpson@cox.net>
Subject: Re: Help with a "Post" procedure.
Message-Id: <PZgBc.10666$wD3.9299@lakeread03>
Thanks to all that responded. It works - now that I understand what's going
on the next site I work on should be a bit easier.
Jim
"Ben Morrow" <usenet@morrow.me.uk> wrote in message
news:cb2jg2$hga$1@wisteria.csv.warwick.ac.uk...
> [don't top-post]
>
> Quoth "Jim Simpson" <jimsimpson@cox.net>:
> > "Jim Simpson" <jimsimpson@cox.net> wrote in message
> > news:wgFAc.791$HN5.60@lakeread06...
> > > I am trying to automate logging in to an HTTPS site which requires a
> > "user
> > > name" and "password". It appears to me that the following code should
do
> > the
> > > job - but it does not do it. Can someone help me out on this.
> > >
> <snip>
> > > my $response = $ua->post($https_login, [ 'text' => "$https_user",
> > > 'password' => "$https_pass", 'submit' => "Log On" ] );
> >
> > In my first post I should have explained that I tried to determine the
> > correct variables to use. I found the following in the source code for
the
> > login sheet that I thought applied to "username" and that is why I used
> > "text" in my code.
> > <input type=text name="username" size="15" maxlength="35"
> > AUTOCOMPLETE="off">
> >
> > And the following that is why I used "password"
> > <input type="password" name="password" size="15" ONKEYDOWN="return
> > handleEnterSubmission( this.form , event)" maxlength="35"
> > AUTOCOMPLETE="off">
> >
> > And the following that I assume applies to the "button" confused me -
but I
> > made a stab at it. I'm not sure how I show that the button has been
pushed.
> > <input type="image" name="submit" value="Submit"
> > SRC="/images/login/log_on.gif" border="0">
>
> The relevant parameter of <input> is 'name'; so you want
>
> my $response = $ua->post(https_login, [
> username => $https_user,
> password => $https_pass,
> submit => 'Submit',
> ]);
>
> > Also i understand that some secure sites may encript the data going in.
How
> > can I determine if that is required for this site?
>
> That is what https does for you.
>
> Ben
>
> --
> 'Deserve [death]? I daresay he did. Many live that deserve death. And some
die
> that deserve life. Can you give it to them? Then do not be too eager to
deal
> out death in judgement. For even the very wise cannot see all ends.'
>
ben@morrow.me.uk
------------------------------
Date: Sun, 20 Jun 2004 05:38:05 GMT
From: Steve Anderson <steveo@member.fsf.org>
Subject: Help: Delete a single carriage return in a file, but not a double carriage return?
Message-Id: <pan.2004.06.20.05.49.16.706375@member.fsf.org>
I'd like to use perl to remove all single carriage returns, but leave all
double carriage returns intact in a text file.
For example, the following:
foo bar baz
baz bar foo baz
baz
baz foo bar
baz
should become:
foo bar baz baz bar foo baz baz
baz foo bar baz
It sounds simple, but I haven't been able to figure out how to do this.
Can anyone give me a hand?
Thanks,
Steve
------------------------------
Date: Sun, 20 Jun 2004 05:58:21 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Help: Delete a single carriage return in a file, but not a double carriage return?
Message-Id: <cb391t$naq$1@wisteria.csv.warwick.ac.uk>
Quoth Steve Anderson <steveo@member.fsf.org>:
> I'd like to use perl to remove all single carriage returns, but leave all
> double carriage returns intact in a text file.
>
> For example, the following:
>
> foo bar baz
> baz bar foo baz
> baz
>
> baz foo bar
> baz
>
> should become:
>
> foo bar baz baz bar foo baz baz
>
> baz foo bar baz
>
> It sounds simple, but I haven't been able to figure out how to do this.
> Can anyone give me a hand?
#!/usr/bin/perl
$/ = $\ = "\n\n";
while (<>) {
chomp;
s/\n//g;
print;
}
__END__
Ben
--
All persons, living or dead, are entirely coincidental.
ben@morrow.me.uk Kurt Vonnegut
------------------------------
Date: 20 Jun 2004 12:29:20 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Help: Delete a single carriage return in a file, but not a double carriage return?
Message-Id: <cb3vv0$h8f$1@mamenchi.zrz.TU-Berlin.DE>
Steve Anderson <steveo@member.fsf.org> wrote in comp.lang.perl.misc:
> I'd like to use perl to remove all single carriage returns, but leave all
^^^^^^
> double carriage returns intact in a text file.
>
> For example, the following:
>
> foo bar baz
> baz bar foo baz
> baz
>
> baz foo bar
> baz
>
> should become:
>
> foo bar baz baz bar foo baz baz
>
> baz foo bar baz
>
> It sounds simple, but I haven't been able to figure out how to do this.
> Can anyone give me a hand?
You say "remove", but from your example you want to replace isolated
line feeds with blanks.
You can use lookbehind and lookahead to make sure a line feed is neither
preceded nor followed by another:
s/(?<!\n)\n(?!\n)/ /g;
Anno
------------------------------
Date: Sun, 20 Jun 2004 09:15:09 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: instance of class into sub?
Message-Id: <xAcBc.145396$Ly.14669@attbi_s01>
gep wrote:
> But there was a reason. Not all the people read both newsgroups and
> because i want to know more about it and receive answer fro mmore
> people, i posted it into 2 diff groups (not 2, but 4 i think). If u
> can't understand it, its only your problem, not mine.
What you have described is a valid reason for posting a single message
that will show up in two or more groups. It's called "cross posting".
What you did was not cross posting. Instead, you posted two independent
messages to two different newsgroups. The proper thing to do is to
post one message to two (or four) newsgroups simulaneously.
Do you know how to post a single message to multiple groups simultaneously?
If you don't, you need to learn how.
Do you understand what I'm saying?
-Joe
------------------------------
Date: Sun, 20 Jun 2004 19:00:23 +0200
From: Markus Mohr <markus.mohr@mazimoi.de>
Subject: Re: KeepCDATA => 1 in XML::DOM (0/1)
Message-Id: <vhgbd0l86976rvoca5ago1h2od5a59d79o@4ax.com>
On 17 Jun 2004 23:01:25 GMT, Martien Verbruggen
<mgjv@tradingpost.com.au> wrote:
>[Please, do not post the same message to two newsgroups independently.
>You also posted this to comp.lang.perl.modules. Instead, use your
>newsreader's crossposting facility to post to multiple groups]
>
>On Thu, 17 Jun 2004 22:47:38 +0200,
> Markus Mohr <markus.mohr@mazimoi.de> wrote:
>> Hi, all,
>>
>> is it possible that "KeepCDATA => 1" within XML::DOM (e. g. 1.43) does
>> not work properly?
>
>It is possible, although I'd rate it as unlikely. What makes you think
>it doesn't work? Where is the code that you tested, and where is the
>data you tested it with? If you post a small self-contained code
>example and XML document here, we can have a look at it for you.
Sure I will. Here you are.
Sincerely
Markus Mohr
------------------------------
Date: Sun, 20 Jun 2004 19:04:25 +0200
From: Markus Mohr <markus.mohr@mazimoi.de>
Subject: Re: KeepCDATA => 1 in XML::DOM - 5.anf (0/1)
Message-Id: <eqgbd09hofjfhcjoarde6u7km7dtdb9smr@4ax.com>
On 17 Jun 2004 23:01:25 GMT, Martien Verbruggen
<mgjv@tradingpost.com.au> wrote:
>[Please, do not post the same message to two newsgroups independently.
>You also posted this to comp.lang.perl.modules. Instead, use your
>newsreader's crossposting facility to post to multiple groups]
>
>On Thu, 17 Jun 2004 22:47:38 +0200,
> Markus Mohr <markus.mohr@mazimoi.de> wrote:
>> Hi, all,
>>
>> is it possible that "KeepCDATA => 1" within XML::DOM (e. g. 1.43) does
>> not work properly?
>
>It is possible, although I'd rate it as unlikely. What makes you think
>it doesn't work? Where is the code that you tested, and where is the
>data you tested it with? If you post a small self-contained code
>example and XML document here, we can have a look at it for you.
Sure: Here is some small example as attachment.
Sincerely
Markus
------------------------------
Date: Sun, 20 Jun 2004 19:07:44 +0200
From: Markus Mohr <markus.mohr@mazimoi.de>
Subject: Re: KeepCDATA => 1 in XML::DOM
Message-Id: <a2hbd01qpl7vkmlfgb93sbld4kfgg39jp7@4ax.com>
On 17 Jun 2004 23:01:25 GMT, Martien Verbruggen
<mgjv@tradingpost.com.au> wrote:
>[Please, do not post the same message to two newsgroups independently.
>You also posted this to comp.lang.perl.modules. Instead, use your
>newsreader's crossposting facility to post to multiple groups]
>
>On Thu, 17 Jun 2004 22:47:38 +0200,
> Markus Mohr <markus.mohr@mazimoi.de> wrote:
>> Hi, all,
>>
>> is it possible that "KeepCDATA => 1" within XML::DOM (e. g. 1.43) does
>> not work properly?
>
>It is possible, although I'd rate it as unlikely. What makes you think
>it doesn't work? Where is the code that you tested, and where is the
>data you tested it with? If you post a small self-contained code
>example and XML document here, we can have a look at it for you.
Have sent them privately due to attachment limitations.
Many greetings,
Markus
------------------------------
Date: Sun, 20 Jun 2004 01:08:28 -0500
From: fake <fake@nowhere.com>
Subject: multiline comments don't work as explained in the FAQ
Message-Id: <b6aad01n9th3lr6uo3e6f9tke8kja655v8@4ax.com>
From the FAQ:
How can I comment out a large block of perl code?
Use embedded POD to discard it:
# program is here
=for nobody
This paragraph is commented out
# program continues
=begin comment text
all of this stuff
here will be ignored
by everyone
=end comment text
=cut
This can't go just anywhere. You have to put a pod directive where
the parser is expecting a new statement, not just in the middle of
an expression or some other arbitrary yacc grammar production.
>>>>>>>>>>>>>>>
However, only a "1" is printed from this program:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>..
#!c:/perl/bin/perl
print "\n 1";
=begin comment text
print "\n 2";
=end comment text
print "\n 3";
>>>>>>>>>>>>>>
Hence the multiline comments as explained in the perldoc do not work.
That is all...
------------------------------
Date: Sun, 20 Jun 2004 07:33:07 GMT
From: Jacob <lord-jacob-not-really@comcast-possibly.net>
Subject: Re: multiline comments don't work as explained in the FAQ
Message-Id: <5255ee57040c0340877b5d7f2005cfb0@news.teranews.com>
On Sun, 20 Jun 2004 01:08:28 -0500, a posting issued forth from fake...
> From the FAQ:
> How can I comment out a large block of perl code?
>
> Use embedded POD to discard it:
>
> # program is here
>
> =for nobody
> This paragraph is commented out
>
> # program continues
>
> =begin comment text
>
> all of this stuff
>
> here will be ignored
> by everyone
>
> =end comment text
>
> =cut
>
> This can't go just anywhere. You have to put a pod directive where
> the parser is expecting a new statement, not just in the middle of
> an expression or some other arbitrary yacc grammar production.
>>>>>>>>>>>>>>>>
>
>
Hmmm, what version of perl? Mine (5.8.3 on Fedora Core 2) says
Found in /usr/lib/perl5/5.8.3/pod/perlfaq7.pod
How can I comment out a large block of perl code?
You can use embedded POD to discard it. Enclose the blocks you
want to comment out in POD markers, for example "=for nobody" and "=cut"
(which marks ends of POD blocks).
# program is here
=for nobody
all of this stuff
here will be ignored
by everyone
=cut
# program continues
The pod directives cannot go just anywhere. You must put a pod
directive where the parser is expecting a new statement, not just in the
middle of an expression or some other arbitrary grammar production.
See perlpod for more details.
> However, only a "1" is printed from this program:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>..
>
>
> #!c:/perl/bin/perl
>
> print "\n 1";
>
>
>=begin comment text
>
> print "\n 2";
>
>
>
>=end comment text
>
> print "\n 3";
>
>
You forgot '=cut'...
>
>>>>>>>>>>>>>>>
>
> Hence the multiline comments as explained in the perldoc do not work.
>
> That is all...
>
#!/usr/bin/perl
print "1\n";
=for nobody
print "2\n";
=cut
print "3\n";
__END__
prints:
1
3
That seems to work to me...
--
Jacob
To email me, remove '-not-really' and '-possibly' from my email address.
------------------------------
Date: Sun, 20 Jun 2004 11:41:30 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: multiline comments don't work as explained in the FAQ
Message-Id: <FeiBc.1385$Nz.80503@news20.bellglobal.com>
"fake" <fake@nowhere.com> wrote in message
news:b6aad01n9th3lr6uo3e6f9tke8kja655v8@4ax.com...
> From the FAQ:
> How can I comment out a large block of perl code?
>
> Use embedded POD to discard it:
>
> # program is here
>
> =for nobody
> This paragraph is commented out
>
> # program continues
>
> =begin comment text
>
> all of this stuff
>
> here will be ignored
> by everyone
>
> =end comment text
>
> =cut
^^^^^^^
Important little bit, there.
> This can't go just anywhere. You have to put a pod directive where
> the parser is expecting a new statement, not just in the middle of
> an expression or some other arbitrary yacc grammar production.
> >>>>>>>>>>>>>>>
>
>
> However, only a "1" is printed from this program:
> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>..
>
>
> #!c:/perl/bin/perl
>
> print "\n 1";
>
>
> =begin comment text
>
> print "\n 2";
>
>
>
> =end comment text
>
Hmm, no =cut here...
> print "\n 3";
>
>
>
> >>>>>>>>>>>>>>
>
> Hence the multiline comments as explained in the perldoc do not work.
>
> That is all...
Failing to understand the documentation is not grounds for claiming it is
wrong. Next time ask for an explanation of why your code is not working
before you assume that you are right and the documentation is wrong...
Matt
------------------------------
Date: Sun, 20 Jun 2004 08:00:43 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: permonks: random images/texts for web page
Message-Id: <KubBc.73965$eu.52150@attbi_s02>
Wenjie wrote:
> - Shall I use SSI if my page is dynamically generated by perl CGI script?
Won't work. Most web servers will not look for SSI directives in the
output created by a CGI. You'll have to emulate them yourself.
-Joe
------------------------------
Date: Sun, 20 Jun 2004 09:07:32 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Port forwarding utility in perl
Message-Id: <otcBc.121667$3x.22045@attbi_s54>
Debashish Mishra wrote:
> I am searching for a port forwarding package in perl
I don't have a package but an entire program.
http://www.inwap.com/mybin/miscunix/list-files.pl?tcp-proxy
-Joe
------------------------------
Date: Sun, 20 Jun 2004 13:37:07 -0400 (EDT)
From: Yiping Zhan <yzhan@andrew.cmu.edu>
Subject: print a hash ordered by value
Message-Id: <Pine.LNX.4.58-035.0406201334320.3059@unix42.andrew.cmu.edu>
What is a good way of getting a printed output like:
d 7
b 6
a 3
c 1
if I have a hash like:
%h = qw(a 3 b 6 c 1 d 7);
Thank you!
-- Newbie
------------------------------
Date: 20 Jun 2004 08:16:31 -0700
From: cajzell@hotmail.com (Caj Zell)
Subject: range as in MATLAB/octave
Message-Id: <c9eae90e.0406200716.4234837a@posting.google.com>
Hello,
in MATLAB (or octave) you write 0:5:20 get a vector that's 0,5,10,15,20.
In perl I just did the following using the beginning, end and the interval.
@ratios=map $_*$interval,$lower..($upper/$interval);
Is there a nicer cleaner way using Perl?
Caj Zell
------------------------------
Date: 20 Jun 2004 17:20:58 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: range as in MATLAB/octave
Message-Id: <cb4h1q$ps2$2@mamenchi.zrz.TU-Berlin.DE>
Caj Zell <cajzell@hotmail.com> wrote in comp.lang.perl.misc:
> Hello,
>
> in MATLAB (or octave) you write 0:5:20 get a vector that's 0,5,10,15,20.
>
> In perl I just did the following using the beginning, end and the interval.
>
> @ratios=map $_*$interval,$lower..($upper/$interval);
>
> Is there a nicer cleaner way using Perl?
As far as it has the semantics you want, that's one way of doing it.
You may want POSIX::floor to get the right behavior for negatives.
Anno
------------------------------
Date: Sun, 20 Jun 2004 00:55:00 -0400
From: Ken Sington <ken_sington@nospam_abcdefg.com>
Subject: Re: search /\/.*[^.].*$/
Message-Id: <NGidnQgKdZ0ChUjdRWPC-w@speakeasy.net>
> would find a "/" and does not contain any number of dots between any
> number of characters.
> A shash followed by any number of word characters is valid.
> A shash followed by any number of word characters then a trailling slash
> is valid.
> A shash followed by any number of word characters then a dot then some
> more chars is not valid.
>
Ah, I see, thanks for pointing that out.
I ment those rules for what comes after the last slash.
------------------------------
Date: 20 Jun 2004 08:35:40 -0700
From: torque@gmail.com (Tim)
Subject: the classic out of memory during large request
Message-Id: <4770b7b.0406200735.4340e29f@posting.google.com>
I'm getting errors like this
Out of memory during "large" request for 528384 bytes, total sbrk() is
16302080 bytes at ... line 176.
when the server is busy. This is for a background perl script. What
I would like to do is to check to see if memory for the request is
available before running the offending the command, and just pause
everything until memory is available. Is that possible?
Thanks all,
Tim
------------------------------
Date: Sun, 20 Jun 2004 16:02:13 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: the classic out of memory during large request
Message-Id: <cb4ce4$aar$1@wisteria.csv.warwick.ac.uk>
Quoth torque@gmail.com (Tim):
> I'm getting errors like this
>
> Out of memory during "large" request for 528384 bytes, total sbrk() is
> 16302080 bytes at ... line 176.
>
> when the server is busy. This is for a background perl script. What
> I would like to do is to check to see if memory for the request is
> available before running the offending the command, and just pause
> everything until memory is available. Is that possible?
You could try investigating $^M...
Ben
--
I must not fear. Fear is the mind-killer. I will face my fear and
I will let it pass through me. When the fear is gone there will be
nothing. Only I will remain.
ben@morrow.me.uk Frank Herbert, 'Dune'
------------------------------
Date: 20 Jun 2004 08:36:37 -0700
From: spacehopper_man@yahoo.com (Oliver)
Subject: unbuffered pipe
Message-Id: <5818fca8.0406200736.fb2d5ac@posting.google.com>
I'm using a pipe to talk to a forked child process -
I do not want any data to get lost if the child process exits
unexpectedly -
- so I was hoping to turn off buffering so that there was at most 1
piece of data (i.e. one line) in the pipe.
I thought if I did:
select(PIPEHANDLE);
$| = 1;
then my pipe would not do buffering, and I was expecting that that
would lead to blocking writes - i.e. if the data hadn't been read from
the pipe, then a write to the pipe would block until it was.
however - after doing the above - I find I can still write data to the
pipe - regardless of how much is read out of the other end.
could someone enlighten me as to what's going on here please?
thanks muchly,
Oliver.
------------------------------
Date: Sun, 20 Jun 2004 16:04:31 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: unbuffered pipe
Message-Id: <cb4cif$aar$2@wisteria.csv.warwick.ac.uk>
Quoth spacehopper_man@yahoo.com (Oliver):
> I'm using a pipe to talk to a forked child process -
>
> I do not want any data to get lost if the child process exits
> unexpectedly -
>
> - so I was hoping to turn off buffering so that there was at most 1
> piece of data (i.e. one line) in the pipe.
>
> I thought if I did:
>
> select(PIPEHANDLE);
> $| = 1;
>
> then my pipe would not do buffering, and I was expecting that that
> would lead to blocking writes - i.e. if the data hadn't been read from
> the pipe, then a write to the pipe would block until it was.
>
> however - after doing the above - I find I can still write data to the
> pipe - regardless of how much is read out of the other end.
>
> could someone enlighten me as to what's going on here please?
$| turns off perl's buffering of the data before it gets sent down the
pipe. The data is still buffered inside the pipe: AFAIK, there is no way
to prevent this.
Ben
--
If you put all the prophets, | You'd have so much more reason
Mystics and saints | Than ever was born
In one room together, | Out of all of the conflicts of time.
ben@morrow.me.uk The Levellers, 'Believers'
------------------------------
Date: Sun, 20 Jun 2004 16:11:00 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: unbuffered pipe
Message-Id: <cb4cuk$ahf$1@wisteria.csv.warwick.ac.uk>
Quoth Ben Morrow <usenet@morrow.me.uk>:
>
> Quoth spacehopper_man@yahoo.com (Oliver):
> > I'm using a pipe to talk to a forked child process -
> >
> > I do not want any data to get lost if the child process exits
> > unexpectedly -
> >
> > - so I was hoping to turn off buffering so that there was at most 1
> > piece of data (i.e. one line) in the pipe.
<snop>
> >
> > however - after doing the above - I find I can still write data to the
> > pipe - regardless of how much is read out of the other end.
> >
> > could someone enlighten me as to what's going on here please?
>
> $| turns off perl's buffering of the data before it gets sent down the
> pipe. The data is still buffered inside the pipe: AFAIK, there is no way
> to prevent this.
...however, having thought some more, you could use a socketpair instead
and set the socketopts SO_SNDBUF and SO_RCVBUF to 1 byte.
Ben
--
Joy and Woe are woven fine,
A Clothing for the Soul divine William Blake
Under every grief and pine 'Auguries of Innocence'
Runs a joy with silken twine. ben@morrow.me.uk
------------------------------
Date: 20 Jun 2004 10:31:29 -0700
From: djberg96@hotmail.com (Daniel Berger)
Subject: WMI and boolean values from Win32_Processor
Message-Id: <6e613a32.0406200931.7ceab289@posting.google.com>
Hi all,
A.S. Perl 5.8.1
Windows 2000
I noticed that when using Win32::OLE + WMI, the boolean return values
from the Win32_Processor class return undef instead of a value.
Relevant link (select Win32_Processor on the left frame):
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/computer_system_hardware_classes.asp
Example code:
use strict;
use Sys::Hostname;
use Win32::OLE qw(in);
my $host = hostname();
my $cs = "winmgmts://$host/root/cimv2";
my $wmi = Win32::OLE->GetObject($cs);
my $cpu_set = $wmi->InstancesOf("Win32_Processor");
foreach my $cpu(in($cpu_set)){
print "Name: [", $cpu->{'Name'}, "]\n";
print "Error Code: [", $cpu->{'ConfigManagerErrorCode'}, "]\n";
print "Description: [", $cpu->{'Description'}, "]\n";
print "Error Cleared?: [", $cpu->{'ErrorCleared'}, "]\n";
}
# Output:
Name: [AMD Athlon(tm) XP 2800+]
Error Code: []
Description: [x86 Family 6 Model 10 Stepping 0]
Error Cleared?: []
The ConfigManagerErrorCode and ErrorCleared attributes (among others)
are of type boolean. I would expect a 0 or 1 for these attributes,
not undef. Or is it understood that undef == false? Or is a WMI
issue? I didn't see anything in the Win32::OLE docs that specifically
mentioned this.
Regards,
Dan
------------------------------
Date: 20 Jun 2004 18:01:38 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: WMI and boolean values from Win32_Processor
Message-Id: <cb4je2$rf0$1@mamenchi.zrz.TU-Berlin.DE>
Daniel Berger <djberg96@hotmail.com> wrote in comp.lang.perl.misc:
> Hi all,
>
> A.S. Perl 5.8.1
> Windows 2000
>
> I noticed that when using Win32::OLE + WMI, the boolean return values
> from the Win32_Processor class return undef instead of a value.
What makes you think the return values are undefined?
> Relevant link (select Win32_Processor on the left frame):
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/computer_system_hardware_classes.asp
>
> Example code:
>
> use strict;
I don't see "use warnings". Switching on warnings is the easiest way
to make actual undef's stand out.
> use Sys::Hostname;
> use Win32::OLE qw(in);
>
> my $host = hostname();
>
> my $cs = "winmgmts://$host/root/cimv2";
> my $wmi = Win32::OLE->GetObject($cs);
>
> my $cpu_set = $wmi->InstancesOf("Win32_Processor");
> foreach my $cpu(in($cpu_set)){
> print "Name: [", $cpu->{'Name'}, "]\n";
> print "Error Code: [", $cpu->{'ConfigManagerErrorCode'}, "]\n";
> print "Description: [", $cpu->{'Description'}, "]\n";
> print "Error Cleared?: [", $cpu->{'ErrorCleared'}, "]\n";
> }
>
> # Output:
> Name: [AMD Athlon(tm) XP 2800+]
> Error Code: []
> Description: [x86 Family 6 Model 10 Stepping 0]
> Error Cleared?: []
>
> The ConfigManagerErrorCode and ErrorCleared attributes (among others)
> are of type boolean. I would expect a 0 or 1 for these attributes,
> not undef. Or is it understood that undef == false? Or is a WMI
> issue? I didn't see anything in the Win32::OLE docs that specifically
> mentioned this.
It is standard Perl practice to return 1 for boolean true, but an
empty string[1] for false. It is still a defined value. So your
result is consistent with normal behavior. I suppose that is the
case.
However, in the absence of warnings, you could be right, and some
of the values could indeed be undefined. To check this, switch on
warnings, or do something like
die 'boo' unless defined $cpu->{'ConfigManagerErrorCode'};
[1] The empty string returned for boolean false isn't just any empty
string. It also has a numeric value of 0, so you can add to it
(or index with it, or otherwise use it as a number) with impunity.
It is one of the janus-headed scalars Perl has up its sleeve, and
it is as correct to say that the value is 0 which happens to have
a string value of ''. Other such two-sided scalars are supplied
by the system variable $!.
Anno
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 6710
***************************************