[21999] in Perl-Users-Digest
Perl-Users Digest, Issue: 4221 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 5 14:10:59 2002
Date: Thu, 5 Dec 2002 11:10:16 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 5 Dec 2002 Volume: 10 Number: 4221
Today's topics:
perl + shtml <yak@globalnet.co.uk>
Re: perl + shtml <cpryce@pryce.net>
Re: perl + shtml <usenet@dwall.fastmail.fm>
problems with references (Ilya Litosh)
Re: problems with references <nobull@mail.com>
Re: read from a process <RobTM@fake.addr.ess>
Re: read variables and values in them at runtime. <sunil_franklin@hotmail.com>
Re: read variables and values in them at runtime. <nobull@mail.com>
Scalar variable into indivudals <Geezer@Freezer.com>
Re: Scalar variable into indivudals <nobody@dev.null>
Re: Scalar variable into indivudals <tassilo.parseval@post.rwth-aachen.de>
Re: Scalar variable into indivudals <Graham.T.Wood@oracle.com>
Re: strange glob error (Scott Stark)
Re: Win32 and *NIX, cryptographically secure random num <michael@giantsquidmarks.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 05 Dec 2002 15:33:36 +0000
From: jackdaw <yak@globalnet.co.uk>
Subject: perl + shtml
Message-Id: <aesuuu4jjd5ttal49e7m0glnocti51nkkc@4ax.com>
Hi all
I was wondering if anyone knew if it was possible to generate a SHTML
(that contains includes) from Perl
when I try it, the page gets parsed as straight HTML
does anyone know a way around this or do I have to rethink the
generation method?
thanks in advance
jackdaw
------------------------------
Date: Thu, 05 Dec 2002 10:16:06 -0600
From: cp <cpryce@pryce.net>
Subject: Re: perl + shtml
Message-Id: <BA14D7E6.12D14%cpryce@pryce.net>
in article aesuuu4jjd5ttal49e7m0glnocti51nkkc@4ax.com, jackdaw at
yak@globalnet.co.uk wrote on 12/5/02 9:33 AM:
[ f'ups set ]
> I was wondering if anyone knew if it was possible to generate a SHTML
> (that contains includes) from Perl
>
> when I try it, the page gets parsed as straight HTML
>
> does anyone know a way around this or do I have to rethink the
> generation method?
Please don't multi-post. If you want your question to go to more than one
news group, cross-post the article. See the answer in alt.perl, including
the suggestion that the proper newsgroup is probably
comp.infosystems.www.authoring.cgi or one of the
comp.infosystems.www.servers newsgroups.
cp
------------------------------
Date: Thu, 05 Dec 2002 16:54:16 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: perl + shtml
Message-Id: <Xns92DB791967743dkwwashere@216.168.3.30>
cp <cpryce@pryce.net> wrote on 05 Dec 2002:
> in article aesuuu4jjd5ttal49e7m0glnocti51nkkc@4ax.com, jackdaw at
> yak@globalnet.co.uk wrote on 12/5/02 9:33 AM:
>
> [ f'ups set ]
>
>> I was wondering if anyone knew if it was possible to generate a
>> SHTML (that contains includes) from Perl
>>
>> when I try it, the page gets parsed as straight HTML
>>
>> does anyone know a way around this or do I have to rethink the
>> generation method?
>
> Please don't multi-post. If you want your question to go to more
> than one news group, cross-post the article. See the answer in
> alt.perl, including the suggestion that the proper newsgroup is
> probably comp.infosystems.www.authoring.cgi or one of the
> comp.infosystems.www.servers newsgroups.
Yeah, and anyway, we just did this a couple of weeks ago:
http://groups.google.com/groups?threadm=DLhD9.1421%24ea.73627%
40news2.calgary.shaw.ca
Summary: either read the files you want to include with Perl and
output them yourself, or configure your server to parse the script
output. The latter may or may not be possible (or even desirable),
depending on the server software -- check its docs.
--
David K. Wall - usenet@dwall.fastmail.fm
"Oook."
------------------------------
Date: 5 Dec 2002 05:49:10 -0800
From: ilja@interpro.ru (Ilya Litosh)
Subject: problems with references
Message-Id: <c79cdb5a.0212050549.265e6a60@posting.google.com>
Hello!
I have a recursive function which fills some tree. I want to
have an easy way of accessing the tree with some index (level
for example). I wrote this:
---------------------------------------
sub some_rec_func($$$)
{
my ($tree, $level, $tree_index) = @_;
$tree->{$level} = { };
$tree_index->[$level] = $tree;
some_rec_func($tree->{$level}, $level + 1, $tree_index) if ($level <
5);
}
my $tree = {}, $tree_index = [];
some_rec_func($tree, 0, $tree_index);
---------------------------------------
It fills $tree with (for example):
{ '0' => { '1' => { '2' => { '3' => { '4' => { '5' => {} } } } } } }
$tree-index is (with Data::Dump):
$tree_index = [
{ '0' => { '1' => { '2' => { '3' => { '4' => { '5' =>{
} } } } } } },
$tree_index->[0]{'0'},
$tree_index->[0]{'0'}{'1'},
$tree_index->[0]{'0'}{'1'}{'2'},
$tree_index->[0]{'0'}{'1'}{'2'}{'3'},
$tree_index->[0]{'0'}{'1'}{'2'}{'3'}{'4'}
];
That's strange for me because I expected that the second element will
be
{ '1' => { '2' => { '3' => { '4' => { '5' => { } } } } } } and it will
refer to this structure in $tree.
The strangest thing is, when I'm doing:
$tree->{0}->{1}->{2} = { };
the $tree_index becomes:
$tree_index = [
{ '0' => { '1' => { '2' => { } } } },
$tree_index->[0]{'0'},
$tree_index->[0]{'0'}{'1'},
{ '3' => { '4' => { '5' => { } } } },
$tree_index->[3]{'3'},
$tree_index->[3]{'3'}{'4'}
];
The deleted element in $tree appeared in $tree_index which is not
at all what I expected.
Why does it behave so strange?
Thanks for any help.
Ilya
------------------------------
Date: 05 Dec 2002 17:47:01 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: problems with references
Message-Id: <u9r8cwtl2i.fsf@wcl-l.bham.ac.uk>
ilja@interpro.ru (Ilya Litosh) writes:
> I have a recursive function which fills some tree. I want to
> have an easy way of accessing the tree with some index (level
> for example). I wrote this:
>
> ---------------------------------------
> sub some_rec_func($$$)
> {
> my ($tree, $level, $tree_index) = @_;
> $tree->{$level} = { };
> $tree_index->[$level] = $tree;
> some_rec_func($tree->{$level}, $level + 1, $tree_index) if ($level <
> 5);
> }
>
>
> my $tree = {}, $tree_index = [];
BTW: You really should enable warning and strictures.
> some_rec_func($tree, 0, $tree_index);
> ---------------------------------------
>
> It fills $tree with (for example):
> { '0' => { '1' => { '2' => { '3' => { '4' => { '5' => {} } } } } } }
>
> $tree-index is (with Data::Dump):
> $tree_index = [
> { '0' => { '1' => { '2' => { '3' => { '4' => { '5' =>{
> } } } } } } },
> $tree_index->[0]{'0'},
> $tree_index->[0]{'0'}{'1'},
> $tree_index->[0]{'0'}{'1'}{'2'},
> $tree_index->[0]{'0'}{'1'}{'2'}{'3'},
> $tree_index->[0]{'0'}{'1'}{'2'}{'3'}{'4'}
> ];
>
> That's strange for me because I expected that the second element will
> be
> { '1' => { '2' => { '3' => { '4' => { '5' => { } } } } } }
It is. If you set $Data::Dumper::Deepcopy you would see this more directly.
> and it will refer to this structure in $tree.
The structure isn't _in_ $tree its pointed to by $tree.
The following...
$tree_index->[0]{'0'}
$tree_index->[1]
$tree->{'0'}
...all contain references (pointers) to the same physical thing in
memory.
> The strangest thing is, when I'm doing:
> $tree->{0}->{1}->{2} = { };
> the $tree_index becomes:
>
> $tree_index = [
> { '0' => { '1' => { '2' => { } } } },
> $tree_index->[0]{'0'},
> $tree_index->[0]{'0'}{'1'},
> { '3' => { '4' => { '5' => { } } } },
> $tree_index->[3]{'3'},
> $tree_index->[3]{'3'}{'4'}
> ];
>
> The deleted element in $tree appeared in $tree_index which is not
> at all what I expected.
> Why does it behave so strange?
Beacause you are thinking that all these hashes things are _in_ $tree
or _in_ $tree_index. They are not. These hashes just are. The are
accessible through these things. When you change a value in a hash
you change the value in the _hash_ - regardless of which way you got
there. If you look at the same hash via a different route you still
see the change.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 5 Dec 2002 17:08:51 GMT
From: Robert Szczygiel <RobTM@fake.addr.ess>
Subject: Re: read from a process
Message-Id: <slrn.pl.auv213.19g.RobTM@pcmic25.cern.ch>
Sunil wrote:
> All,
> I have got the following routine which take a arbitrary sql script and
> executes it after connecting to a oracle DB.
[...]
> Any Ideas?
perldoc -m IPC::open3
Example for running perl script:
open3( \*WRH, \*RDH, \*ERH, "perl",$pname,@args);
close( WRH );
my @stdout = <RDH>;
my @stderr = <ERH>;
RobTM:)
--
** - Why a bike cannot stand up by itself?
** - Because it is two-tyred!
-- http://3226865153/~szczygie --
------------------------------
Date: Thu, 5 Dec 2002 19:55:59 +0530
From: "Sunil" <sunil_franklin@hotmail.com>
Subject: Re: read variables and values in them at runtime.
Message-Id: <yoJH9.5$Td5.25@news.oracle.com>
I have something like the following, but I am not seeing any value. I am
missing something?
----------------------------------------------------------------------------
------
package shared;
my $schemaName = 'pqr';
my $schemaPassword = 'abc';
my $connectString = 'xyz';
##########################
$sym='connectString';
$my_value = do { no strict 'refs'; *{"shared::$sym"}{HASH} } ;
print "Value is : $my_value \n";
##########################
1;
----------------------------------------------------------------------------
------
Thanks,
Sunil.
"Brian McCauley" <nobull@mail.com> wrote in message
news:u9d6ohv9p7.fsf@wcl-l.bham.ac.uk...
> "Sunil" <sunil_franklin@hotmail.com> writes:
>
> > I have a simple perl package.
> > I would like to write a routine (dump_vars() ) which will print all the
> > string variables in the package and their corresponding values at
runtime.
> > Is there any way I can achieve this?
>
> The symbol table of package FOO is a hash called %FOO:: - yes it
> really does end in a double-colon. It contains wierd things called
> typeglobs.
>
> You can get a list of bare symbols in FOO with keys(%FOO::).
>
> Suppose $sym='foo'
>
> The expresion do { no strict 'refs'; *{"FOO::$sym"}{HASH} } will return a
> reference to %FOO::foo if there is such a variable and undef
> otherwise.
>
> Similarly for other builtin types execpt that, unfortunately, for
> SCALAR it aways returns a reference.
>
> The documentation of typeglobs and symbol tables is rather scattered.
> Some is in perldata and some in perlmod (and some probably in other
> places).
>
> --
> \\ ( )
> . _\\__[oo
> .__/ \\ /\@
> . l___\\
> # ll l\\
> ###LL LL\\
------------------------------
Date: 05 Dec 2002 17:46:10 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: read variables and values in them at runtime.
Message-Id: <u9u1hstl3x.fsf@wcl-l.bham.ac.uk>
Please stop the TOFU posting. It is considered very rude. Being very
rude makes people angry with you. Making people angry with you
reduces the number of people who want to help you. Those people who
do help you will be in a less generous mood.
Do you have difficulty understanding any part of this?
"Sunil" <sunil_franklin@hotmail.com> writes TOFU:
[ TOFU corrected ]
> "Brian McCauley" <nobull@mail.com> wrote in message
> news:u9d6ohv9p7.fsf@wcl-l.bham.ac.uk...
> > "Sunil" <sunil_franklin@hotmail.com> writes:
> > > I would like to write a routine (dump_vars() ) which will print all the
> > > string variables in the package and their corresponding values at
> runtime.
> > > Is there any way I can achieve this?
> >
> > The symbol table of package FOO is a hash called %FOO:: - yes it
> > really does end in a double-colon. It contains wierd things called
> > typeglobs.
> >
> > You can get a list of bare symbols in FOO with keys(%FOO::).
> >
> > Suppose $sym='foo'
> >
> > The expresion do { no strict 'refs'; *{"FOO::$sym"}{HASH} } will return a
> > reference to %FOO::foo if there is such a variable and undef
> > otherwise.
> >
> > Similarly for other builtin types execpt that, unfortunately, for
> > SCALAR it aways returns a reference.
> package shared;
>
> my $connectString = 'xyz';
> $sym='connectString';
> $my_value = do { no strict 'refs'; *{"shared::$sym"}{HASH} } ;
The above will set $my_value to be a \%shared::connectString if there
is such a hash and set it to undef otherwise. Ther is no such thing
as %shared::connectString so it is undef.
Note that lexically scoped variables are not in packages. They are in
similar things called pads. There's no comprable way to access pads
(although there's probably something in B).
Manipulating pads is not something for the beginner.
> Thanks,
There is little point saying "Thanks" if you are going to spit TOFU in
our faces at the same time.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 05 Dec 2002 16:02:59 +0000
From: Geezer From The Freezer <Geezer@Freezer.com>
Subject: Scalar variable into indivudals
Message-Id: <3DEF78B3.B8685EA6@Freezer.com>
I have a scalar variable that contains this:-
8 packets transmitted, 8 packets received, 0% packet loss round-trip (ms)
min/avg/max = 2/2/3
I need to get the following into individual variables:-
0% (as 0)
2/2/3 (I need the middle value 2)
how can I do this? I've tried assigning variable like this
$B = @B[7]
$C = $B[14]
but to no avail - I'm lost.
------------------------------
Date: Thu, 05 Dec 2002 16:42:21 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: Scalar variable into indivudals
Message-Id: <3DEF817F.6070703@dev.null>
Geezer From The Freezer wrote:
> I have a scalar variable that contains this:-
>
> 8 packets transmitted, 8 packets received, 0% packet loss round-trip (ms)
> min/avg/max = 2/2/3
>
> I need to get the following into individual variables:-
>
> 0% (as 0)
> 2/2/3 (I need the middle value 2)
>
> how can I do this?
Use pattern matching (you can read up on it in the perlretut manpage).
Something along these lines:
use strict;
use warnings;
my $string=<DATA>;
if ($string=~m/(\d*)%/){
print "Packet loss is $1 percent.\n";
} else {
die "No valid packet loss figure.\n";
};
if ($string=~m[/(\d*)/]){
print "Average is $1.\n";
} else {
die "No valid average figure.\n";
};
__END__
8 packets transmitted, 8 packets received, 0% packet loss round-trip
(ms) min/avg/max = 2/2/3
===RESULTS===
Packet loss is 0 percent.
Average is 2.
------------------------------
Date: 5 Dec 2002 16:47:20 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Scalar variable into indivudals
Message-Id: <asnvuo$dvm$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Geezer From The Freezer:
> I have a scalar variable that contains this:-
>
> 8 packets transmitted, 8 packets received, 0% packet loss round-trip (ms)
> min/avg/max = 2/2/3
>
> I need to get the following into individual variables:-
>
> 0% (as 0)
> 2/2/3 (I need the middle value 2)
>
> how can I do this? I've tried assigning variable like this
> $B = @B[7]
> $C = $B[14]
>
> but to no avail - I'm lost.
Best is to tackle this with a regular expression in list context:
my ($perc, $avg) = $scalar =~ m!
(\d+)% # percentage
.* # we skip that till we get...
\d+/(\d+)/\d+$ # round-trip time avg
!x;
The x switch used here allows for embedded comments and it ignores
whitespace characters so the pattern can be written in more readably.
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Thu, 05 Dec 2002 17:14:25 +0000
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: Scalar variable into indivudals
Message-Id: <3DEF8971.F99169AC@oracle.com>
Geezer From The Freezer wrote:
> I have a scalar variable that contains this:-
>
> 8 packets transmitted, 8 packets received, 0% packet loss round-trip (ms)
> min/avg/max = 2/2/3
>
> I need to get the following into individual variables:-
>
> 0% (as 0)
> 2/2/3 (I need the middle value 2)
>
> how can I do this? I've tried assigning variable like this
> $B = @B[7]
> $C = $B[14]
>
> but to no avail - I'm lost.
You could use "split" to seperate each individual word into a separate array
element but you'd still need to remove parts to get rid of the "%" and the
"2/" and "/3", so I'd suggest just using a regular expression for the whole
thing:
$variable="8 packets transmitted, 8 packets received, 0% packet loss
round-trip (ms)
min/avg/max = 2/2/3";
if( $variable =~ m:(\d+)\%.*/(\d+)/:s){
$pc_packet_loss=$1;
$avg=$2;
}
What this is doing is matching, in $variable, any number of digits (\d+)
followed by % then any number of any character followed by a slash, any
number of digits then another slash, keeping the first "any digits" and the
one between the 2 slashes in $pc_packet_loss and $avg. The s means "treat
the variable as a single line" rather than a list of single lines.
For information about regular expressions and how to use them see perldoc
perlre (re for Regular Expressions) and perldoc perlretut (retut for Regular
Expressions Tutorial)
Hope this helps
Graham
------------------------------
Date: 5 Dec 2002 11:04:30 -0800
From: sstark@us.ibm.com (Scott Stark)
Subject: Re: strange glob error
Message-Id: <ce94ec71.0212051104.69dd50a5@posting.google.com>
Thanks for the explanation. One other question, how can I capture the
glob error so I can at least keep track of it? The script just
continues to run as if nothing happened. (Unfortunately I'm unable to
upgrade to perl 5.6.) Here's the output:
checking firstdir....
checking seconddir....
glob failed (child exited with status 1) at ./fh.pl line 38, <_GEN_0>
chunk 725.
checking thirddir....
My perl snippet:
my($dir);
@files = glob("$dir/*");
I've looked in the FAQ but couldn't find anything about this.
thanks,
Scott
mauzo@mimosa.csv.warwick.ac.uk (Ben Morrow) wrote in message news:<asjeva$9ae$1@wisteria.csv.warwick.ac.uk>...
> A pattern such as '*.c 'which expands to 'all files ending in .c in the current
> directory' is called a glob. ...
------------------------------
Date: Thu, 5 Dec 2002 11:40:55 -0700
From: "Michael D. Carey" <michael@giantsquidmarks.com>
Subject: Re: Win32 and *NIX, cryptographically secure random numbers with PERL
Message-Id: <3def9d3a_3@spamkiller.newsgroups.com>
It looks like Math::Random is on both platforms. Any
comments on the cryptographic security of Math::Random...?
I am not a crypto-idiot, but I also am not Bruce Schneier...
------------------------------
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.
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 4221
***************************************