[19586] in Perl-Users-Digest
Perl-Users Digest, Issue: 1781 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 20 14:05:36 2001
Date: Thu, 20 Sep 2001 11:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1001009110-v10-i1781@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 20 Sep 2001 Volume: 10 Number: 1781
Today's topics:
.htaccess & HTML forms <geoff@spiced.ham.fogcat.co.uk>
Re: ANNOUNCE: grepmail 4.51 released <newspost@coppit.org>
Re: ANNOUNCE: grepmail 4.51 released <epa98@doc.ic.ac.uk>
Re: Compile and install CPAN modules on win32 <nothing@nowhere.com>
Creating a file (Lorimer)
Re: Creating a file <jim@nothing.com>
Re: Creating a file <rogier@arpadrive-in.com>
Re: Creating a file <holland@origo.ifa.au.dk>
Re: Creating a file <stevea@wrq.com>
Re: DBI/MySQL help needed <abrenner@pitt.edu>
Re: Getting duration from start and and times and dates <dtweed@acm.org>
Getting duration from start and and times and dates (wi <bholness@nortelnetworks.com>
Re: Getting duration from start and and times and dates <mbudash@sonic.net>
Re: Getting duration from start and and times and dates (Tad McClellan)
Re: Getting duration from start and and times and dates <sb@mcasia.imperia.net>
h2xs and string constants in .h files <jrl@ast.cam.ac.uk>
Re: h2xs and string constants in .h files <nospam-abuse@ilyaz.org>
Hash problem... <guardian@chello.be>
Re: Hash problem... (Randal L. Schwartz)
Re: Hash problem... <guardian@chello.be>
Re: Hash problem... (Randal L. Schwartz)
Re: Hash problem... <guardian@chello.be>
Re: Hash problem... (Randal L. Schwartz)
How to recomple regular expression ? <addady@hotmail.com>
Re: How to recomple regular expression ? (Randal L. Schwartz)
Re: How to recomple regular expression ? <nothing@nowhere.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 20 Sep 2001 16:30:37 GMT
From: Geoff Smith <geoff@spiced.ham.fogcat.co.uk>
Subject: .htaccess & HTML forms
Message-Id: <Xns9122B21FF43A1IDFogcat9591fgps@62.253.162.107>
I have a .htaccess password protected directory on my site. As expected if
a user tries to access pages in that directory the browser throws up an
input box asking for the user ID and password.
But... I want to prompt for the username and password via a form on an HTML
page rather than letting the browser do it.
I know I could get the info and then re-direct to the page
http://user:password@www.site.com/directory
but that leaves the user id and password in the browser address bar.
Is there a nice little ready made script anywhere that will take the
entered information and re-direct to the approriate page with the correct
authetification already set?
--
_/_/_/ Nottingham Web Resources <http://www.nottingham.uk.net>
_/_/_/ Fogcat Computer Services <http://www.fogcat.co.uk>
------------------------------
Date: Thu, 20 Sep 2001 08:54:08 -0400
From: David Coppit <newspost@coppit.org>
Subject: Re: ANNOUNCE: grepmail 4.51 released
Message-Id: <3BA9E6F0.5060307@coppit.org>
Edward Avis wrote:
> David Coppit <newspost@coppit.org> writes:
>
>>While I'm at it, I'd like to raise some awareness that Perl code
>>isn't just about modules. This cross-posting, plus the lackluster
>>script archive on CPAN (still no tarballs, after all these years!)
>>indicate some sort of modules-only slant.
>
> Probably because when you write a script or program, it isn't as
> strongly associated with Perl. The user doesn't need to know Perl to
> use it, or even care what language it is implemented in. There's no
> real point, IMHO, to a collection of programs with no common feature
> other than that they are written in Perl. Except as a source of
> examples and inspiration.
[First, to be fair to Randal, the cross-post was an accident and does
not indicate some sort of "modules bias".]
I think "examples and inspiration" is a good enough reason. I *like* to
see how people implement things in Perl, both at the module and the
application level. I know that when I was starting to learn Perl, I was
desperately in need of examples. Unfortunately, modules have a lot of
extra cruft that can get in the way of a beginner's learning experience.
David
------------------------------
Date: 20 Sep 2001 18:20:14 +0100
From: Edward Avis <epa98@doc.ic.ac.uk>
Subject: Re: ANNOUNCE: grepmail 4.51 released
Message-Id: <xn91yl17p9t.fsf@owl.doc.ic.ac.uk>
David Coppit <newspost@coppit.org> writes:
>>There's no real point, IMHO, to a collection of programs with no
>>common feature other than that they are written in Perl. Except as
>>a source of examples and inspiration.
>I think "examples and inspiration" is a good enough reason.
>Unfortunately, modules have a lot of extra cruft that can get in the
>way of a beginner's learning experience.
True; but so would any large application. The cruft associated with a
module is _usually_ not any worse than the infrastructure of a big
app, and if anything it's a bit clearer what is doing what. Still,
any example code is useful, especially if you are looking for an
example of one specific technique.
I don't think that CPAN should be the official home of Perl
applications in the same way it is for modules; but a listing of
'useful apps which just happen to be written in Perl' would be good
publicity.
Ideally the source code for all these programs would be searchable, so
if you're looking for examples of using HTTP::Response, you'd just
type the module name into a search box and browse through code that
uses it.
--
Ed Avis <epa98@doc.ic.ac.uk>
Finger for PGP key
------------------------------
Date: Thu, 20 Sep 2001 17:24:37 GMT
From: Markus Laire <nothing@nowhere.com>
Subject: Re: Compile and install CPAN modules on win32
Message-Id: <Xns9122CFA31936Dmarkuslaire@192.89.123.233>
youradmirer@onebox.com (Newbie) wrote in
news:582bc82b.0109192312.3371e7d6@posting.google.com:
> I hope that this short message will help many of you who like to
> compile and install CPAN modules on Windows, but don't want to
> experience the pain I have been through to get these modules installed
> on Windows.
>
> I have built many modules with VC++6.0, so it's highly recommended. In
For those who don't have VC, there is also cygwin (http://www.cygwin.com/)
which gives quite complete unix-environment with windows.
With cygwin you can install modules as in unix.
------------------------------
Date: 20 Sep 2001 10:13:30 -0700
From: djdjokic@yahoo.com (Lorimer)
Subject: Creating a file
Message-Id: <a18e5d95.0109200913.688a8c90@posting.google.com>
Here is the problem: I want to open a file if exist and if it is not
exist then I want to create it and then open for writting in it.
Opening existing one is not a problem but how to create new one.
open (FILE, "> $file") || die "Could not open $!";
print FILE 'nesto';
close (FILE);
And I am getting this message
Could not open No such file or directory at line 650
if there is no such file
Can someone help?
------------------------------
Date: Thu, 20 Sep 2001 18:23:46 +0100
From: "James" <jim@nothing.com>
Subject: Re: Creating a file
Message-Id: <1001006694.4368.0.nnrp-07.d4f024b6@news.demon.co.uk>
Does the directory have write permissions? Have you specified the right
path..?
"Lorimer" <djdjokic@yahoo.com> wrote in message
news:a18e5d95.0109200913.688a8c90@posting.google.com...
> Here is the problem: I want to open a file if exist and if it is not
> exist then I want to create it and then open for writting in it.
> Opening existing one is not a problem but how to create new one.
>
> open (FILE, "> $file") || die "Could not open $!";
> print FILE 'nesto';
> close (FILE);
>
> And I am getting this message
>
> Could not open No such file or directory at line 650
>
> if there is no such file
>
> Can someone help?
------------------------------
Date: Thu, 20 Sep 2001 19:26:42 +0200
From: "Rogier" <rogier@arpadrive-in.com>
Subject: Re: Creating a file
Message-Id: <9od8pg$lor$1@cyan.nl.gxn.net>
Change open(FILE, ">> $file") || die....
The >> is important
Lorimer <djdjokic@yahoo.com> schreef in berichtnieuws
a18e5d95.0109200913.688a8c90@posting.google.com...
> Here is the problem: I want to open a file if exist and if it is not
> exist then I want to create it and then open for writting in it.
> Opening existing one is not a problem but how to create new one.
>
> open (FILE, "> $file") || die "Could not open $!";
> print FILE 'nesto';
> close (FILE);
>
> And I am getting this message
>
> Could not open No such file or directory at line 650
>
> if there is no such file
>
> Can someone help?
------------------------------
Date: 20 Sep 2001 19:27:28 +0200
From: Steve Holland <holland@origo.ifa.au.dk>
Subject: Re: Creating a file
Message-Id: <w47lmj9ydq7.fsf@origo.ifa.au.dk>
djdjokic@yahoo.com (Lorimer) writes:
> Here is the problem: I want to open a file if exist and if it is not
> exist then I want to create it and then open for writting in it.
> Opening existing one is not a problem but how to create new one.
>
> open (FILE, "> $file") || die "Could not open $!";
> print FILE 'nesto';
> close (FILE);
>
> And I am getting this message
>
> Could not open No such file or directory at line 650
>
> if there is no such file
>
> Can someone help?
It sounds like you either don't have write permission for the
directory that you are in, or that there is something wrong with the
value of $file. Try checking your permissions and printing out $file
immediately before the open statement.
=====================================================================
To find out who and where I am look at:
http://www.nd.edu/~sholland/index.html
Spammers: Please send spam to: abuse@aol.com and abuse@yahoo.com
=====================================================================
------------------------------
Date: Thu, 20 Sep 2001 17:41:06 GMT
From: Steve Allan <stevea@wrq.com>
Subject: Re: Creating a file
Message-Id: <uofo5n4i6.fsf@wrq.com>
djdjokic@yahoo.com (Lorimer) writes:
>Here is the problem: I want to open a file if exist and if it is not
>exist then I want to create it and then open for writting in it.
>Opening existing one is not a problem but how to create new one.
>
>open (FILE, "> $file") || die "Could not open $!";
>print FILE 'nesto';
>close (FILE);
>
>And I am getting this message
>
>Could not open No such file or directory at line 650
>
>if there is no such file
>
>Can someone help?
I'd change the die message to:
die "Could not open $file: $!";
so you can see the full path to the file you're trying to create.
Then make sure that path (excluding the file name of course) exists.
--
-- Steve __
------------------------------
Date: Thu, 20 Sep 2001 13:51:38 -0400
From: Aaron Brenner <abrenner@pitt.edu>
Subject: Re: DBI/MySQL help needed
Message-Id: <3BAA2CAA.4EFF188A@pitt.edu>
martinblack wrote:
>
> Hi, I have a problem with one of my scripts that supposedly creates
> database tables. ? Okay, this ones probably quite easy, but I haven't
> had very much DBI experience. The error message says:
>
> "DBD::mysql::st execute failed: You have an error in your SQL syntax
> near ')' at line 10 at dbstart.cgi line 56.
> [...]
> Could this be a problem with DBI?
As the other posters observed, it's probably a problem with your SQL.
See below.
>
> eval {
> $sth = $dbh->prepare(
> $sql="CREATE TABLE product
> (company_id VARCHAR (5) NOT NULL,
> product_id INT NOT NULL,
> title VARCHAR($max),
> description VARCHAR($max),
> spex tinyblob,
> price Float not null,
> sex char (2),
> PRIMARY KEY (company_id, product_id),)
^
Removing this comma ^
did the trick for me.
AB
--
Aaron L. Brenner
Digital Projects Librarian
University Library System
University of Pittsburgh
G20-N Hillman Library
Pittsburgh, PA 15260
Phone: 412.648.2839
Fax: 412.648.7742
------------------------------
Date: Thu, 20 Sep 2001 16:28:44 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: Getting duration from start and and times and dates (without Date module)
Message-Id: <3BAA17FC.C5868DF8@acm.org>
Ben Holness wrote:
> I need to be able to calculate a duration, given a start and end time
> (hh:mm:ss) and date (mm/dd/yyyy).
As has already been mentioned, you can add modules to any directory;
just use "use lib" to tell perl where to find them.
Here's a module-free approach:
==========================================================================
my $start = "09/11/2001 08:48:00";
my $stop = "09/20/2001 12:10:00";
my ($mon, $mday, $y, $h, $m, $s) = split (/[\/ :]/, $start);
my $start_ticks = zeller ($y, $mon, $mday)*86400 + $h*3600 + $m*60 + $s;
($mon, $mday, $y, $h, $m, $s) = split (/[\/ :]/, $stop);
my $stop_ticks = zeller ($y, $mon, $mday)*86400 + $h*3600 + $m*60 + $s;
print "T plus ", $stop_ticks-$start_ticks, " seconds and counting ...\n";
sub zeller {
my ($year, $month, $day) = @_;
$year += int(($month+9)/12) - 1;
$month = ($month+9) % 12;
$year*365 + int($year/4) - int($year/100) + int($year/400) +
$month*30 + int((6*$month+5)/10) + $day + 1;
}
==========================================================================
-- Dave Tweed
------------------------------
Date: Thu, 20 Sep 2001 16:14:53 +0100
From: "Ben Holness" <bholness@nortelnetworks.com>
Subject: Getting duration from start and and times and dates (without Date module)
Message-Id: <9od15u$ec9$1@qnsgh006.europe.nortel.com>
Hi all,
I am in the process of writing a script to be used by many people from a
shared Perl distribution which I am not able to add modules to :(
I need to be able to calculate a duration, given a start and end time
(hh:mm:ss) and date (mm/dd/yyyy).
From scouring Google and the FAQ, it seems that the Date module would be the
best solution, however (as I have mentioned), this option is closed to me.
Does anybody know of an easy way to do this comparison, or have a subroutine
already written that works, taking into account rollovers of date, including
leap years etc? (it is possible that one such calculation would start on Feb
28th at 23:58 and run for ten minutes on a leap year)...
Many thanks in advance,
Ben
------------------------------
Date: Thu, 20 Sep 2001 16:04:56 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Getting duration from start and and times and dates (without Date module)
Message-Id: <mbudash-5415A3.09045820092001@news.sonic.net>
In article <9od15u$ec9$1@qnsgh006.europe.nortel.com>, "Ben Holness"
<bholness@nortelnetworks.com> wrote:
> Hi all,
>
> I am in the process of writing a script to be used by many people from a
> shared Perl distribution which I am not able to add modules to :(
>
> I need to be able to calculate a duration, given a start and end time
> (hh:mm:ss) and date (mm/dd/yyyy).
>
> From scouring Google and the FAQ, it seems that the Date module would be
> the best solution, however (as I have mentioned), this option is closed to
> me.
>
> Does anybody know of an easy way to do this comparison, or have a
> subroutine
> already written that works, taking into account rollovers of date,
> including
> leap years etc? (it is possible that one such calculation would start on
> Feb
> 28th at 23:58 and run for ten minutes on a leap year)...
if you're able to add new files to the filesystem, you can install the
Date::Manip module in the same dir as the script in question, and make
use of it by appropriately changing the @INC array so yur script can
find it:
use FindBin;
use lib "$FindBin::Bin";
use Date::Manip;
however, if you are not able to add new files to the filesystem, it will
be a bit more difficult. you can download and peruse the pertinent code
in the module itself, and manually add it to the script's code.
i'm sure the fine contributors to this newsgroup will come up with even
more ideas.
good luck!
--
Michael Budash ~~~~~~~~~~ mbudash@sonic.net
------------------------------
Date: Thu, 20 Sep 2001 16:09:18 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Getting duration from start and and times and dates (without Date module)
Message-Id: <slrn9qk2ar.9gf.tadmc@tadmc26.august.net>
Ben Holness <bholness@nortelnetworks.com> wrote:
>
>I am in the process of writing a script to be used by many people from a
>shared Perl distribution which I am not able to add modules to :(
>
>I need to be able to calculate a duration, given a start and end time
>(hh:mm:ss) and date (mm/dd/yyyy).
>
>From scouring Google and the FAQ, it seems that the Date module would be the
>best solution, however (as I have mentioned), this option is closed to me.
So don't use the module as a module. Open up the source, find
the parts you need, embed them in your main Perl program.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 20 Sep 2001 18:34:25 +0200
From: Steffen Beyer <sb@mcasia.imperia.net>
Subject: Re: Getting duration from start and and times and dates (without Date module)
Message-Id: <hq5do9.sqb.ln@imperia.net>
Ben Holness <bholness@nortelnetworks.com> wrote:
> I am in the process of writing a script to be used by many people from a
> shared Perl distribution which I am not able to add modules to :(
> I need to be able to calculate a duration, given a start and end time
> (hh:mm:ss) and date (mm/dd/yyyy).
> [...]
Perform calculations using Unix time values (seconds since the epoch).
AND use Perl date/time modules which are part of the standard Perl distribution!
Good luck!
--
Steffen Beyer <sb@engelschall.com>
(This message may not be replyable. Use address on line above instead!)
http://www.engelschall.com/u/sb/whoami/ (Who am I)
http://www.engelschall.com/u/sb/gallery/ (Fotos Brasil, USA, ...)
http://www.engelschall.com/u/sb/download/ (Free Perl and C Software)
------------------------------
Date: Thu, 20 Sep 2001 15:55:13 +0100
From: Jim Lewis <jrl@ast.cam.ac.uk>
Subject: h2xs and string constants in .h files
Message-Id: <3BAA0351.7C5FC386@ast.cam.ac.uk>
Hi,
consider the following C header file:
#define AAA 1
#define BBB "hi there"
How can I get h2xs to create a .xs file which will export BBB to a perl
program that uses
this module? So far only numeric values seem to be passed into the
'constant' subroutine.
cheers, Jim
-------------------------------------------------------------------------------
Jim Lewis |
Cambridge Astronomy Survey Unit | Phone (direct) 44-(0)1223-766652
Institute of Astronomy | (reception) 44-(0)1223-337548
Madingley Road | FAX 44-(0)1223-337523
Cambridge CB3 0HA |
UK | e-mail
jrl@ast.cam.ac.uk
-------------------------------------------------------------------------------
------------------------------
Date: Thu, 20 Sep 2001 16:32:21 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: h2xs and string constants in .h files
Message-Id: <9od5ml$lu4$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Jim Lewis
<jrl@ast.cam.ac.uk>], who wrote in article <3BAA0351.7C5FC386@ast.cam.ac.uk>:
> #define AAA 1
> #define BBB "hi there"
>
> How can I get h2xs to create a .xs file which will export BBB to a perl
> program that uses
> this module? So far only numeric values seem to be passed into the
> 'constant' subroutine.
Nope. You need to create some custom code.
Ilya
------------------------------
Date: Thu, 20 Sep 2001 16:26:43 GMT
From: "GuaRDiaN" <guardian@chello.be>
Subject: Hash problem...
Message-Id: <7Noq7.845$2a.48312@news.chello.be>
Here's what I store...
$$player_name{kills}++;
$$player_name{kills}{victim}{$player_name2}++;
$$player_name{kills}{weapon}{$noun2}++;
$$player_name2{death}++;
$$player_name2{death}{killer}{$player_name}++;
$$player_name2{death}{weapon}{$noun2}++;
Here it's what I retrieve...
foreach $user ( keys %player ) {
print "$user kills: $user->{kills}\n";
print "$user death: $user->{death}\n";
}
This works fine... but I can't retrieve the other informations ...
how could I get data stored in
$$player_name{kills}{victim}{$player_name2
$$player_name{kills}{weapon}{$noun2}
Any help would be appreciated :o)
Thx in advance...
------------------------------
Date: 20 Sep 2001 09:43:40 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Hash problem...
Message-Id: <m1d74ldd8j.fsf@halfdome.holdit.com>
>>>>> "GuaRDiaN" == GuaRDiaN <guardian@chello.be> writes:
GuaRDiaN> Here's what I store...
GuaRDiaN> $$player_name{kills}++;
GuaRDiaN> $$player_name{kills}{victim}{$player_name2}++;
Can't do that. Can't have a value be both a data item
*and* a pointer. Rethink your data structure.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Thu, 20 Sep 2001 16:56:50 GMT
From: "GuaRDiaN" <guardian@chello.be>
Subject: Re: Hash problem...
Message-Id: <mdpq7.855$2a.48860@news.chello.be>
Humm ...
if ( $event1 = "killed" ) {
$$player_name{kills}++; # Player kills
$$player_name{kills}{victim}{$player_name2}++;
$$player_name{kills}{weapon}{$noun2}++;
$$player_name2{death}++; # Player death
$$player_name2{death}{killer}{$player_name}++;
$$player_name2{death}{weapon}{$noun2}++;
}
Why Perl accept to store using this system? but won't retrieve them ?
"Randal L. Schwartz" <merlyn@stonehenge.com> a écrit dans le message de
news: m1d74ldd8j.fsf@halfdome.holdit.com...
> >>>>> "GuaRDiaN" == GuaRDiaN <guardian@chello.be> writes:
>
> GuaRDiaN> Here's what I store...
> GuaRDiaN> $$player_name{kills}++;
> GuaRDiaN> $$player_name{kills}{victim}{$player_name2}++;
>
> Can't do that. Can't have a value be both a data item
> *and* a pointer. Rethink your data structure.
>
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
0095
> <merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
> See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
training!
------------------------------
Date: 20 Sep 2001 10:14:21 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Hash problem...
Message-Id: <m14rpxdbte.fsf@halfdome.holdit.com>
>>>>> "GuaRDiaN" == GuaRDiaN <guardian@chello.be> writes:
GuaRDiaN> Humm ...
GuaRDiaN> if ( $event1 = "killed" ) {
GuaRDiaN> $$player_name{kills}++; # Player kills
GuaRDiaN> $$player_name{kills}{victim}{$player_name2}++;
GuaRDiaN> $$player_name{kills}{weapon}{$noun2}++;
GuaRDiaN> $$player_name2{death}++; # Player death
GuaRDiaN> $$player_name2{death}{killer}{$player_name}++;
GuaRDiaN> $$player_name2{death}{weapon}{$noun2}++;
GuaRDiaN> }
GuaRDiaN> Why Perl accept to store using this system? but won't retrieve them ?
With use strict, you'd be thwarted after
GuaRDiaN> Here's what I store...
GuaRDiaN> $$player_name{kills}++;
GuaRDiaN> $$player_name{kills}{victim}{$player_name2}++;
because $$player_name{kills} would be something like "3", and you're
then doing "3"->{victim}, which ends up being a soft reference for the
hash called "3", namely "%3" in the current package. Illegal, with
use strict, but permitted under grandfathering for Perl 4.
So, the reason Perl lets you is because you didn't tell it to
throw out soft references.
Always start with use strict.
Always start with -w.
print for "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Thu, 20 Sep 2001 17:18:59 GMT
From: "GuaRDiaN" <guardian@chello.be>
Subject: Re: Hash problem...
Message-Id: <7ypq7.858$2a.49419@news.chello.be>
Any idea how I could store something like that ?
"Randal L. Schwartz" <merlyn@stonehenge.com> a écrit dans le message de
news: m14rpxdbte.fsf@halfdome.holdit.com...
> >>>>> "GuaRDiaN" == GuaRDiaN <guardian@chello.be> writes:
>
> GuaRDiaN> Humm ...
> GuaRDiaN> if ( $event1 = "killed" ) {
> GuaRDiaN> $$player_name{kills}++; # Player kills
> GuaRDiaN> $$player_name{kills}{victim}{$player_name2}++;
> GuaRDiaN> $$player_name{kills}{weapon}{$noun2}++;
> GuaRDiaN> $$player_name2{death}++; # Player death
> GuaRDiaN> $$player_name2{death}{killer}{$player_name}++;
> GuaRDiaN> $$player_name2{death}{weapon}{$noun2}++;
> GuaRDiaN> }
>
> GuaRDiaN> Why Perl accept to store using this system? but won't retrieve
them ?
>
> With use strict, you'd be thwarted after
>
> GuaRDiaN> Here's what I store...
> GuaRDiaN> $$player_name{kills}++;
> GuaRDiaN> $$player_name{kills}{victim}{$player_name2}++;
>
> because $$player_name{kills} would be something like "3", and you're
> then doing "3"->{victim}, which ends up being a soft reference for the
> hash called "3", namely "%3" in the current package. Illegal, with
> use strict, but permitted under grandfathering for Perl 4.
>
> So, the reason Perl lets you is because you didn't tell it to
> throw out soft references.
>
> Always start with use strict.
> Always start with -w.
>
> print for "Just another Perl hacker,"
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
0095
> <merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
> See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
training!
------------------------------
Date: 20 Sep 2001 10:40:09 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Hash problem...
Message-Id: <m1r8t1bw1y.fsf@halfdome.holdit.com>
>>>>> "GuaRDiaN" == GuaRDiaN <guardian@chello.be> writes:
Please stop top-posting! Google here for "jeopardy posting" to see
why.
GuaRDiaN> Any idea how I could store something like that ?
Yes. Move it down one level. Never make a hash element try
to do double duty as a reference and as a value.
Change:
[ broken code ]
if ( $event1 = "killed" ) {
$$player_name{kills}++; # Player kills
$$player_name{kills}{victim}{$player_name2}++;
$$player_name{kills}{weapon}{$noun2}++;
$$player_name2{death}++; # Player death
$$player_name2{death}{killer}{$player_name}++;
$$player_name2{death}{weapon}{$noun2}++;
}
to
if ( $event1 = "killed" ) {
$$player_name{kills}{count}++; # Player kills
$$player_name{kills}{victim}{$player_name2}++;
$$player_name{kills}{weapon}{$noun2}++;
$$player_name2{death}{count}++; # Player death
$$player_name2{death}{killer}{$player_name}++;
$$player_name2{death}{weapon}{$noun2}++;
}
Notice that $$player_name{kills} is now always a reference. Never
a data.
print "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Thu, 20 Sep 2001 17:51:59 +0200
From: <addady@hotmail.com>
Subject: How to recomple regular expression ?
Message-Id: <9ocvt4$f0f$1@news.netvision.net.il>
When using a regular expression that contains an interpolated Perl variable,
if it is known that the variable (or variables) will not change during the
execution of the program.
To workaround this problem you can "eval" the regular expression
command so that is will recompile each time.
The problem is this workaround don't work for me !
Here is a small program that demonstrate the problem:
$template="aaaabcdaaa";
for($i=1;$i<=5;$i++){
print $i."\n";
eval {
$template =~ s/abcd/$i/;
};
print "This is template: $template \n---------------------\n";
}
1
This is template: aaa1aaa
---------------------
2
This is template: aaa1aaa
---------------------
3
This is template: aaa1aaa
---------------------
4
This is template: aaa1aaa
---------------------
5
This is template: aaa1aaa
Regards,
Dib Urim
------------------------------
Date: 20 Sep 2001 08:14:28 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: How to recomple regular expression ?
Message-Id: <m1ofo5dhd7.fsf@halfdome.holdit.com>
Well, I tried to send this to you privately, so as not to embarass
you, but you fscked up your email address to play NOT NICE on the net.
So now I get to embarass you publicly. Fool.
>>>>> "You" == <addady@hotmail.com> writes:
You> When using a regular expression that contains an interpolated Perl variable,
You> if it is known that the variable (or variables) will not change during the
You> execution of the program.
You> To workaround this problem you can "eval" the regular expression
You> command so that is will recompile each time.
You> The problem is this workaround don't work for me !
You> Here is a small program that demonstrate the problem:
You> $template="aaaabcdaaa";
You> for($i=1;$i<=5;$i++){
You> print $i."\n";
You> eval {
You> $template =~ s/abcd/$i/;
You> };
You> print "This is template: $template \n---------------------\n";
You> }
You> 1
You> This is template: aaa1aaa
You> ---------------------
You> 2
You> This is template: aaa1aaa
You> ---------------------
You> 3
You> This is template: aaa1aaa
You> ---------------------
You> 4
You> This is template: aaa1aaa
You> ---------------------
You> 5
You> This is template: aaa1aaa
This is working just fine. After the first loop, $template
is "aaa1aaa" and does not contain "abcd" any more.
Your test case is flawed, and your analysis of that is also flawed.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Thu, 20 Sep 2001 17:19:48 GMT
From: Markus Laire <nothing@nowhere.com>
Subject: Re: How to recomple regular expression ?
Message-Id: <Xns9122CED65D9EBmarkuslaire@192.89.123.233>
<addady@hotmail.com> wrote in news:9ocvt4$f0f$1@news.netvision.net.il:
> When using a regular expression that contains an interpolated Perl
> variable, if it is known that the variable (or variables) will not
> change during the execution of the program.
> To workaround this problem you can "eval" the regular expression
> command so that is will recompile each time.
> The problem is this workaround don't work for me !
>
If I understand you correctly, then you have misunderstood rexexp
behaviour. Normal behaviour is to recompile rexexp every time, and you
don't need any workaround to get this.
On the other hand, if you know that interpolated variable do not change,
then you can force perl to compile regexp only once by using 'o' flag in
regexp.
------------------------------
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 1781
***************************************