[9032] in Perl-Users-Digest
Perl-Users Digest, Issue: 2650 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 20 17:08:07 1998
Date: Wed, 20 May 98 14:00:54 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 20 May 1998 Volume: 8 Number: 2650
Today's topics:
Re: Benchmark: local filehandle vs. Filehandle.pm <tchrist@mox.perl.com>
Re: Benchmark: pre-extending array? <danboo@negia.net>
Re: Benchmark: pre-extending array? (John Porter)
Re: Benchmark: pre-extending array? (Mark-Jason Dominus)
Re: COM and CPAN (actually, a semi-rant on survivable s <bruce_howells@i2.com>
Re: file locking question <aqumsieh@matrox.com>
Re: Flushing STDIN before read? <gmarzot@baynetworks.com>
Re: Function syntax with prototyping, filehandles and a <tchrist@mox.perl.com>
Re: Help please... <ahdiii@webspan.net>
Re: Inter-process file arbitration? <tchrist@mox.perl.com>
Re: Inter-process file arbitration? <lr@hpl.hp.com>
Newbie package hash ??? <dcordero@giss.nasa.gov>
Re: Newbie package hash ??? (Mike Stok)
Re: Newbie package hash ??? (John Porter)
Perl forking (Benjamin Dixon)
Re: Perl forking <ahdiii@webspan.net>
Re: Perl terminology <aqumsieh@matrox.com>
perl variables <jeffyjo-isom@worldnet.att.net>
Re: perl variables (Mike Stok)
Problem de-referencing a reference to a typeglob stored (Alan Meyer)
Re: Run .pl or .cgi under Win95 <ahdiii@webspan.net>
Re: Run .pl or .cgi under Win95 (Craig Berry)
Re: Running Perl on Windows (Alan Meyer)
Re: SNMP and Perl <gmarzot@baynetworks.com>
string comparisons armitage21@my-dejanews.com
suid problem <joe@ispsoft.de>
Re: Trying to install a module ... <ahdiii@webspan.net>
What is wrong with this FileHandle code? <jim.michael@gecm.com>
Re: What is wrong with this FileHandle code? <ahdiii@webspan.net>
Re: What is wrong with this FileHandle code? <jim.michael@gecm.com>
Re: Where is warning about PERL 5.001? (I R A Aggie)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 20 May 1998 20:11:55 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Benchmark: local filehandle vs. Filehandle.pm
Message-Id: <6jvdeb$i47$3@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
<jari.aalto@poboxes.com> (Jari Aalto+mail.perl) writes:
:
: After seeing the discussion about the slowness of Filehandle
: package I wanted to see just how slow it would make code.
I think you did something wrong.
use FileHandle;
use Benchmark;
timethese 100_000, {
meth => sub { $x = FileHandle->new() },
local => sub { $x = do { local *FH; \*FH } },
}
local: 4 secs ( 1.64 usr 0.00 sys = 1.64 cpu)
meth: 43 secs (20.34 usr 0.41 sys = 20.75 cpu)
use FileHandle;
use Benchmark;
timethese 25 => {
module => sub {
my $fh = FileHandle->new("/etc/termcap", "r");
while ( $_ = $fh->getline ) { }
},
normal => sub {
local *FH;
open(FH,"/etc/termcap");
while ( <FH>) { }
},
};
module: 19 secs ( 9.10 usr 0.15 sys = 9.25 cpu)
normal: 3 secs ( 1.53 usr 0.08 sys = 1.61 cpu)
Modules are
s
l
o
w
And in this case, do virtually nothing for you but super slowdowns.
--tom
--
"If you think Emacs is such a great editor, just look what it did for
Richard Stallman's typing skills!"
------------------------------
Date: Wed, 20 May 1998 14:10:20 -0400
From: Dan Boorstein <danboo@negia.net>
Subject: Re: Benchmark: pre-extending array?
Message-Id: <35631C8C.EB5086D7@negia.net>
John Porter wrote:
> sub extending {
> my $c = 1;
> my @a = (undef) x $size;
> for (1..$size) {
> $c ||= $_;
> }
> \@a;
> }
i'm not so sure this is the sort of pre-extending the camel refers to.
the above is indeed extending, but it is quite explicit. it assigns a
temporary list of 1000 undefined elements to an array. i believe the
camel refers to implict extending through setting $#a or by assigning
$a[$size-1] to undef.
i believe this issue was recently beat to death on the p5p list so i
would check the archives for a variety of benchmark results. the
thread is called "Array preallocation: the devil's work?"
cheers,
--
Dan Boorstein home: danboo@negia.net work: danboo@y-dna.com
"THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER."
- Cosmic AC
------------------------------
Date: Wed, 20 May 1998 20:10:44 GMT
From: jdporter@min.net (John Porter)
Subject: Re: Benchmark: pre-extending array?
Message-Id: <MPG.fcd043fb31b59f29896e1@news.min.net>
On 20 May 1998 17:12:16 GMT,
in article <6jv2tg$241@news.service.uci.edu>,
ehood@geneva.acs.uci.edu (Earl Hood) wrote:
> [mail & posted]
>
> This is not equivalent in functionality. The extending is not
> really "extending" but array initialize.
You're right. My bad.
But...
> To make it more like the pushing function, the following is better:
>
> sub extending {
> my $c = 1;
> my @a;
> for (1..$size) {
> $c ||= $_;
> $a[$#a+1] = undef;
> }
> \@a;
> }
>
> Now it mirrors the action of extending the array during a loop. This
> mirrors the semantics of pushing.
The idea is not to duplicate the semantics of push.
The question is, which way is faster in typical user code?
If I'm going to be stuffing a large number of things into an
array, do I get a speed advantage by pre-extending the array?
So, in retrospect, Jari's original test was sufficient to
demonstrate that preextend+multiassign is slower than
multipush.
John Porter
------------------------------
Date: 20 May 1998 16:54:15 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Benchmark: pre-extending array?
Message-Id: <6jvftn$q2q$1@monet.op.net>
Keywords: hyaline opiate scope tale
In article <tbiun1hwj0.fsf@blue.sea.net>, <jari.aalto@poboxes.com> wrote:
>
> In what circumstances the pre-extending is faster?
> Or is pre-exteding remerk obsolete in recent perl?
> Please comment if I did the test wrong.
Before everyone gets hot and bothered about this, I should point out
that we discussed this at length on p5p, because Jon Orwant was
shocked to discover that preextending seemed to be much slower.
But then Chip pointed out that for something like this:
> a => '
> my @a;
> for (1..100)
> {
> push @a, "1";
> }
> @a'
the array @a grows to be 100 elements long, and Perl *never releases
the memory for it*. The theory here is that if it got big once, it
will probably get big again. In this case, the theory is exactly
right. The memory hangs around, and on the next trial, it is
*already* pre-extended.
So you are not benchmarking the thing you think you are benchmarking.
------------------------------
Date: Wed, 20 May 1998 14:49:30 -0400
From: Bruce Howells <bruce_howells@i2.com>
Subject: Re: COM and CPAN (actually, a semi-rant on survivable software design)
Message-Id: <356325BA.74FE1B6A@i2.com>
John Porter wrote:
> Why in the world did you not rename get.bat to lwp-get.bat?
> What possible advantage could there have been to renaming it so
> unconformingly as you did?
The intent was to prevent the get.bat from getting in the way - not necessarily to be
poetic about filenaming for a one-off problem solution. Something, which it would
seem, others take rather more seriously than I.
-Bruce Howells, bruce_howells@i2.com
------------------------------
Date: Wed, 20 May 1998 15:57:07 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: file locking question
Message-Id: <35633593.7BAB041F@matrox.com>
Ryan McGuigan wrote:
> How can I read the last line of a file, and then append to it while having
> it locked the whole time?
>
> thanks,
> Ryan
Well...
Lock it (exclusively) before you read and append.
Is this a trick question?
--
Ala Qumsieh | No .. not just another
ASIC Design Engineer | Perl Hacker!!!!!
Matrox Graphics Inc. |
Montreal, Quebec | (Not yet!)
------------------------------
Date: 20 May 1998 15:56:30 -0400
From: Joe Marzot <gmarzot@baynetworks.com>
Subject: Re: Flushing STDIN before read?
Message-Id: <pdaf8cpvgx.fsf@baynetworks.com>
just a hunch - check out Term::ReadKey and Term::Readline
(both installed on global for Bay)
-GSM
psmith@baynetworks.com (Paul D. Smith) writes:
>
> OK, so I have this important question I want to ask the user. I'm
> reading from STDIN. I want to flush any typeahead he/she may have
> entered, to avoid possible incorrect responses.
>
> Soooo... how to do that with perl?
>
> My investigations so far are leading me down the fcntl() path, setting
> the O_NONBLOCK option on the STDIN file descriptor, then using sysread()
> to try to read from STDIN until I get back some kind of "would block"
> error, then unsetting the O_NONBLOCK option and continuing as normal.
>
> Is this the only/best way to go?
>
> If so, what's the most portable method for this? There seem to be many
> choices for setting non-blocking bits, such as O_NDELAY, FNDELAY, or
> O_NONBLOCK, but ideally the same perl code would run on SunOS 4.1.x and
> Solaris 2.x, along with AIX and HP-UX.
>
> Anyone have any samples they'd care to part with :)?
>
> Also, faq pointers or other doc or CPAN pointers are great, as are
> pointers to existing code that does similar things (I searched through
> the core and the modules I have installed for fcntl and BLOCK but didn't
> notice any examples, and my search of CPAN didn't turn up anything).
>
> --
> -------------------------------------------------------------------------------
> Paul D. Smith <psmith@baynetworks.com> Network Management Development
> "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
> -------------------------------------------------------------------------------
> These are my opinions--Bay Networks takes no responsibility for them.
--
G.S. Marzot email: gmarzot@baynetworks.com
Bay Networks Inc. voice: (978)670-8888 x63990
600 Tech Park M/S BL60-101 pager: (800)409-6080 (4096080@skytel.com)
Billerica, MA 01821 fax: (978)670-8145
------------------------------
Date: 20 May 1998 19:58:43 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Function syntax with prototyping, filehandles and arrays
Message-Id: <6jvclj$i47$2@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Marc.Haber-usenet@gmx.de (Marc Haber) writes:
:So they actually aren't good for early mistype detection?
Pretty much.
:It isn't an @ because I would like to have the chance to add a second
:array at a later time. I tried the *, it didn't work.
You misunderstand what @ is. It's not an array in a prototype.
It's a list. \@ is a pass-by-implicit-reference array, which is
different.
:Are the prototypes really that different from the prototype concept we
:know from other languages?
Absolutely. Here's a Perl Cookbook draft excerpt.
--tom
Creating Function Prototypes
Problem
You want to use function prototypes so the compiler can check your
argument types.
Solution
Perl has something of a prototype facility, but it isn't what you're
thinking. Perl's function prototypes are more a kind of context coercion
used to write functions that behave like some of Perl's builtins, such
as `push' and `pop'.
Discussion
Manually checking the validity of a function's arguments can't happen
until runtime. If you make sure the function is declared before it
is used, you can tickle the compiler into using a very limited form
of prototype checking to help you here. Please don't confuse Perl's
function prototypes with those found in any other language. Perl
prototypes serve only to emulate the behavior of built-in functions.
A Perl function prototype is enclosed in parentheses after the
subroutine definition name. It consists a string of any of the Perl
type characters, ```$@%&*'''. You can add spaces for legibility and
backslashes to mean that should be passed by implicit reference. Any
backslashed prototype character must be passed something starting
with that character. Any unbackslashed ``@'' or ``%'' eats all
the rest of the arguments, and forces list context. An argument
represented by ``$'' forces scalar context. An ``&'' requires an
anonymous subroutine, and ``*'' does whatever it has to turn the
argument into a reference to a symbol table entry. A semicolon
separates mandatory arguments from optional arguments.
If you provide an empty prototype, the function cannot be passed any
arguments, just like the built-in function `time'. It also makes
the function a potential candidates for inlining. If the result
after optimization and constant folding is either a constant or a
lexically- scoped scalar with no other references, this value will
be used in place of function calls made without `"&"' or the obsolete
`do' operator.
Let's make a function that takes two arrays of numbers and returns a new
list where each element is the sum of the corresponding elements of the
two input lists. That subroutine definition would look like this:
sub add_vecpair( \@ \@ ) { ....
Make sure that that definition is seen by the compiler before it
compiles any calls to the function. Once this is done, the function can
(and must) then be called this way:
@c = add_vecpair(@a, @b);
Actually, once any function's definition has been seen by the compiler,
you don't need to use the parentheses on the call. This is the same
thing:
@c = add_vecpair @a, @b;
Neither of these calls looks as though it's passing array references
in, but because of the prototype, they are. The compiler adds the
backslashes for you. This can be annoying at times, such as when
one of the elements isn't a literal array. For example, under the
prototype, this call is technically illegal, even though it would
appear fine:
@c = add_vecpair(@a, [ values %hash ]); # prototype conflict
This is where you find yourself fighting with the fastidious prototype.
Here's how to make it shut up:
@c = add_vecpair(@a, @{ [ values %hash ] } );
Not very pretty, eh? It's the same kind of thing you have to do when you
use a prototyped built-in in ways it's not expecting. For example,
if ($x > 10) {
push @a, $value;
} else {
push @b, $value;
}
Cannot be written as
push $x > 10 ? @a : @b , $value;
But instead requires a rather less obvious indirect approach. The
extra backslash and `@{}' dereferencing are there to keep the `push'
function's formal prototype from complaining unnecessarily.
push @{ $x > 10 ? \@a : \@b }, $value;
If the function in question is user-defined instead of built-in,
you can disable the compiler's mettlesome prototype checking by
prefixing the function call with an ampersand. You'll just have to
make sure the types on the call are right yourself then. For example:
@c = &add_vecpair(\@a, [ values %hash ]); # `&' ignores prototype
Our advice is to avoid prototypes in most if not all situations. If
the preceding sequence isn't enough to convince you, think about
this: by enforcing prototypes, you've broken the beautiful model of
functions built to take or return any number of arguments. It would
have been more robust to have written the function to accept any
number of array references, and sum up the corresponding elements of
each. The extra backslash and `@{}' dereferencing are there to keep
the overly picky prototype checks from carping unnecessarily. You'll
just have to make sure the types on the call are right yourself
then. For example:
sub add_vecs {
my($vec, @result);
foreach $vec (@_) {
for (my $i = 0; $i < @$vec; $i++) {
$result[$i] += $vec->[$i];
}
}
return @result;
}
@sumvec = add_vecs(\@a, \@b, \@c, \@d);
One more technique: if the `add_arefs' function definition has
been seen before the call to the function, you can factor out the
backslash by taking advantage of that operator's distributive
property. Precede the parameter list with a backslash to apply
the backslash to each argument. If you want to do this before the
function has been declared, you must pre-declare it with a forward
reference or add another level of parentheses:
@sumvec = add_arefs(\@a, \@b, \@c, \@d); # pass all by reference
@sumvec = add_arefs(\(@a, @b, @c, @d)); # pass all by reference
sub add_arefs; # forward reference of function
@sumvec = add_arefs\(@a, @b, @c, @d); # same thing, but cleaner
The best place for prototypes is to emulate a built-in. The built-in
array and hash manipulation functions are prototyped to take
references to their aggregates so they can change them. Here's an
hpush() function that works like `push', but on hashes. It ``appends''
a list of key-value pairs to an existing hash, overwriting previous
contents for those keys.
sub hpush(\%@) {
my $href = shift;
while ( my ($k, $v) = splice(@_, 0, 2) ) {
$href->{$k} = $v;
}
}
hpush(%pieces, "queen" => 9, "rook" => 5);
--
There is no problem so small that it can't be blamed on Datakit --Andrew Hume
------------------------------
Date: Wed, 20 May 1998 14:59:25 -0400
From: Arthur Dardia <ahdiii@webspan.net>
Subject: Re: Help please...
Message-Id: <3563280D.4C844CD3@webspan.net>
Ahm...okay, well, first of all you might need cgi-lib.pl or CGI.pm. Maybe
people prefer CGI.pm over cgi-lib.pl. Then, if you use cgi-lib.pl you'll
have to make a form in .html that is defined like so:
<form action="http://www.myserver.com/cgi-bin/myscript.pl"
method=post">
Then, in the .pl script, you'll have to ReadParse(); and fixCGI(); the
information submitted by the form to the perl script. Make sure you use
fixCGI() instead of FixCGI(); because FixCGI(); is a function that is defind
in the module. I had a friend write a sub for me that he called fixCGI()
which is slightly different (according to my friend).
sub fixCGI
{
foreach $str (@in)
{
$newstr = "";
@tmp = split(//, $str);
for ($i=0; $i<=$#tmp; $i++)
{
if ($tmp[$i] eq "%")
{
$rep = chr(hex($tmp[$i+1] . $tmp[$i+2]));
$i += 2;
}
else
{$rep = $tmp[$i];}
$newstr = $newstr . $rep;
}
$str = $newstr;
}
}
Example:
Pretend Susan filled in the form with "Michaels" for the surname field.
In the .pl script, you can access this data as $in{surname} being that the
surname field in the .html field is defined as:
<input name="surname" size=40>
Then, you'd need an error sub, such as the following:
sub error {
($message) = @_;
print("<b>ERROR:</b><br>",
$message,
"<br><br>Contact the webmaster with the above error message,
unless you can
fix it yourself.\n");
exit(0);
}
Also, you'd need if statements for all of the fields, like:
if ( ! $in{surname} ) {
&error("Missing field: surname.");
}
The error sub and the if statement will make sure that a user fills in all
fields. You'll need to duplicate the if statement replacing "surname" in
both occurences with the name of the field.
Now, that you have the data from the .html form, you can now make another
sub routine, that when called, will write all of the information into the MS
Access file that you specify. I hope this helps. Reply to my email address
if you have any other questions.
Arthur Dardia
PS - I suggest getting the book entitled "Learning Perl, 2nd Edition." I
was a newbie like you about 2 weeks ago, but now I'm getting better and have
written 4 perl scripts that can add and delete news to my gaming page by
only filling out a .html form instead of editing the .html, and reuploading.
Dimce H wrote:
> Hello people how are you?
> I wanted to ask anyone if they could help me with a major assignment of
> mine. I am struggling big time. I have to write a Perl script that gets
> data from a browser and inserts it into a database. I dont know where
> to start. For example do I need a separate HTML form, and if so, how
> will the input of the form be passed onto the script? Does it matter
> which Windows server I run on my NT machine? Which win32 extensions do I
> need to install? Any other special applications? How would I start this
> script? Any ideas? Have you got any scripts similar to this one? It is
> supposed to take the Name, Surname, Student number (for validation),
> Subject name and a mark for that subject, and then store them into a
> database (possibly MS Access). It sounds fairly simple but to a newbie
> this is an extremely difficult task. Can I get my hands on a script like
> this one anywhere on the net?
>
> Please, please help me if you can if have a spare minute to look into it
> and help me out heaps.
>
> Thanking you kindly,
> DimCe
------------------------------
Date: 20 May 1998 19:47:52 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Inter-process file arbitration?
Message-Id: <6jvc18$i47$1@csnews.cs.colorado.edu>
In comp.lang.perl.misc, "Jeremy Goldberg"
:But the open will fail if another process is writing to it!
Stop lying. The only system that would do that would be one designed to
make multitasking idiocruddyotic. Sounds like Martian programming,
a queer notion at best, and evil and broken one in all probability.
--tom
--
"You can only measure the size of your head from the inside." --Larry Wall
------------------------------
Date: Wed, 20 May 1998 13:25:55 -0700
From: "Larry Rosler" <lr@hpl.hp.com>
Subject: Re: Inter-process file arbitration?
Message-Id: <6jve8t$p5p@hplntx.hpl.hp.com>
Mark-Jason Dominus wrote in message <6jv7in$p3j$1@monet.op.net>...
>
>>"Jeremy Goldberg" <jgoldberg@dial-but-dont-spam.pipex.com>:
>> >P.S. Does flock() only work AFTER you've opened a file?
>
>In article <6jupgg$cii@bsd1.ilse.net>, robert <robert@il.fontys.nl>
wrote:
>>[Much useful advice omitted.]
>>Yes, since it works on filedescriptors (so you have to immediately
lock the
>>file after opening it).
>
>Often this is inconvenient. For instance, in the example you showed,
>the program erases the file's contents before it obtains the lock;
>this might be incorrect.
>
>In many cases, it's useful to maintain a separate empty file whose
>only purpose is to be locked. Then you might do:
...
This technique works fine on Unix-based systems. However, flock is not
implemented by the commercial perl that I must use on the Windows NT
system I must port to. (The version information is reproduced below.)
Instead, I use the deprecated (in perlfaq5) technique of testing for the
existence of a lockfile, waiting if necessary until it goes away, and
then creating it. To avoid the disastrous race condition, I do this
sequentially on two separate lockfiles, which reduces the probability of
a race to insignificant. (At a guess, (10 ** -4) ** 2 = 10 ** -8 chance
of catastrophe, which I can live with.)
However, creating and destroying two files for each short CGI process
execution is wasteful compared to the flock approach using an existing
lockfile. Does someone have a better solution -- for example, using
fcntl, which this perl supports? (I need also to implement the solution
in C, where the filesystem overhead would be even more significant.) I
am not permitted to upgrade this perl to 5.004 or to install a module
such as File::Lockf from CPAN (which claims to be implemented only for
Solaris == Unix).
Any advice about this, or about a similar porting issue with respect to
the 'alarm' function for managing time-outs?
********************
Microsoft(R) Windows NT(TM)
(C) Copyright 1985-1996 Microsoft Corp.
I:\>perl -e "flock IN, 2"
The flock() function is unimplemented at -e line 1.
I:\>perl -v
This is perl, version 5.003 with DEBUGGING MULTIPLICITY
built under Windows_NT at Sep 24 1997 00:36:07
+ suidperl security patch
Copyright 1987-1996, Larry Wall
Win32 port Copyright 1996 by Mortice Kern Systems Inc.
MKS version 6.1 build 209
Perl may be copied only under the terms of either the Artistic License
or the
GNU General Public License, which may be found in the Perl 5.0 source
kit.
********************
--
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com
------------------------------
Date: Wed, 20 May 1998 15:36:28 -0400
From: Douglas Cordero <dcordero@giss.nasa.gov>
Subject: Newbie package hash ???
Message-Id: <356330BC.41C6@giss.nasa.gov>
Hi all:
I am going crazy with this one. My apologies if this
is wasting group time/space/energy.
I have a module containing a hash like so:
package Silo;
%DTYPES = qw( d1 D100 d2 D200 );
...
Now in the main perl program, I am trying to access the
hash with a valid key:
...
my $type = 'd2';
my $temp = "Silo::%DTYPES{$type}";
print "temp = $temp\n";
...
This prints:
temp = Silo::%DTYPES{d1}
How do I get it to dig into the hash and make $temp=D100 ??
Thx and best,
Doug C.
------------------------------
Date: 20 May 1998 20:01:09 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Newbie package hash ???
Message-Id: <6jvcq5$qqr@news-central.tiac.net>
In article <356330BC.41C6@giss.nasa.gov>,
Douglas Cordero <dcordero@giss.nasa.gov> wrote:
>I have a module containing a hash like so:
>
>package Silo;
>
>%DTYPES = qw( d1 D100 d2 D200 );
>Now in the main perl program, I am trying to access the
>hash with a valid key:
>
>...
>
>my $type = 'd2';
>my $temp = "Silo::%DTYPES{$type}";
>print "temp = $temp\n";
my $temp =$Silo::DTYPES{$type};
is what you want, the combination of a leading $ and a key enclosed in {}s
says you're getting a scalar value out of the hash.
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@colltech.com | Collective Technologies (work)
------------------------------
Date: Wed, 20 May 1998 20:22:25 GMT
From: jdporter@min.net (John Porter)
Subject: Re: Newbie package hash ???
Message-Id: <MPG.fcd06fcfedde8709896e2@news.min.net>
On Wed, 20 May 1998 15:36:28 -0400,
in article <356330BC.41C6@giss.nasa.gov>,
dcordero@giss.nasa.gov (Douglas Cordero) wrote:
>
> I am going crazy with this one. My apologies if this
> is wasting group time/space/energy.
Not at all ;-)
> package Silo;
> %DTYPES = qw( d1 D100 d2 D200 );
>
> Now in the main perl program, I am trying to access the
> hash with a valid key:
>
> my $type = 'd2';
> my $temp = "Silo::%DTYPES{$type}";
>
> How do I get it to dig into the hash and make $temp=D100 ??
Well, they don't get much newbier than this, do they.
But it's a good question.
You've gathered that the namespace location of a variable
may be explicitly qualified by putting the full qualification
on the name. But what you didn't expect is that the
special prefix character ($,@,%) is always the very first
character. In fact, it's not really part of the name.
(Well, it's a *different* part of the name...)
So what you really want is:
my $temp = $Silo::DTYPES{$type};
"Wait," you're saying, "Why dja put a $ in front instead of
a %, if Silo::DTYPES is a hash?"
Well, as anyone who's read perldata knows, %DTYPES refers
to the whole hash, i.e. the variable itself, but
$DTYPES{$key} is used to access any specific value contained
in the hash -- since values of a hash are scalars, and $
means scalar. That's good, since you're assigning it to
$temp, a scalar variable.
By the way, why did you quote "$Silo::DTYPES{$type}"?
That is a "useless use of interpolation into a string".
hth,
John Porter
------------------------------
Date: 20 May 1998 19:47:58 GMT
From: beatle@arches.uga.edu (Benjamin Dixon)
Subject: Perl forking
Message-Id: <6jvc1e$fq8$1@cronkite.cc.uga.edu>
Could someone please explain to me how I can start two processes such that
they run simultaneously. What I am trying to do is make mp3s from my CD
collection. To automate this a bit, I wrote a simple perl script to create
the directories and encode the mp3s, rip the CDs, etc. But as is, it first
rips the CD, then encodes as mp3. What I would like for it to do is rip
the first song, then begin ripping the second song while at the same time
mp3ing the first song. I have two system calls to dagrab (cd ripper) and
8hz (mp3 ripper). I tried to fork the two but with no such luck. I've
looked in the faq and in "Learning Perl" as well as
the Perl man pages and reference guide but I haven't found a good
explaination of what I want anywhere. As I understand it, a call to system
is the same as a call to fork and exec? Any help or pointers to help would
be greatly appreciated.
Ben
--
******************************************************************************
Benjamin R. Dixon, jr.
UCNS Student Consultant
http://www.arches.uga.edu/~beatle
beatle@arches.uga.edu
------------------------------------------------------------------------------
------------------------------
Date: Wed, 20 May 1998 16:31:15 -0400
From: Arthur Dardia <ahdiii@webspan.net>
Subject: Re: Perl forking
Message-Id: <35633D92.D7B0B896@webspan.net>
Sounds like a cool perl script, too bad I don't know how to help you. :)
Arthur Dardia
Benjamin Dixon wrote:
> Could someone please explain to me how I can start two processes such that
> they run simultaneously. What I am trying to do is make mp3s from my CD
> collection. To automate this a bit, I wrote a simple perl script to create
> the directories and encode the mp3s, rip the CDs, etc. But as is, it first
> rips the CD, then encodes as mp3. What I would like for it to do is rip
> the first song, then begin ripping the second song while at the same time
> mp3ing the first song. I have two system calls to dagrab (cd ripper) and
> 8hz (mp3 ripper). I tried to fork the two but with no such luck. I've
> looked in the faq and in "Learning Perl" as well as
> the Perl man pages and reference guide but I haven't found a good
> explaination of what I want anywhere. As I understand it, a call to system
> is the same as a call to fork and exec? Any help or pointers to help would
> be greatly appreciated.
>
> Ben
> --
> ******************************************************************************
> Benjamin R. Dixon, jr.
> UCNS Student Consultant
> http://www.arches.uga.edu/~beatle
> beatle@arches.uga.edu
>
> ------------------------------------------------------------------------------
------------------------------
Date: Wed, 20 May 1998 16:00:46 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Perl terminology
Message-Id: <3563366E.EE4B3ED9@matrox.com>
Jon Walsh wrote:
> Tom Christiansen <tchrist@mox.perl.com> writes:
>
> > [courtesy cc of this posting sent to cited author via email]
> >
> > In comp.lang.perl.misc,
> > Jon Walsh <prophet@skepticult.org> writes:
> > :The Waite Group's Perl 5 book assumes no prior knowledge
> >
> > I think that's misrepresentative.
>
> Really? It got me started nicely. It covers the basics of programming
> on your way to learning perl, which seems to be what was asked for.
I stumbled upon that book during my earlier Perl-learning days. I must say
that it covers the basics and goes on to cover a lot of the more advanced
stuff. What I liked most about it is the abundance of examples, something the
Camel Book lacks. Unfortunately though, I have discovered WAY too many
mistakes in the example code they present. But, overall, I think it's a good
reference.
--
Ala Qumsieh | No .. not just another
ASIC Design Engineer | Perl Hacker!!!!!
Matrox Graphics Inc. |
Montreal, Quebec | (Not yet!)
------------------------------
Date: Wed, 20 May 1998 09:07:08 -1000
From: Jeff & Rebecca Jo Isom <jeffyjo-isom@worldnet.att.net>
Subject: perl variables
Message-Id: <6jv9e8$23t@bgtnsc02.worldnet.att.net>
Is there a way to check the contents of a variable to see if it contains
a specific character?
For example if I have a variable from a form that stores an email
address and I want to make sure the variable contains a @. How would I
accomplish this?
Thanks
Jeff Isom
------------------------------
Date: 20 May 1998 19:21:39 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: perl variables
Message-Id: <6jvag3$qqr@news-central.tiac.net>
In article <6jv9e8$23t@bgtnsc02.worldnet.att.net>,
Jeff & Rebecca Jo Isom <jeffyjo-isom@worldnet.att.net> wrote:
>Is there a way to check the contents of a variable to see if it contains
>a specific character?
>
>For example if I have a variable from a form that stores an email
>address and I want to make sure the variable contains a @. How would I
>accomplish this?
One way to do it is to say
if (index ($var, '@') >= $[) {
...
}
the documentation pages called perlfunc and perlvar describe the index
function and what the odd looking $[ variable are.
perldoc perlfunc
is the way I usually view the documentation.
Note that I've only shown how to see if there's an @ in the variable, not
where it is or whether it's a sensible email address. For good reasons,
which can be discovered by visiting www.dejanews and rummagaing around :-)
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@colltech.com | Collective Technologies (work)
------------------------------
Date: 20 May 1998 20:23:18 GMT
From: ameyer@NoSPAMix.netcom.com (Alan Meyer)
Subject: Problem de-referencing a reference to a typeglob stored in a hash
Message-Id: <6jve3m$f89@sjx-ixn5.ix.netcom.com>
I encountered some unusual behavior in Perl for which I can't
account. Am I doing something wrong?
Assume that a text file exists named "xxx". This code will open the
file, store a reference to the typeglob of the file handle in variable
$x, and then dump the file to the screen.
open FOO, "<xxx" or die "foo $!";
$x = \*FOO;
while (<$x>) {
print;
}
It works fine.
The following code is identical in every respect except that instead of
storing the reference in a plain scalar, it stores it in a member of a
hash. Yet it doesn't work. I tried it on ActiveStates's NT Perl 5.007
build 316, and on another NT Perl, and on Solaris. In each case nothing
is dumped to the screen.
open FOO, "<xxx" or die "foo $!";
$x{FH} = \*FOO;
while (<$x{FH}>) {
print;
}
What's the difference? Why should the expression <$x{FH}> behave differently
from <$x> ???
Amazingly (to me), the following code works around the problem.
open FOO, "<xxx" or die "foo $!";
$x{FH} = \*FOO;
$y = $x{FH};
while (<$y>) {
print;
}
Anyone have any ideas?
Thanks.
--
Alan Meyer
AM Systems, Inc
Randallstown, MD
ameyer@NoSPAMix.netcom.com
(Please remove NoSPAM from address for email)
------------------------------
Date: Wed, 20 May 1998 15:07:41 -0400
From: Arthur Dardia <ahdiii@webspan.net>
Subject: Re: Run .pl or .cgi under Win95
Message-Id: <356329FD.4736E276@webspan.net>
You'll need a web server, try getting Apache. It's one of the best.
http://www.apache.org
To configure it for CGI, you'll need to edit the .conf files.
Specifically the smf.conf (/me hopes he spelled it right.)
Arthur Dardia
unique wrote:
> I need help on running a perl script under a browser/Win95 .
>
> What I am trying to do is to use Perl as a CGI to dynamically create a
> "HTML" type output as stdout to be accepted by a browser!
>
> Thanks a lot!
------------------------------
Date: 20 May 1998 20:04:07 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Run .pl or .cgi under Win95
Message-Id: <6jvcvn$spn$1@marina.cinenet.net>
unique (unique@net-lynx.com) wrote:
: I need help on running a perl script under a browser/Win95 .
:
: What I am trying to do is to use Perl as a CGI to dynamically create a
: "HTML" type output as stdout to be accepted by a browser!
I'm sorry, this is simply impossible. Many have tried to do this, but
none have succeeded. Perl is entirely unsuited to this task. Do yourself
a favor and stop trying.
[Obligatory <sarcasm> flag]
Seriously, what's your actual question here? To write HTML to stdout from
Perl, you...write HTML to stdout from Perl, usually with a Content-type
prepended in the CGI case.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: 20 May 1998 20:43:49 GMT
From: ameyer@NoSPAMix.netcom.com (Alan Meyer)
Subject: Re: Running Perl on Windows
Message-Id: <6jvfa5$f89@sjx-ixn5.ix.netcom.com>
In article <355eab87.2530398@news.demon.co.uk>, steven@amber.co.uk wrote...
>
>genfil@my-dejanews.com wrote:
>
>>I need help!
>>I write perl scripts on unix and now I have to write scripts on NT and
>>Win95.
>>Is there an equivalent of "#!/usr/bin/perl" on NT and Win95?
>>Thank you!
Making a file extension association in NT sort of works, but I have
found that in some circumstances it doesn't work correctly. Unfortunately
I can't remember what they are.
One simple, dumb, technique that has always worked for me is to make a
batch file in parallel with the perl script.
If the script is "foo.pl", you can make a file named "foo.bat" with
the following contents:
{perlpath}\perl {foopath}\foo.pl $1 $2 $3 $4 $5 $6 $7 $8 $9
Plain "foo" runs the program, passing it however many command line arguments
there are up to 9 of them.
--
Alan Meyer
AM Systems, Inc
Randallstown, MD
ameyer@NoSPAMix.netcom.com
(Please remove NoSPAM from address for email)
------------------------------
Date: 20 May 1998 15:40:53 -0400
From: Joe Marzot <gmarzot@baynetworks.com>
Subject: Re: SNMP and Perl
Message-Id: <pdbtsspw6y.fsf@baynetworks.com>
Default Shell User <cmeena@hotmail.com> writes:
>
> Hi all,
>
> I am trying to write a perl script that uses snmp polling commands
> snmpwalk and snmpget. But I get a bunch of garbage as output. Is there
> any specific snmp library for perl.
>
> Any help would be appreciated.
you know what they say about computers - GIGO :)
try
ftp://ftp.corpeast.baynetworks.com/netman/snmp/perl5/SNMP-1.7.tar.gz
this version works with ucd-snmp-3.3.1
ftp://ftp.ece.ucdavis.edu/pub/snmp/ucd-snmp-3.3.1.tar.gz
cheers, GSM
>
> thanks
>
--
G.S. Marzot email: gmarzot@baynetworks.com
Bay Networks Inc. voice: (978)670-8888 x63990
600 Tech Park M/S BL60-101 pager: (800)409-6080 (4096080@skytel.com)
Billerica, MA 01821 fax: (978)670-8145
------------------------------
Date: Wed, 20 May 1998 20:34:30 GMT
From: armitage21@my-dejanews.com
Subject: string comparisons
Message-Id: <6jveon$gcv$1@nnrp1.dejanews.com>
Can someone help me out and tell me how I should go about comparing strings
using PERL? Thanks!
danny
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Wed, 20 May 1998 20:06:27 +0200
From: Jochen Wiedmann <joe@ispsoft.de>
Subject: suid problem
Message-Id: <35631BA3.6D8CA29F@ispsoft.de>
Hello,
a not so much Perl related problem, but it appears in a Perl script,
so I'll put it into this group. :-)
I have a suid script that ought to administrate a set of text files.
Any text file has a number of users associated with it that are
allowed to modify the text file. The idea is that users may do a
suidscript <filename>
where suidscript checks whether the user is permitted to modify
<filename> and if so, an editor is invoked.
Problem is, that all these editors typically have escape sequences
that allow to pass arbitrary commands to a shell: An obvious
security hole.
Any ideas how to fix this?
Thanks,
Jochen
--
Jochen Wiedmann joe@ispsoft.de
Linux - Just do it! 07123 14887
------------------------------
Date: Wed, 20 May 1998 15:10:03 -0400
From: Arthur Dardia <ahdiii@webspan.net>
Subject: Re: Trying to install a module ...
Message-Id: <35632A8A.E970A511@webspan.net>
Get File-Manifest-1.06.tar.gz.
Arthur Dardia
Yuri Shtil wrote:
> I downloaded Include-1.02a from a SPAN site and followed the installation
> instructions in README:
>
> ----------------------------------------------------------------
>
> perl Makefile.PL
> Can't locate ExtUtils/Manifest.pm in @INC at Makefile.PL line 5.
> BEGIN failed--compilation aborted at Makefile.PL line 5.
>
> ----------------------------------------------------------------
>
> Any idea ? This is the first time I tried to install a module.
>
> What am I doing wrong ?
>
> YS
------------------------------
Date: Wed, 20 May 1998 14:56:44 -0400
From: Jim Michael <jim.michael@gecm.com>
Subject: What is wrong with this FileHandle code?
Message-Id: <3563276C.39E2@gecm.com>
This is based on code in the blue Camel, p. 441 and the online docs
(perldoc FileHandle):
#!/usr/bin/perl -w
use FileHandle;
$fh = new FileHandle;
if ($fh->open "f1.txt") {
print <$fh>;
undef $fh;
}
Here is the error message I receive under Linux and NT:
----
String found where operator expected at merge.pl line 4, near "->open
"f1.txt""
(Missing operator before "f1.txt"?)
syntax error at merge.pl line 4, near "->open "f1.txt""
Execution of merge.pl aborted due to compilation errors.
----
I must be overlooking something obvious?
Cheers,
Jim
------------------------------
Date: Wed, 20 May 1998 15:33:48 -0400
From: Arthur Dardia <ahdiii@webspan.net>
Subject: Re: What is wrong with this FileHandle code?
Message-Id: <3563301C.45E7756@webspan.net>
I'm not familar with FileHandle, I just use Perl's generic open(). Try
adding parentheses, because Perl's requires it, so try this (I doubt it'd
work):
#!/usr/bin/perl -w
use FileHandle;
$fh = new FileHandle;
if ($fh->open("f1.txt")) {
print <$fh>;
undef $fh;
}
HTH,
Arthur Dardia
Jim Michael wrote:
> This is based on code in the blue Camel, p. 441 and the online docs
> (perldoc FileHandle):
>
> #!/usr/bin/perl -w
> use FileHandle;
> $fh = new FileHandle;
> if ($fh->open "f1.txt") {
> print <$fh>;
> undef $fh;
> }
>
> Here is the error message I receive under Linux and NT:
> ----
> String found where operator expected at merge.pl line 4, near "->open
> "f1.txt""
> (Missing operator before "f1.txt"?)
> syntax error at merge.pl line 4, near "->open "f1.txt""
> Execution of merge.pl aborted due to compilation errors.
> ----
>
> I must be overlooking something obvious?
>
> Cheers,
>
> Jim
------------------------------
Date: Wed, 20 May 1998 15:46:48 -0400
From: Jim Michael <jim.michael@gecm.com>
Subject: Re: What is wrong with this FileHandle code?
Message-Id: <35633328.1027@gecm.com>
Arthur Dardia wrote:
> I'm not familar with FileHandle, I just use Perl's generic open(). >Try
> adding parentheses, because Perl's requires it, so try this (I doubt >it'd
> work):
>
> #!/usr/bin/perl -w
> use FileHandle;
> $fh = new FileHandle;
> if ($fh->open("f1.txt")) {
> print <$fh>;
> undef $fh;
> }
OK, adding the parens worked. Neither example (perldoc or Camel) used
the parens. Thanks.
Cheers,
Jim
--
.
------------------------------
Date: Wed, 20 May 1998 14:53:10 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Where is warning about PERL 5.001?
Message-Id: <fl_aggie-2005981453100001@aggie.coaps.fsu.edu>
In article <35661958.2971797@news.jps.net>, brian@brie.com (Brian
Lavender) wrote:
+ I am looking for the warning regarding PERL 5.001. I remember it being
+ posted just about everywhere a year ago, but now I can't find it. Does
+ anyone know where it is? I even searched Deja News. I need to show
+ some evidence to get the people at my work to upgrade their version of
+ PERL.
Perhaps you're looking for <url:http://www.cert.org/>?
James
--
Consulting Minister for Consultants, DNRC
The Bill of Rights is paid in Responsibilities - Jean McGuire
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/CPAN-local/doc/FAQs/cgi/idiots-guide.html>
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 2650
**************************************