[7574] in Perl-Users-Digest
Perl-Users Digest, Issue: 1200 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 20 15:17:17 1997
Date: Mon, 20 Oct 97 12:00:28 -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 Mon, 20 Oct 1997 Volume: 8 Number: 1200
Today's topics:
Re: @ + @ = % but how? <bugaj@bell-labs.com>
Re: @ + @ = % but how? <Greg.Allen@csfp.co.uk>
Blank Space occurs after Search and Replace <bobm@tiac.net>
guestbook in "Learning Perl", 2nd Ed. (Michael L Denniston,CD108C SCIE,299-4097,3)
How do I match the first word in a string? (Brian Kendig)
Re: How do I match the first word in a string? (Mike Stok)
How to call sysopen (Vijay Veeranna)
Re: How to call sysopen (Honza Pazdziora)
Re: How to change user password?? <seay@absyss.fr>
Including variable file name (Vijay Veeranna)
Re: Including variable file name (Honza Pazdziora)
Re: Including variable file name <seay@absyss.fr>
Re: interprocess communcation for Win32 (Matthew H. Gerlach)
map or for : which is better in this case? <brian@criticalpath.net>
Re: Mind sucking, time wasting regex <mreimer@vpop.net>
Perl Bug Report <ghowland@hotlava.com>
Re: Perl Bug Report <cmargoli@world.northgrum.com>
PERL for DEC OSF/1 v3.0 <E.W.Drenth@research.kpn.com>
Re: Perl for Win95 (MCornelio)
Re: Perl GDBM and delete records rick@www.bpa.nl
Re: Pop up browser authentification dlg with perl???... (brian d foy)
resource for perl sql integration? <afrds2@microserve.net>
Re: Searching Perl(5) grammar (Greg Bacon)
Socket Question (Paul Ryder)
Re: Socket Question (Mike Stok)
Support for AIX <Bob_Fritz@pvn.com>
Re: Undef in my list -- syntax suggestion (Daniel S. Lewart)
Re: WebSite: How to get Perl to execute in Browser <afrds2@microserve.net>
Why this behaviour with complex data structure? <telka@nortel.ca>
Re: Why this behaviour with complex data structure? (Mike Stok)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 20 Oct 1997 07:32:41 -0400
From: Stephan Vladimir Bugaj <bugaj@bell-labs.com>
To: mailus@web-uk.com
Subject: Re: @ + @ = % but how?
Message-Id: <344B4159.79916578@bell-labs.com>
Richard Butcher wrote:
> I have an array:
> @startwith = ("a","b","c","d","e","f","g","h")
>
> How do I insert the first eight fields into a hash that looks like
> %result = "a","0","b","0","c","1","d","0","e","0","f","1","g","0","h","0")
> and then pick up the two other fields as $nine and $ten
>
> I know I can split each line into an array
> @fields = split(/;/,$line);
> and, if necessary, limit it to eight items
> but I don't know how to combine and then pick up the two leftovers.
>
I'd do it something like this (there may be some cool
shortcuts for doing this which I am unaware of...):
# $line = the ; delimited line you mention
@startwith = ("a","b","c","d","e","f","g","h");
chomp($line); #if you don't want the probable \n at the end of $line
#to wind up in $ten
@fields = split(/;/,$line);
$ten = pop(@fields);
$nine = pop(@fields);
$i = 0;
foreach $foo (@startwith)
{
$result{$foo} = $fields[$i];
$i++;
}
--
"Do computers think?"
------------------------------------------------------------------------
Stephan Vladimir Bugaj bugaj@bell-labs.com
Member of Technical Staff (908) 949-3875
Multimedia Communication Research Dept. Rm. 4F-601, Holmdel
Bell Labs of Lucent Technologies www.multimedia.bell-labs.com
PGP Key available from www.pgp.net/wwwkeys.html or your local keyserver.
Non-Lucent personal website located at www.cthulhu-dynamics.com/stephan.
------------------------------------------------------------------------
STANDARD DISCLAIMER: My opinions are NOT necessarily those of LUCENT.
------------------------------------------------------------------------
"Do submarines swim?" - E.W. Dijkstra
------------------------------
Date: Mon, 20 Oct 1997 19:01:03 +0100
From: Greg Allen <Greg.Allen@csfp.co.uk>
Subject: Re: @ + @ = % but how?
Message-Id: <344B9C5F.29E7@csfp.co.uk>
Stephan Vladimir Bugaj wrote:
>
> Richard Butcher wrote:
>
> > I have an array:
> > @startwith = ("a","b","c","d","e","f","g","h")
> >
> > How do I insert the first eight fields into a hash that looks like
> > %result = "a","0","b","0","c","1","d","0","e","0","f","1","g","0","h","0")
> > and then pick up the two other fields as $nine and $ten
> >
> > I know I can split each line into an array
> > @fields = split(/;/,$line);
> > and, if necessary, limit it to eight items
> > but I don't know how to combine and then pick up the two leftovers.
> >
I missed the original post, but once you've done the pop's, you can do:
%result = map( ($startwith[$_],$fields[$_]), 0..7 )
to sticks key,value pairs into the hash.
that would replace the foreach loop. Each iteration of the map returns a
two element list, note that you need the extra brackets here else map
won't be called with the arguments you want.
_____________________________________________________
Greg Allen
OTC Settlement Systems
Credit Suisse Financial Products
_____________________________________________________
------------------------------
Date: Mon, 20 Oct 1997 14:36:41 -0400
From: Bob Maillet <bobm@tiac.net>
Subject: Blank Space occurs after Search and Replace
Message-Id: <344BA4B9.AB4DAC9D@tiac.net>
In the script below, after the first line is writtine to the file each
remaining line starts with a blank space..Is there any way to eliminate
the blank space at the beginning of these lines? I am opening the file
twice because the search & replace is going to be part of an if
statement if this is a new text file.
$mcat = "C:/Perl/minorcat.txt";
open (FILE, $mcat);
@file = <FILE>;
close(FILE);
foreach (@file){
$_ =~ s/^\"//;
$_ =~ s/\"\n$/\n/;
open (MILE, ">$mcat");
print MILE "@file";
close(MILE);
}
Bob
------------------------------
Date: 20 Oct 1997 14:38:17 -0400
From: mdennist@dekalb.dc.peachnet.edu (Michael L Denniston,CD108C SCIE,299-4097,3)
Subject: guestbook in "Learning Perl", 2nd Ed.
Message-Id: <62g8ep$in0@dekalb.dc.peachnet.edu>
Hi
I am trying to modify the guestbook program given on p. 198 of the new
addition of Learning Perl by Schwartz & Christianson. I am concerned
about security for my cgi-bin directory which is being run under my user
name. Consequently I want to check for meta-characters and other nasties
being entered into my guestbook. The Perl syntax for the checking
routine is not a problem, I just cannot seem to find the right variable
to check. I suspect that I am not as familiar with some of the objects
used in this program as I ought to be.
The folks at O'Reilly suggested that I do this in lieu of e-mailing the
authors.
I appreciate any help that you can give. E-mail preferred.
MLD
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
<> Mike Denniston, Assoc Prof, Chemistry <>
<> DeKalb College CD1143 <>
<> 555 N. Indian Creek Dr., Clarkston, GA 30021 <>
<> Phone [404]-299-4097, 298-3913 FAX [404]-298-3833 <>
<> Email: mdennist@dekalb.dc.peachnet.edu <>
<> tarnhelm@fafner.dc.peachnet.edu <>
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
------------------------------
Date: Mon, 20 Oct 1997 17:39:57 GMT
From: bskendig@netcom.com (Brian Kendig)
Subject: How do I match the first word in a string?
Message-Id: <bskendigEID2EL.Bq@netcom.com>
This should be simple, but it's got me stumped. I'm trying to assign
the first word of a string to a variable, but it's not working. This code:
$foo = "Hi There";
($foo) =~ /^(\w+)/;
print "$foo\n";
outputs "Hi There" instead of "Hi". I've also tried these, individually:
$foo =~ /^(\w+)/;
($foo) =~ /^([^ ]+)/;
$foo ~= s/^(\w+)/\1/;
But, no luck with any of them; $foo remains unchanged. What am I doing
wrong?
--
_/_/_/ Be insatiably curious. Je ne suis fait comme aucun
/_/_/ Ask "why" a lot. de ceux que j'ai vus; j'ose croire
_/_/ n'etre fait comme aucun de ceux qui existent.
/ Brian Kendig Si je ne vaux pas mieux, au moins je suis autre.
/ bskendig@netcom.com -- Rousseau
http://people.netscape.com/brian/
------------------------------
Date: 20 Oct 1997 18:30:06 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: How do I match the first word in a string?
Message-Id: <62g7ve$pl2@news-central.tiac.net>
In article <bskendigEID2EL.Bq@netcom.com>,
Brian Kendig <bskendig@netcom.com> wrote:
>This should be simple, but it's got me stumped. I'm trying to assign
>the first word of a string to a variable, but it's not working. This code:
>
> $foo = "Hi There";
> ($foo) =~ /^(\w+)/;
> print "$foo\n";
>
>outputs "Hi There" instead of "Hi". I've also tried these, individually:
>
> $foo =~ /^(\w+)/;
> ($foo) =~ /^([^ ]+)/;
In all of these you match against $foo but don't capture the result
anywhere.
> $foo ~= s/^(\w+)/\1/;
>
>But, no luck with any of them; $foo remains unchanged. What am I doing
>wrong?
In this one you match the word at the beginning of the string and replace
it with itself (as an aside, you should use $1 on the right hand side of
the substitution, using -w will warn you about these things...)
You can say
($firstWord) = $foo =~ /^(\w+)/;
which will attempt to match $foo against the regex and make a list of the
parenthesised chunks of the regex. This list will then be used to assign
values into the list on the left of the = sign or undef if there aren;t
enough values. This leaves foo untouched, if you want to modify it in
place you might say
$foo =~ s/^(\w+).*/$1/s;
wherer the regex will attempt to match (and remember into $1) a string of
one or more \w characters at the front of $foo and any number (including
zero) of characters after that. Once the match is completed successfully
then whatever was matched is replaced by $1, if it fails (e.g. $foo
doesn't start with a \w character) then it's left untouched e.g.
DB<12> $foo = "Hello There\n"
DB<13> if ($foo =~ s/^(\w+).*/$1/s) {print "changed to $foo"}
changed to Hello
DB<14> $foo = " Hello There\n"
DB<15> if ($foo =~ s/^(\w+).*/$1/s) {print "changed to $foo"}
DB<16> X foo
$foo = ' Hello There
'
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@psa.pencom.com | Pencom Systems Administration (work)
------------------------------
Date: 20 Oct 1997 16:12:55 GMT
From: vv@romeo (Vijay Veeranna)
Subject: How to call sysopen
Message-Id: <62fvu7$fv4@cbisinet.cbis.com>
Perl verion : 5.004
Platform : Solaris 2.4
I am getting the error Undefined subroutine &main::sysopen called at ....
I am calling sysopen as below. What am I doing wrong?
$file=">/tmp/sql.lck";
use FileHandle;
$retn = sysopen(FH, "$file", O_RDWR|O_CREAT|O_EXCL, 0644) or die "can't open num
file: $file";
print " retn is $retn\n";
Thanks
vijay
------------------------------
Date: Mon, 20 Oct 1997 17:00:57 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: How to call sysopen
Message-Id: <adelton.877366857@aisa.fi.muni.cz>
vv@romeo (Vijay Veeranna) writes:
> Perl verion : 5.004
> Platform : Solaris 2.4
>
> I am getting the error Undefined subroutine &main::sysopen called at ....
> I am calling sysopen as below. What am I doing wrong?
There's probably something before this code that undefines the
sysopen. Do you get this error when you run only the piece of code?
> $file=">/tmp/sql.lck";
>
> use FileHandle;
> $retn = sysopen(FH, "$file", O_RDWR|O_CREAT|O_EXCL, 0644) or die "can't open num
> file: $file";
> print " retn is $retn\n";
Also, you probably do not want that ">" in the $file, when using
sysopen.
Hope this helps.
--
------------------------------------------------------------------------
Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
I can take or leave it if I please
------------------------------------------------------------------------
------------------------------
Date: Mon, 20 Oct 1997 18:44:50 +0200
From: Doug Seay <seay@absyss.fr>
To: Robert Nosko <robertn@dawid.com.pl>
Subject: Re: How to change user password??
Message-Id: <344B8A82.7CDA5D48@absyss.fr>
[posted and mailed]
Robert Nosko wrote:
>
> How can I change user password on Linux using CGI script??
You don't mean the /etc/passwd, do you? Do you really want to allow a
securety hole of this size? Why not just put the root password on your
home page and save everyone some hassle.
If you really want to go about doing this, you need to use
/usr/bin/passwd because it will handle shadow passwd files, formatting,
multiple access locking and whatnot. But passwd reads from the TTY
device directly, so you will need some sort of pseudo-tty driver in
there to make things happy. I've never done this, so I don't know how
hard it would be.
You could always play with crypt(3) (not the same as crypt(1)) and
modifying the passwd file directly. Root can read and write this file
like any other file.
- doug
------------------------------
Date: 20 Oct 1997 15:51:28 GMT
From: vv@romeo (Vijay Veeranna)
Subject: Including variable file name
Message-Id: <62fum0$fv4@cbisinet.cbis.com>
My require statement is a variable name and I am getting
compilation errors when I do the following:
$ENV_ROOT = = $ENV{'EMS_ROOT'};
require '$ENV_ROOT/bin/db_access.pl'
I am expecting it to substitute for the $ENV_ROOT
variable. Any suggestions will be greatly appreciated.
thanks
Vijay Veeranna
Analyst
Cincinnati Bell Information Systems
600 Vine St.
P.O. Box 1638 Cincinnati OH 45201
------------------------------
Date: Mon, 20 Oct 1997 16:55:17 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: Including variable file name
Message-Id: <adelton.877366517@aisa.fi.muni.cz>
vv@romeo (Vijay Veeranna) writes:
> My require statement is a variable name and I am getting
> compilation errors when I do the following:
>
> $ENV_ROOT = = $ENV{'EMS_ROOT'};
> require '$ENV_ROOT/bin/db_access.pl'
>
> I am expecting it to substitute for the $ENV_ROOT
> variable. Any suggestions will be greatly appreciated.
If you want the $ENV_ROOT to interpolate, you have to write
require "$ENV_ROOT/bin/db_access.pl";
Hope this helps.
--
------------------------------------------------------------------------
Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
I can take or leave it if I please
------------------------------------------------------------------------
------------------------------
Date: Mon, 20 Oct 1997 19:06:05 +0200
From: Doug Seay <seay@absyss.fr>
To: Vijay Veeranna <vv@romeo>
Subject: Re: Including variable file name
Message-Id: <344B8F7D.6E46A111@absyss.fr>
[posted and mailed]
Vijay Veeranna wrote:
>
> My require statement is a variable name and I am getting
> compilation errors when I do the following:
>
> $ENV_ROOT = = $ENV{'EMS_ROOT'};
> require '$ENV_ROOT/bin/db_access.pl'
'' strings don't expand variables. Change that to "" and you have a
much better chance of making perl happy. But this is only a guess as
you didn't give any warning messages.
- doug
------------------------------
Date: Mon, 20 Oct 1997 15:34:41 GMT
From: gerlach@netcom.com (Matthew H. Gerlach)
Subject: Re: interprocess communcation for Win32
Message-Id: <gerlachEICwLt.G4M@netcom.com>
In article <628qgp$1mr@runge.mit.edu> wjh@math.mit.edu (Jianhua Wang) writes:
>Hi all:
>
>I am a new perl5.0 User. I am trying to do the following things:
>
>1:launch a perl program
>2:create a child process
>3: communicate between the parent and the child process.
>
>how do I achieve this? I tried to use chat2.pl but it doesn't work in
>win32 because the "fork" doesn't work. Is there anyone who can help me?
>thanks in advance.
>
>jianhua
This is a fairly complicated thing to implement. Under Unix this is
usually done with pseudo-ttys. I hear Expect has been ported to winNT.
It doesn't use pseudo-ttys, but it is supposed to be able to talk to
other programs.
Matthew
------------------------------
Date: Mon, 20 Oct 1997 10:09:24 -0700
From: brian moseley <brian@criticalpath.net>
Subject: map or for : which is better in this case?
Message-Id: <344B9044.54BCCF4E@criticalpath.net>
ok. $list is a reference to an array of objects( which respond to a
header() method) and $hdr is a string; both $list and $hdr have been
passed into this particular sub.
i want to create a hash with key "value of this object's $hdr header"
and value "index of this object in @$list", such that i can create
@sorted_table = sort keys %table;
and then build a new sorted array of objects.
which of the below pieces of code is preferable, in terms of speed,
readability, and overall niceness?
candidate 1:
my %table;
for ( my $idx = 0; $idx < ( scalar @$list ); $idx++ ) {
my $val = $list->[$idx]->header( $hdr );
$table{$val} = $idx;
}
candidate 2:
my $idx = 0;
my %table = map {
$_->header( $hdr ), $idx++
} @$list;
--
* brian moseley *
{ agent of chaos => critical path }
------------------------------
Date: Mon, 20 Oct 1997 10:41:15 -0700
From: Matthew Reimer <mreimer@vpop.net>
Subject: Re: Mind sucking, time wasting regex
Message-Id: <344B97BB.93C45BD0@vpop.net>
I wrote in the original question asking for a tricky regex to pull
titles and HREFs out of a stream.
Thank you all for your solutions; I haven't tried them all yet. I really
want to use a single regex, because I want the same core code to work
with a lot of different regexs.
I ended up adding a feature like lookahead to perl to limit greediness;
(?$...) temporarily (for the duration of the current match) sets the end
of line to the first position that allows the regex argument of (?$...)
to match. E.g., a regex that works for the problem in my original post:
(?$.*?<A HREF.*?>).*<H3>(.*?)</H3>.*?<A HREF=(.*?)Full story</A>
This is roughly the same as splitting on <A HREF...>.
Make sense? Someone who really knows regexes (Friedl?) might suggest
better terminology, or a better implentation, but I think something like
this ought to be added to perl. It may not be the most efficient way,
but it allows things that aren't possible otherwise.
Matt
reljr@sigg.com wrote:
>
> You know, sometimes I just get stubborn and won't stop beating a dead
> horse. A regex question was posted Oct. 10 1997, and there were several
> answers posted, but I didn't like any of them (imagine that). So I posted
> an answer and later decided that I didn't like it either.
>
> I pondered the mystery of this regex beast until I got the answer today.
> One of my many thoughts about this regex is that I don't like the
> non greedy quantifier system in perl. There is no way to limit what it
> will look for on the righthand side of the expression except by limiting
> the total expression itself. To solve this regex so that it would pass
> all of the tests I was forced to place the *?)+ business into the regex.
>
> So what's my reason for posting? Hell I don't have any good reason for it
> except perhaps to ask if there isn't a better way to do this that will
> pass the string test below.
------------------------------
Date: Mon, 20 Oct 1997 17:01:26 +0100
From: Gary Howland <ghowland@hotlava.com>
Subject: Perl Bug Report
Message-Id: <344B8056.261@hotlava.com>
Here's a bug in Perl. Quite a nasty one too, since it changes values
for subsequent calls of a function:
use strict;
sub f
{
my $x = shift;
my $y = shift;
my $z = $y->{'1'} if defined $y;
$z = $x unless defined $z;
print "$x, $z\n";
}
f("a");
f("b");
I would expect the output:
a, a
b, b
but instead I get:
a, a
b, a
Gary
--
pub 1024/C001D00D 1996/01/22 Gary Howland <gary@hotlava.com>
Key fingerprint = 0C FB 60 61 4D 3B 24 7D 1C 89 1D BE 1F EE 09 06
------------------------------
Date: Mon, 20 Oct 1997 17:12:10 GMT
From: Charles Margolin <cmargoli@world.northgrum.com>
Subject: Re: Perl Bug Report
Message-Id: <344B90EA.5A8C@world.northgrum.com>
Gary Howland wrote:
>
> Here's a bug in Perl. Quite a nasty one too, since it changes values
> for subsequent calls of a function:
>
> use strict;
>
> sub f
> {
> my $x = shift;
> my $y = shift;
> my $z = $y->{'1'} if defined $y;
> $z = $x unless defined $z;
>
> print "$x, $z\n";
> }
>
> f("a");
> f("b");
>
> I would expect the output:
>
> a, a
> b, b
>
> but instead I get:
>
> a, a
> b, a
>
Not a bug. Your statement
my $z = $y->{'1'} if defined $y;
would do two things if it had been executed: declare the lexical
$z and set its value. Here it did neither, so $z is a package
"global" variable. It was set to "a" on the first call, so it
is still defined in the second call.
--
Charles G. Margolin DSSD Internal Information Services
cmargoli@world.northgrum.com Northrop Grumman Corp. 0624/23
margolin@acm.org Hawthorne, California 90250-3277
------------------------------
Date: Mon, 20 Oct 1997 14:50:24 GMT
From: "Erwin Drenth" <E.W.Drenth@research.kpn.com>
Subject: PERL for DEC OSF/1 v3.0
Message-Id: <01bcdd6f$dfb87f50$90c43f8b@l2690>
Can anyone tell me where I can find a perl version for DEC OSF/1 v3.0? I've
tried searching the Web, but that didn't get me anywhere.
Thanks in advance,
Erwin Drenth
------------------------------
Date: 20 Oct 1997 17:19:38 GMT
From: mcornelio@aol.com (MCornelio)
Subject: Re: Perl for Win95
Message-Id: <19971020171901.NAA23855@ladder02.news.aol.com>
I use perl2exe. It works with Perl for Win32 rel. 306. It generates
executables in the 550-600K range for small perl programs. I would guess that
it's about 550K + size of your sourcecode for deliverables.
I paid ~$25.00 for it ... downloaded it from http://www.demobuilder.com/
I think it works fine ...
Michael Cornelio
------------------------------
Date: Mon, 20 Oct 1997 10:04:58 -0600
From: rick@www.bpa.nl
Subject: Re: Perl GDBM and delete records
Message-Id: <877359131.21714@dejanews.com>
In article <6284no$aan$1@lyra.csx.cam.ac.uk>,
mjtg@cus.cam.ac.uk (M.J.T. Guy) wrote:
>
> In article <876922507.3728@dejanews.com>, <rick@www.bpa.nl> wrote:
> >Apparently deleting records from a GDBM hash within an each loop
> >does not work. It works for the FIRST record, but after deleting
> >that first record the each-loop exits. For a regular hash this does
> >work fine (deleting entries from a hash is explicitly permitted,
> >adding entries is not). Anyone a solution with GDBM?
>
> No it doesn't work for ordinary hashes. You just happened to get
> away with it, or didn't notice the error or something.
>
> From perldoc -f each:
>
> =item each HASH
> ... If you add or delete elements of a hash while you're
> iterating over it, you may get entries skipped or duplicated, so
don't.
>
> Note particularly that last sentence.
The Camel book (Perl 5) page 159 says about EACH:
"You must not add elements to the hash while iterating over it,
although you are permitted to use delete".
This example shows deleting records from an ordinary hash in an each
loop does work fine:
#!/bin/perl
$Data{1} = 1;
$Data{2} = 2;
$Data{3} = 3;
$Data{4} = 4;
$Data{5} = 5;
$Data{6} = 6;
$Data{7} = 7;
$Data{8} = 8;
print "Data after creation:\n";
while (($i,$v) = each %Data) {
print "$i $v\n";
}
# Delete index 4 and 6 and 1
delete($Data{4});
delete($Data{6});
delete($Data{1});
print "\n\nAfter delete index 4 and 6 and 1:\n";
while (($i,$v) = each %Data) {
print "$i $v\n";
}
# Delete all records
while (($i,$v) = each %Data) {
die "aargh!" if (! delete($Data{$i}) );
die "aaaargh2!" if (exists($Data{$i}));
}
print "\n\nAfter delete all remaing records:\n";
while (($i,$v) = each %Data) {
print "$i $v\n";
}
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Mon, 20 Oct 1997 14:06:15 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Pop up browser authentification dlg with perl???.....
Message-Id: <comdog-ya02408000R2010971406150001@news.panix.com>
In article <01bcdd60$fb1b4ac0$5a5c72c3@samir95>, "Samir" <soyouz1@easynet.fr> wrote:
> I had this sctipt:
>print "HTTP/1.0 401 Access Denied\n";
>print "WWW-Authenticate: Basic\n\n";
> I tried it, but nothing happens!!!
what header does your server actually return? HTTPeek [1] might be
helpful here :)
[1]
<URL:http://computerdog.com/httpeek/>
--
brian d foy <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)* <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
------------------------------
Date: Mon, 20 Oct 1997 11:03:57 -0400
From: Dave Stephens <afrds2@microserve.net>
Subject: resource for perl sql integration?
Message-Id: <344B72DD.5F73@microserve.net>
Does anyone know of a good on-line resource which
discusses the use of PERL scripts as front ends
for SQL database, specifically MS Access? My
employer wants to move to Access, but maintain
the same intranet forms I set up.
Thanks,
Dave Stephens
------------------------------
Date: 20 Oct 1997 16:43:09 GMT
From: gbacon@adtran.com (Greg Bacon)
To: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: Searching Perl(5) grammar
Message-Id: <62g1mt$4kj$1@info.uah.edu>
[Posted and mailed]
In article <97-10-092@comp.compilers>,
Randal Schwartz <merlyn@stonehenge.com> writes:
: You forgot "phase of the moon", "remaining supply of smoke for
: smoke-and-mirrors", and "relative Bacon number".
Does this mean that when I'm using perl, I'm allowed to use the "do what
I mean operator"? :-) (Besides, why would a self respecting Perl hacker
want to trace steps to Kevin when it's almost certain that he's never
hacked a punctuation of Perl in his life? :-)
Greg
--
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF
------------------------------
Date: Mon, 20 Oct 1997 16:12:27 GMT
From: paul@f1world.com (Paul Ryder)
Subject: Socket Question
Message-Id: <344b829a.28514882@news.u-net.com>
Hi,
I want to make a mail client, but need the lines that open a socket
connection to the server, and also how i can listen out for certain
stuff in the input from this socket.
Can anyone give me the standard lines of perl for opening a socket
connection and listening for input from this?
Thanks
_________________________________________________
Paul Ryder http://www.f1world.com
paul@pry.u-net.com ICQ : 262573
paul@f1world.com
paul@quake2.com
------------------------------
Date: 20 Oct 1997 18:48:46 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Socket Question
Message-Id: <62g92e$qst@news-central.tiac.net>
In article <344b829a.28514882@news.u-net.com>,
Paul Ryder <paul@f1world.com> wrote:
>I want to make a mail client, but need the lines that open a socket
>connection to the server, and also how i can listen out for certain
>stuff in the input from this socket.
>
>Can anyone give me the standard lines of perl for opening a socket
>connection and listening for input from this?
If you're going to talk to a POP server or an SMTP server and you're using
a reasonably recent perl (5.xxx) then I'd suggest you pick up the libnet
modules from CPAN (either go to http://www.perl.com and follow the CPAN
link or go to ftp://ftp.funet.fi/pub/languages/perl/CPAN ) This includes
POP3 and SMTP libraries whose documentation begins like this:
NAME
Net::POP3 - Post Office Protocol 3 Client class (RFC1081)
SYNOPSIS
use Net::POP3;
# Constructors
$pop = Net::POP3->new('pop3host');
$pop = Net::POP3->new('pop3host', Timeout => 60);
DESCRIPTION
This module implements a client interface to the POP3
protocol, enabling a perl5 application to talk to POP3
servers. This documentation assumes that you are familiar
with the POP3 protocol described in RFC1081.
A new Net::POP3 object must be created with the new
method. Once this has been done, all POP3 commands are
accessed via method calls on the object.
EXAMPLES
Need some small examples in here :-)
[...]
NAME
Net::SMTP - Simple Mail Transfer Protocol Client
SYNOPSIS
use Net::SMTP;
# Constructors
$smtp = Net::SMTP->new('mailhost');
$smtp = Net::SMTP->new('mailhost', Timeout => 60);
DESCRIPTION
This module implements a client interface to the SMTP and
ESMTP protocol, enabling a perl5 application to talk to
SMTP servers. This documentation assumes that you are
familiar with the concepts of the SMTP protocol described
in RFC821.
A new Net::SMTP object must be created with the new
method. Once this has been done, all SMTP commands are
accessed through this object.
The Net::SMTP class is a subclass of Net::Cmd and
IO::Socket::INET.
EXAMPLES
This example prints the mail domain name of the SMTP
server known as mailhost:
#!/usr/local/bin/perl -w
use Net::SMTP;
$smtp = Net::SMTP->new('mailhost');
print $smtp->domain,"\n";
$smtp->quit;
[...]
If you want to do the IPC yourself then you can start with the examples on
the perlipc man page:
Here's a sample TCP client using Internet-domain sockets:
#!/usr/bin/perl -w
require 5.002;
use strict;
use Socket;
my ($remote,$port, $iaddr, $paddr, $proto, $line);
$remote = shift || 'localhost';
$port = shift || 2345; # random port
if ($port =~ /\D/) { $port = getservbyname($port, 'tcp') }
die "No port" unless $port;
$iaddr = inet_aton($remote) || die "no host: $remote";
$paddr = sockaddr_in($port, $iaddr);
$proto = getprotobyname('tcp');
socket(SOCK, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";
connect(SOCK, $paddr) || die "connect: $!";
while (defined($line = <SOCK>)) {
print $line;
}
close (SOCK) || die "close: $!";
exit;
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@psa.pencom.com | Pencom Systems Administration (work)
------------------------------
Date: Mon, 20 Oct 1997 12:08:02 -0700
From: Bob <Bob_Fritz@pvn.com>
Subject: Support for AIX
Message-Id: <344BAC12.2102@pvn.com>
Recently I installed Perl in my AIX 4.1.4 environment as well as in my
AIX 3.2.5 environment. I also support one machine with AIX 4.2.1,
although I haven't installed Perl on that machine yet.
My question is does Perl have need to be rebuilt when I apply patches,
(PTF's), or do upgrades to the operating system?
------------------------------
Date: 20 Oct 1997 18:30:29 GMT
From: d-lewart@uiuc.edu (Daniel S. Lewart)
Subject: Re: Undef in my list -- syntax suggestion
Message-Id: <62g805$a3s$1@vixen.cso.uiuc.edu>
adelton@fi.muni.cz (Honza Pazdziora) writes:
> I wonder if anyone else also thinks that allowing undef in my
> definition would be nice to have. I do parsing of binary data and
> quite often I would need something like
> my ($a, undef, $b) = unpack "CCC", "ABC";
Try this:
my ($a, $b) = unpack "CxC", "ABC";
I do think that templates need more discussion in the documentation.
Daniel Lewart
d-lewart@uiuc.edu
------------------------------
Date: Mon, 20 Oct 1997 10:52:39 -0400
From: Dave Stephens <afrds2@microserve.net>
Subject: Re: WebSite: How to get Perl to execute in Browser
Message-Id: <344B7037.3686@microserve.net>
Go to windows explorer, choose VIEW --> OPTIONS --> FILE TYPE
Make sure the .pl extension is associated with perl.exe
AND that you have this character after the program "%1"
Example: c:\perl\perl5\perl.exe "%1"
Deborah Jean Schmid wrote:
>
> Howdy all.
> I have WebSite 1.1 running under Win95 and I can't get
> my perl scripts to run in the browser. I have the file
> type (.pl) opening with build 307 (CPAN). When I click
> on a script in Explorer, an ms-dos window pops up briefly
> and I can see the expected output.
>
> I checked the registry and I have the following set:
>
> HKEY_LOCAL_MACHINE\SOFTWARE\ActiveWare\Perl5
> Default "D:\dyanJen\Perl\bin"
> BIN "D:\dynaJen\Perl\bin"
> COMSPEC "D:\dynaJen\Perl\bin"
> HTML-DOCS "D:\dynaJen\Perl\docs"
> PRIVLIB "D:\dynaJen\Perl\lib"
>
> Not to mention the whole slew of items set by WebSite:
>
> HKEY_LOCAL_MACHINE\SOFTWARE\Denny\WebServer\CurrentVersion
> A zillion things here from the server properties (I presume).
>
> I have a feeling I'm missing something simple, but I've read
> FAQ's and such until my eyes are sore.
>
> Any ideas? Or, if there is a list of explicit steps one must
> take to get Perl to run, could you point me in that direction?
>
> Thanks.
> Tom Schmid
------------------------------
Date: Mon, 20 Oct 1997 13:51:47 -0400
From: Robert Telka <telka@nortel.ca>
Subject: Why this behaviour with complex data structure?
Message-Id: <344B9A33.74F5@nortel.ca>
Pardon me if this topic has already been beaten to death...
I've run into this rather interesting scenario, where I'm assigning
to a hash a key:value pair. The Key will consist of a department
number, the Value will be an array of names. Fairly trivial...
However, upon examining the hash, for every addition to the hash,
I find that 2 keys are added!
- one key is the department, having value reference to array
- second key is the reference of the array, value ???
Take a peek at the snipet and output included below.
Nonetheless, this is really confusing me! Is this standard default
Perl behaviour (v5.002 on HP-UX 10.10), or is it that I'm doing
something incorrectly? I was going to rely on the hash to give me
valid departments (ie. keys), however I may have to use a separate
array to store all the departments, and use the elements of the array
as indicies into my hash.
Comments anyone? Any help would be greatly appreciated!
Regards,
Robert Telka
------------
HP Operating Systems Analyst
Operating Systems Support, Nortel Technology
PO Box 3511, Station C, Ottawa, Ontario, Canada K1Y 4H7
External: (613) 765-5510 * Fax: (613) 763-3283 * Internal:
(39)-55510
================ begin snippet =======================
#!/usr/bin/perl
# Of course my real data doesn't live like this in the real world...
@depts = ("4Y", "4H", "4Y", "7Q");
@names = ("Telka", "Smith", "Ezust", "White");
%hash = undef;
for ($index = 0, $iteration = 1; $index < 4; $index++, $iteration++)
{ print "\n---------[ Iteration $iteration ]------------\n";
print "Processing $names[$index] who belongs to department
$depts[$index]\n";
# it the department doesn't exist, then add it and assign it
# an unamed array.
if (not exists $hash{$depts[$index]})
{ $hash{$depts[$index]} = [] ;
print "Hash has added an empty array for key $depts[$index]\n";
}
else # just print that we have found the department in our hash
{ print "Hash already has entry for key $depts[$index]\n";
}
# Add the name to the array which exists for a specific department
push(@{$hash{$depts[$index]}}, $names[$index]);
# Print all the key:value pairs our hash contains... and observe the
# problem I've run across...
foreach $key (%hash)
{ print "Key: $key\n\tValue: @{$hash{$key}}\n\n";
}
}
================== end snippet ========================
And here's a copy of the output:
> ./sample
---------[ Iteration 1 ]------------
Processing Telka who belongs to department 4Y
Hash has added an empty array for key 4Y
Key: 4Y
Value: Telka
Key: ARRAY(0x40021938)
Value:
---------[ Iteration 2 ]------------
Processing Smith who belongs to department 4H
Hash has added an empty array for key 4H
Key: 4H
Value: Smith
Key: ARRAY(0x4002195c)
Value:
Key: 4Y
Value: Telka
Key: ARRAY(0x40021938)
Value:
---------[ Iteration 3 ]------------
Processing Ezust who belongs to department 4Y
Hash already has entry for key 4Y
Key: 4H
Value: Smith
Key: ARRAY(0x4002195c)
Value:
Key: 4Y
Value: Telka Ezust
Key: ARRAY(0x40021938)
Value:
---------[ Iteration 4 ]------------
Processing White who belongs to department 7Q
Hash has added an empty array for key 7Q
Key: 7Q
Value: White
Key: ARRAY(0x4002198c)
Value:
Key: 4H
Value: Smith
Key: ARRAY(0x4002195c)
Value:
Key: 4Y
Value: Telka Ezust
Key: ARRAY(0x40021938)
Value:
------------------------------
Date: 20 Oct 1997 18:40:13 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Why this behaviour with complex data structure?
Message-Id: <62g8id$q8q@news-central.tiac.net>
In article <344B9A33.74F5@nortel.ca>, Robert Telka <telka@nortel.ca> wrote:
>Comments anyone? Any help would be greatly appreciated!
>%hash = undef;
This should probably be undef %hash or %hash = ()
> # it the department doesn't exist, then add it and assign it
> # an unamed array.
> if (not exists $hash{$depts[$index]})
> { $hash{$depts[$index]} = [] ;
> print "Hash has added an empty array for key $depts[$index]\n";
> }
> else # just print that we have found the department in our hash
> { print "Hash already has entry for key $depts[$index]\n";
> }
You don't have to do this, perl will do it for you...
> # Add the name to the array which exists for a specific department
> push(@{$hash{$depts[$index]}}, $names[$index]);
>
> # Print all the key:value pairs our hash contains... and observe the
> # problem I've run across...
> foreach $key (%hash)
here %hash expands to a list of alternating keys and values as it's in an
array context, so you'll see the keys *and* their values.
You could try this:
#!/usr/local/bin/perl -w
@depts = ("4Y", "4H", "4Y", "7Q");
@names = ("Telka", "Smith", "Ezust", "White");
%hash = ();
for ($index = 0, $iteration = 1; $index < 4; $index++, $iteration++) {
print "\n---------[ Iteration $iteration ]------------\n";
print "Processing $names[$index] who belongs to department $depts[$index]\n";
push @{$hash{$depts[$index]}}, $names[$index];
foreach $key (keys %hash) {
print "Key: $key\n\tValue: @{$hash{$key}}\n\n";
}
}
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@psa.pencom.com | Pencom Systems Administration (work)
------------------------------
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 1200
**************************************