[18407] in Perl-Users-Digest
Perl-Users Digest, Issue: 575 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 27 14:05:56 2001
Date: Tue, 27 Mar 2001 11:05:22 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <985719921-v10-i575@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 27 Mar 2001 Volume: 10 Number: 575
Today's topics:
Re: acceccing files on localhost ? <kellyboy@nospanner>
Re: Email do not show up in MYSQL <iltzu@sci.invalid>
HTTP Headers <s.warhurst@rl.ac.uk>
Re: HTTP Headers <comdog@panix.com>
Re: indent logging msgs by function call level? (Abigail)
Re: lines with headers <iltzu@sci.invalid>
Re: More Help please :-) <Steve_Alpert@idx.com>
Re: Naming returned files <goldbb2@earthlink.net>
Re: one-liner assignment from regex <klacquement@syscor.com>
Re: one-liner assignment from regex <kimmfc@mydeja.com>
Re: perl irc channel (She Devil With A Rubber Chicken)
Re: perl irc channel <mischief@velma.motion.net>
Re: Q: Active Perl redistributable MINIMUM? <pkrupa@redwood.rsc.raytheon.com>
Re: Question: Addressing Strings? <goldbb2@earthlink.net>
regex-qr// for search and replace <b_nospam_ill.kemp@wire2.com>
Re: regex-qr// for search and replace (John Joseph Trammell)
Re: regex-qr// for search and replace <bart.lateur@skynet.be>
Re: require question; data structure for rules (Abigail)
Re: require question; data structure for rules <bart.lateur@skynet.be>
stat() or 'real' filesize of a file in an iso-filesyste <pilsl_@goldfisch.at>
Re: stat() or 'real' filesize of a file in an iso-files (Abigail)
Re: stat() or 'real' filesize of a file in an iso-files (John Joseph Trammell)
staying at the bottom on an html page <chart@bestweb.net>
Re: Using Sunfreeware's perl in place of Sun's perl (John D Groenveld)
Re: Using Sunfreeware's perl in place of Sun's perl <och@nym.alias.net>
Re: Using Sunfreeware's perl in place of Sun's perl (those who know me have no need of my name)
Re: Using Sunfreeware's perl in place of Sun's perl <och@nym.alias.net>
Re: Using Sunfreeware's perl in place of Sun's perl (John D Groenveld)
Re: Using Sunfreeware's perl in place of Sun's perl <och@nym.alias.net>
Re: Wierd new response to old CGI script <comdog@panix.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 27 Mar 2001 11:12:44 -0600
From: "kellyboy" <kellyboy@nospanner>
Subject: Re: acceccing files on localhost ?
Message-Id: <tc1ib8npuit7f@corp.supernews.com>
> >my apache is on /usr/local/apache
> >cgi-bin is /usr/local/apache/cgi-bin
> >
> >I have directory /home/kellyboy/image
> >
> >Using cgi script locating in /usr/local/apache/cgi-bin, how would you
write
> >a script to retreive images from /home/kellyboy/image
>
> It's not the file location that matters, it's the URL. Note that it's
> not the CGI script that sends the image file, but it's the browser that
> fetches it. So what's the URL for the /home/kellyboy/image directory?
> Could it be "http://www.your.server/image/"? Then all you need is
> "/image/filename.jpg".
its not in the url as configured in httpd.conf...
thats is the question...can I access file on the machine in spite of what
directory are configured in the 'Alias' directive of 'httpd.conf'
kellyboy
------------------------------
Date: 27 Mar 2001 16:56:09 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Email do not show up in MYSQL
Message-Id: <985711723.19397@itz.pp.sci.fi>
In article <3ABF39E3.E99DA45D@hotmail.yesyouremovethis.com>, Kenny Scott wrote:
>Victor Prasad wrote:
>>
>> I am trying to use an HTML form to a perl script to pass an email
>> address in the form:
>> test@test.com
>> It shows up in the database and perl script as: test%40test.com
>> I am using the POST method - how do I get it to enter it correctly?
>
>You could run it through a regex first, ie
>
>$email =~ s/%40/@/;
>
>which will change it before you stick it in your database.
That should be a global substitution. In any case, you just plugged one
hole, with 255 still left. A more general regex solution would be
$email =~ s/%([0-9a-f]{2})/chr hex $1/ige;
Still, that's just plugging the holes. For a better overall solution,
try the standard module CGI.pm, for which an excellent introduction can
be found at http://stein.cshl.org/WWW/software/CGI/ .
--
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla / Kira -- do not feed the troll.
------------------------------
Date: Tue, 27 Mar 2001 12:20:00 +0100
From: "S Warhurst" <s.warhurst@rl.ac.uk>
Subject: HTTP Headers
Message-Id: <99pt18$itk@newton.cc.rl.ac.uk>
Hi
Can anyone tell me how to retrieve all the http header information passed
from the client to server, and break it down into pairs? I have been
searching for a while but can't find any routines to do it.
Thanks
Spencer
------------------------------
Date: Tue, 27 Mar 2001 12:54:37 -0600
From: brian d foy <comdog@panix.com>
Subject: Re: HTTP Headers
Message-Id: <comdog-D84B53.12543727032001@news.panix.com>
In article <99pt18$itk@newton.cc.rl.ac.uk>, "S Warhurst"
<s.warhurst@rl.ac.uk> wrote:
> Can anyone tell me how to retrieve all the http header information passed
> from the client to server, and break it down into pairs? I have been
> searching for a while but can't find any routines to do it.
how are you trying to do this and what are you trying to accomplish?
--
brian d foy <comdog@panix.com>
------------------------------
Date: Tue, 27 Mar 2001 16:06:53 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: indent logging msgs by function call level?
Message-Id: <slrn9c1ekt.alk.abigail@tsathoggua.rlyeh.net>
Mathias Koerber (mathias@koerber.org) wrote on MMDCCLXV September
MCMXCIII in <URL:news:kjb0ct4koapqlkqdenjbum8fs0ka6i1alq@4ax.com>:
== I need to debug a lengthy program with many nested function calls.
==
== Is there any tool (module etc) which can assist in formatting
== error/debug/log messages such that they are indented apropriately
== to the evel of function (or loop etc) called?
$SIG {__DIE__} = sub {
my $i;
1 while caller (++ $i);
die " " x -- $i => @_
};
And something similar for $SIG {__WARN__}.
Of course, if you use 'print' to print warnings and error messages, you lose.
Abigail
--
print v74.117.115.116.32.97.110.111.116.104.101.114.
v32.80.101.114.108.32.72.97.99.107.101.114.10;
------------------------------
Date: 27 Mar 2001 16:39:16 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: lines with headers
Message-Id: <985710058.16252@itz.pp.sci.fi>
In article <99mbq1$bo0$1@news.netmar.com>, kenta@nospam.nospam wrote:
>Hi, I'm looking for advice to make this program more "elegant."
>
>#!perl -w
>$first_time=1;
>while(<>){
> chomp;
> unless (/^\d*$/){
> print "$title=$sum\n" unless $first_time;
> $title=$_;
> $first_time=0;
> $sum=0;
> next;
> }
> $sum+=$_;
>}
>print "$title=$sum\n" unless $first_time;
If you want to keep the line-by-line while(<>) loop, which is a good
idea unless you know the file will never grow very large, there isn't
much to do. A few minor improvements:
#!/usr/bin/perl -w
use strict;
my ($title, $sum);
while (<>) {
chomp;
if (/\D/) {
print "$title=$sum\n if defined $title;
($title, $sum) = ($_, 0);
} else {
$sum += $_;
}
}
print "$title=$sum\n if defined $title;
Using -w and strict is always a good idea. When you do use strict, you
will need to declare any variables you use (except for Perl's special
variables like $_). Usually what you want are lexical variables, for
which you'll use "my", although is such a short script it makes little
difference. Global variables can be declared with "use vars '$var';" or
in Perl v5.6.0 with "our".
I also removed your $first_time variable, since the same effect can be
achieved by testing whether $title is defined. (Actually checking for
truth would've been enough, since neither "0" nor "" are valid titles.)
I also inverted the sense of your regex, testing whether there is any
non-digit anywhere in the string. (This would fail without "chomp".)
--
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla / Kira -- do not feed the troll.
------------------------------
Date: Tue, 27 Mar 2001 12:40:18 -0500
From: Steve Alpert <Steve_Alpert@idx.com>
Subject: Re: More Help please :-)
Message-Id: <b5k1ct0pnbumb9ooa1j3ftr3djj3d3gabs@4ax.com>
nospam@thank.you wrote:
>Thanks for the pointers :-) Much Appreciated
>
>Another quick one,
>
>I've sorted the list of email address with the script and the
>resulting file has duplicates :-( Is there a quick way of removing the
>duplicate lines? While the script is sorting the list? I'm using;
>
>@newvalue = sort @value;
>
>to sort the list.
how 'bout:
#!/user/bin/perl -w
use strict;
my @a = qw(a b c d c a e b);
my $last = '';
print grep { my $r = $_ ne $last; $last = $_; $r } sort @a;
/steve
Steve Alpert (Steve_Alpert @ i d x . c o m)
IDX Systems Corp. Boston, Massachusetts
------------------------------
Date: Tue, 27 Mar 2001 17:27:25 GMT
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Naming returned files
Message-Id: <3AC0CE43.A56D3FF3@earthlink.net>
Alan Hood wrote:
>
> I need to download a file using a value from a select box on the
> browser.
I'll assume you mean that you want to force the browser to create a
save-file dialog, rather than try and view the file.
> Since I connot alter the mime-types on the server I am trying to use a
> perl script.
Seems a reasonable way to go about it.
> The following code works but returns the name of the script.
>
> my $orderToDown = $orderPath.$formPars->param("SELECTED");
Hmm, shouldn't you add spaces on either side of the . for readability?
Although I think you can be sure that $orderToDown doesn't *start* with
funky characters (like ">"), because $orderPath was defined by you, not
from a form parameter, this still isn't safe.
What if param('SELECTED') contains a string like '../../bin/rm -rf /|"
or somesuch?
You ought to clean the part that comes from param() before using it, and
make sure it doesn't contain any special characters which might screw
things up.
> print "Content-type: application/octet-stream html\n\n";
Ehh? What's the "html" on the end there for?
> open(ORDER,$orderToDown);
Even if the above string is "clean" you still probably shouldn't use the
two argument version of open in a cgi script. Instead, use:
open(ORDER, "<", $orderToDown);
> while(<ORDER>){
> print $_;
> }
The line above is slow. You should instead use either
print <ORDER>;
or
{ local $/; print <ORDER>; }
or if you want to use less memory, something like:
{ local $/ = \"1024"; print while <ORDER>; }
Which makes it read and print data in 1024 byte blocks.
> close(ORDER);
> }
What's this brace supposed to match?
>
> I have tried to change the name by using Content-Location in the
> resonse header as follows
>
> print "Content-Location: (http://www.website.com/orderfile.ord)\n";
All that content-location does is redirect to another web page. And if
you do use it, then you oughtn't have () around the url.
> But this does not work.
Because of the ().
> Can anybody tell if this is possible and if so how ?.
#!/usr/local/bin/env perl -w
use strict;
use CGI::Carp qw(fatalsToBrowser);
my $query = new CGI;
my $item = $query->param('SELECTED');
die <<ERRORSTRING if( $item =~ /[^a-zA-Z0-9_]+/ );
It is illegal to use non alpha-numeric characters in this part of the
form. Don't do that. Since the <b>real<b> form doesn't contain any
such characters, you're a hacker trying to find a hole and break into
my system. Eat **** and die!!!
ERRORSTRING
print $query->redirect("http://www.website.com/$item.ord");
__END__
>
> Many thanks
>
> Alan Hood
--
The difference between theory and practice is that in theory, theory and
practice are identical, but in practice, they are not.
------------------------------
Date: 27 Mar 2001 09:14:16 -0800
From: Kevin Lacquement <klacquement@syscor.com>
Subject: Re: one-liner assignment from regex
Message-Id: <m2g0fz8787.fsf@aridhol.syscor.priv>
>>>>> "TM" == Tad McClellan <tadmc@augustmail.com> writes:
TM> Kevin Lacquement <klacquement@syscor.com> wrote:
>>>>>>> "KC" == Kim C <kimmfc@mydeja.com> writes:
>>
>> [...]
>>
KC> ($start , $end) = /(^.)(.$)/;
>>
>> What does this actually match?
TM> two-character strings (or three chars if the last is a newline).
>> I'd think it gets everything,
TM> What part of the pattern matches lots of characters?
Sorry...that was me misreading the regexp. For some odd reason, I
thought I saw some *s in there. Time to visit the optometrist, I
think.
[...]
Cheers,
Kevin
--
He that breaks a thing to find out what it is has left the path of
wisdom -- Gandalf the Grey
------------------------------
Date: Tue, 27 Mar 2001 18:32:08 GMT
From: Kim C <kimmfc@mydeja.com>
Subject: Re: one-liner assignment from regex
Message-Id: <o5n1cts24e1p2oanevcs37hqhrsh1r6cmq@4ax.com>
Thanks all!
Kim
------------------------------
Date: 27 Mar 2001 17:18:01 GMT
From: redsonja@liii.com (She Devil With A Rubber Chicken)
Subject: Re: perl irc channel
Message-Id: <99qi09$668$1@cedar.ggn.net>
In article <8zn2c4uu.fsf@pobox.com>, Jonathan Feinberg <jdf@pobox.com> wrote:
>AvA <a.v.a@home.nl> writes:
>
>> lol randal, somehow i doubt that anyone would fire you
>
>You would be *amazed* at what Randal's "employers" might do.
Only the stupid ones. ;-7
--
"You know you're a geek when you log onto IRC | Do not CD c
so you can tell your friend halfway across the | taunt --------P===\==/
country which HTML hex code to use for the | happy fun /_\__
color of your wedding dress." -- Me | fencer! _\ \
------------------------------
Date: Tue, 27 Mar 2001 18:58:31 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: perl irc channel
Message-Id: <tc1omneda2sta2@corp.supernews.com>
Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>>>>>> "Kent" == Kent Perrier <kperrier@blkbox.com> writes:
> Kent> Jonathan Feinberg <jdf@pobox.com> writes:
>>> AvA <a.v.a@home.nl> writes:
>>>
>>> > lol randal, somehow i doubt that anyone would fire you
>>>
>>> You would be *amazed* at what Randal's "employers" might do.
> Kent> Yeah, just ask Intel....
> Well, there's an old saying (I think it's old, anyway) that if
> you have to explain a joke, you lose. :)
True. ;-)
> But the reason for this post is I can't let stand a bit of
> misinformation even as a joke... I was never an *employee* of Intel.
> Just a contractor. I'm sensitive about that because the ongoing legal
> case makes that distinction a very necessary part of my defense.
And although Randal won't stick his hand out and mention it here,
you can PayPal a donation to his legal defense. This is what all
of you `Free Kevin' people should have been wearing t-shirts about.
I've been a big advocate of Randal's case since I first heard the news
around August 1995, bringing it up at user groups meetings and
forming impromptu email campaigns to state officials in Oregon.
The even bigger advocates formed the Friends of Randal Schwartz,
which is what the `fors' in the URL Randal provides stands for.
> And for those that don't get this post or the two parent articles,
> please go read http://www.lightlink.com/fors/ et seq, for details
> about my ongoing legal case.
To PayPal a donation to Randal's defense in one of the most outrageous
and dangerous cases of law in our time, look for the PayPal button
on Randal's website, http://www.stonehenge.com/merlyn, and let's
let people know how silly it is to prosecute someone for something
he was hired to do.
I just made a donation, so come on and jump on the badnwagon.
Chris
--
Christopher E. Stith
For the pleasure of others, please adhere to the following
rules when visiting your park:
No swimming. No fishing. No flying kites. No frisbees.
No audio equipment. Stay off grass. No pets. No running.
------------------------------
Date: Tue, 27 Mar 2001 10:57:39 -0700
From: "Peter A. Krupa" <pkrupa@redwood.rsc.raytheon.com>
Subject: Re: Q: Active Perl redistributable MINIMUM?
Message-Id: <3AC0D493.E13440BE@redwood.rsc.raytheon.com>
I was asking myself the same question just the other day. Obviously,
perl.exe alone won't do the job--it's only 20Kb under v5.6. I put perl.exe
and perl56.dll on a floppy disk (with PATH=.) and was able to run these
one-liners (on NT 4.0):
perl -e "print ( \"Hello, world!\n\" );"
dir /b /s c:\perl\bin | perl -ne "print if!/(\.exe|\.bat|\.pl)/;"
perl -e "print \"Executable\n\" if -x 'Perl.exe'"
Try running your script with this minimum configuration. If you get an
error add the other DLLs in c:\perl\bin until the error goes away,
hopefully. (Of course if your script uses modules you will need to make
them accessible.)
Post your findings back here!
------------------------------
Date: Tue, 27 Mar 2001 18:39:55 GMT
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Question: Addressing Strings?
Message-Id: <3AC0DF35.928ADABC@earthlink.net>
Logan Shaw wrote:
>
> In article <eli$0103231928@qz.little-neck.ny.us>,
> Eli the Bearded <elijah@workspot.net> wrote:
> >In comp.lang.perl.misc, Zac Hester <zhester@enetis.net> wrote:
> >> I'm trying to use strings like character arrays. Okay, I know, I
> >> know, Perl is a string oriented language. That's all I've heard
> >> from Perl programmers for quite a while now, but there's got to be
> >> a solution. If I can use the 'index' function to return a
> >> substring's position in a string, shouldn't there be an inverse of
> >> that function that returns a substring based on a position (or
> >> positions)?
> >
> >You got something against substr?
>
> Or if you really want to use all of Perl's list operations on a
> string's characters, one can always do this:
>
> @array = split (//, $string);
Unfortunatly for you, m// is magic when the expression is empty.
Just do @array = split ("", $string); for this.
>
> and then this:
>
> $string = join ("", @array);
>
> to put it back together again. It's not the most efficient thing
> in the world, but it's nice if you want to, say, concisely figure
> out which characters occur in a file:
>
> open (FOO, "/etc/passwd") or die;
> $file_as_string = join ("", <FOO>);
> close FOO;
This would be much better written as:
{
local *FOO, $/;
open(FOO, "/etc/passwd") or die;
$file_as_string = <FOO>;
} # FOO is implicitly closed due to being local
> @char_array = split (//, $file_as_string);
Again, // is magical. It means match with the last nonempty pattern.
If you've never had any nonempty patterns in your file, then it may
work, but it is a bad idea to always expect this to be so.
Example:
my $str = "a, b, c, d";
my @ary1 = split // => $str;
my @ary2 = split /, / => str;
my @ary3 = split // => $str;
print join( "X", @$_ ), "\n" for (\@ary1, \@ary2, \@ary3);
__END__
This will print:
aX,X XbX,X XcX,X Xd
aXbXcXd
aXbXcXd
And if the matching is being done somewhere in a sub, it may be even
more unobvious what's going on.
> %found = map ( ($_ => 1), @char_array );
Using map is less efficient than simply doing:
@found{ @char_array } = ();
> print map ("'$_'\n", sort keys %found);
Again, using map is innefficient. This is better:
print "'", join( "'\n'", sort keys %found ), "'\n";
And this is better yet:
print "'$_'\n" for (sort keys %found);
> Hope that helps.
>
> - Logan
> --
> whose? my your his her our their _its_
> who's? I'm you're he's she's we're they're _it's_
--
The difference between theory and practice is that in theory, theory and
practice are identical, but in practice, they are not.
------------------------------
Date: Tue, 27 Mar 2001 17:56:07 +0100
From: "W K" <b_nospam_ill.kemp@wire2.com>
Subject: regex-qr// for search and replace
Message-Id: <985712399.15095.0.nnrp-01.c3ad6974@news.demon.co.uk>
I want to ge able to save a regular expression. easy, you say.
$re=qr/interseting word/;
if ($text =~/$re){ etc. etc.}
The question is, can I store a search and replace in such a way?
If I am going to look through hundreds of strings doing search and replace
on them it would normally require a compilation of the regular extression
each time(?).
It would seem like a nice optimisation to have, but I didn't see anything
like this mentioned.
(The /o wouldn't be useful in my case)
------------------------------
Date: Tue, 27 Mar 2001 17:10:14 GMT
From: trammell@bayazid.hypersloth.invalid (John Joseph Trammell)
Subject: Re: regex-qr// for search and replace
Message-Id: <slrn9c1gbv.k8j.trammell@bayazid.hypersloth.net>
On Tue, 27 Mar 2001 17:56:07 +0100, W K <b_nospam_ill.kemp@wire2.com> wrote:
> The question is, can I store a search and replace in such a way?
Yes.
my $r = qr(foo);
(my $s = "lalala foo lalala\n") =~ s/$r/bar/;
print $s;
perldoc perlop for more gory details.
------------------------------
Date: Tue, 27 Mar 2001 17:30:24 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: regex-qr// for search and replace
Message-Id: <q3j1ctoh4nqs7loj9lrfh6eo20ksmfbjuf@4ax.com>
W K wrote:
>The question is, can I store a search and replace in such a way?
>If I am going to look through hundreds of strings doing search and replace
>on them it would normally require a compilation of the regular extression
>each time(?).
>
>It would seem like a nice optimisation to have, but I didn't see anything
>like this mentioned.
>
>(The /o wouldn't be useful in my case)
You're right, /o isn't too useful. Perhaps a closure can help?
sub regexsub {
my $re = shift;
return sub {
shift =~ /$re/o;
}
}
$sub[0] = regexsub('fo+');
$sub[1] = regexsub('ba+r');
foreach (qw'foo baaar fooooo bar bbbbbbbbar') {
foreach my $i(0, 1) {
$sub[$i]->($_) and print "Match for '$_' with regex $i\n";
}
}
-->
Match for 'foo' with regex 0
Match for 'baaar' with regex 1
Match for 'fooooo' with regex 0
Match for 'bar' with regex 1
Match for 'bbbbbbbbar' with regex 1
In pre-5.6.0, //o and closures don't work too well together. There,
you'd have to put the closure (the sub that gets returned by regexsub)
in an eval STRING construct.
But somehow, I feel that you really want to combine all LHS in one big
set of alternatives, and depending on which alternative matched, get a
different substitution. However, implementing that is a whole different
kettle of fish.
--
Bart.
------------------------------
Date: Tue, 27 Mar 2001 16:11:53 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: require question; data structure for rules
Message-Id: <slrn9c1eu9.alk.abigail@tsathoggua.rlyeh.net>
Logan Shaw (logan@cs.utexas.edu) wrote on MMDCCLXV September MCMXCIII in
<URL:news:99pk2i$phi$1@boomer.cs.utexas.edu>:
__ In article <3AC044EC.8547C84F@leland.stanford.edu>,
__ Jonathan Dugan <dugan@leland.stanford.edu> wrote:
__ >I'd like the rule set to be alterable at run time without stopping the
__ >script, so I've implemented the rule set as a module. In the setup()
__ >subroutine, I use require to load the modules and build the hashes
__ >containing the rules. I've put signal handlers in the main program to
__ >catch HUP.
__ >
__ >So the problem: how do I keep reloading a module? (or for that
__ >matter, any code in an external file) I want the function called on
__ >HUP to simply run the setup() sub again (which it does) but the
__ >'require' function only will load a module once.
__
__ You want "do". It's like require, but it doesn't remember that
__ it's already loaded something. "perldoc -f do" for more info.
Of you undefine the entry in %INC, before calling require.
Abigail
------------------------------
Date: Tue, 27 Mar 2001 17:19:52 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: require question; data structure for rules
Message-Id: <cci1cts2p2oola9e2ja88t4vrc4ref1psa@4ax.com>
Jonathan Dugan wrote:
>I'd like the rule set to be alterable at run time without stopping the
>script, so I've implemented the rule set as a module. In the setup()
>subroutine, I use require to load the modules and build the hashes
>containing the rules. I've put signal handlers in the main program to
>catch HUP.
>
>So the problem: how do I keep reloading a module? (or for that
>matter, any code in an external file) I want the function called on
>HUP to simply run the setup() sub again (which it does) but the
>'require' function only will load a module once. I looked at the use
>function, but it appears to apply the require function too, and that
>will only load a module once.
Perhaps you want "use" instead. Put the stuff you want to repeat, again
and a gain, in the import method. Er... that will do what it does at
compile time.
Why don't you simply put it in a sub e.g. "setup", and call it every
time you actually want to run it?
>I could just make the rules definitions a normal data file (like all
>the other ones it re-reads) however, as you'll see in the next
>question, the rules are a bit complicated, so it seems to make sense
>to just write in perl to start with.
You might think of a hybrid method. Parse::Recdescent works this way.
You can imagine it to compile its custom language and turning it into
perl code, or at least, a structure that's easy to interpret in Perl.
>I'd like both conditions and effects to be BLOCKS {} with perl code in
>them.
>
>So... can you put a BLOCK of perl code as an element of an list? How
>would you run it?
Yes. Use an anonumous sub, i.e. the sub keyword followed by a block. For
example:
#! perl -w
%dispatch = (
FOO => sub { print "This is FOO. Really. Parameters are: @_\n";
return "foo"; },
BAR => sub { print "This is BAR. Truely. Parameters are: @_\n";
return "bar"; },
);
foreach my $word (qw(FOO BAR BAR FOO FOO)) {
print $dispatch{$word}->(1, 2, 3), "\n";
}
-->
This is FOO. Really. Parameters are: 1 2 3
foo
This is BAR. Truely. Parameters are: 1 2 3
bar
This is BAR. Truely. Parameters are: 1 2 3
bar
This is FOO. Really. Parameters are: 1 2 3
foo
This is FOO. Really. Parameters are: 1 2 3
foo
--
Bart.
------------------------------
Date: Tue, 27 Mar 2001 18:29:20 +0200
From: peter pilsl <pilsl_@goldfisch.at>
Subject: stat() or 'real' filesize of a file in an iso-filesystem
Message-Id: <MPG.152ade4bcdf1ed719897c1@news.inode.at>
I am scanning 100.000 files and create subsets for burning on cdrom. To
fill each cdrom as most as possible, I need to know for each file and
directory how much space it will finally take on the destination-
filesystem (joliet-iso9660), including its space in the filesystems
header.
The size-value delivered by stat() is a very bad estimation of course. I
also tried the product blocks*blksize, but this delivers a unreal value
and in fact I dont know what blksize and blocks really mean.
Thanks for your help,
peter
--
pilsl@
goldfisch.at
------------------------------
Date: Tue, 27 Mar 2001 17:31:00 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: stat() or 'real' filesize of a file in an iso-filesystem
Message-Id: <slrn9c1jik.alk.abigail@tsathoggua.rlyeh.net>
peter pilsl (pilsl_@goldfisch.at) wrote on MMDCCLXV September MCMXCIII in
<URL:news:MPG.152ade4bcdf1ed719897c1@news.inode.at>:
//
// I am scanning 100.000 files and create subsets for burning on cdrom. To
// fill each cdrom as most as possible, I need to know for each file and
That's the 0-1 knapsack problem. Which is NP-complete. You really do
not want to calculate the optimal way to write your CDs, unless you can
afford to wait far past the heat-death of the universe.
// directory how much space it will finally take on the destination-
// filesystem (joliet-iso9660), including its space in the filesystems
// header.
//
// The size-value delivered by stat() is a very bad estimation of course. I
// also tried the product blocks*blksize, but this delivers a unreal value
// and in fact I dont know what blksize and blocks really mean.
That sounds like a very filesystem specific question, and should be
asked elsewhere.
Abigail
--
map{${+chr}=chr}map{$_=>$_^ord$"}$=+$]..3*$=/2;
print "$J$u$s$t $a$n$o$t$h$e$r $P$e$r$l $H$a$c$k$e$r\n";
------------------------------
Date: Tue, 27 Mar 2001 18:35:04 GMT
From: trammell@bayazid.hypersloth.invalid (John Joseph Trammell)
Subject: Re: stat() or 'real' filesize of a file in an iso-filesystem
Message-Id: <slrn9c1lb1.kd9.trammell@bayazid.hypersloth.net>
On Tue, 27 Mar 2001 17:31:00 +0000 (UTC), Abigail <abigail@foad.org> wrote:
> peter pilsl (pilsl_@goldfisch.at) wrote on MMDCCLXV September MCMXCIII in
> <URL:news:MPG.152ade4bcdf1ed719897c1@news.inode.at>:
> //
> // I am scanning 100.000 files and create subsets for burning on cdrom. To
> // fill each cdrom as most as possible, I need to know for each file and
>
> That's the 0-1 knapsack problem. Which is NP-complete. You really do
> not want to calculate the optimal way to write your CDs, unless you can
> afford to wait far past the heat-death of the universe.
True in general, but if the files are all much smaller than
the "knapsack", a 'pretty good' solution is calculable.
Peter: what does a histogram of your file sizes look like?
------------------------------
Date: Tue, 27 Mar 2001 19:01:18 GMT
From: GWN <chart@bestweb.net>
Subject: staying at the bottom on an html page
Message-Id: <B6E64DB9.10044%chart@bestweb.net>
Is there a way to have a web page that is output by a perl cgi script
display the bottom of the page after printing and not the top?
chart
------------------------------
Date: 27 Mar 2001 11:42:52 -0500
From: groenvel@cse.psu.edu (John D Groenveld)
Subject: Re: Using Sunfreeware's perl in place of Sun's perl
Message-Id: <99qfuc$grt$1@gallifrey.cse.psu.edu>
Leave Sun's perl (SUNWpl5u) installed in /usr/perl5.
Build your own perl (the latest release, with your favorite compiler, with
your favorite site specific options) in your favorite location,
/opt/perl, /usr/local, whatever.
Any Sun scripts which depend on Sun's perl will reference /usr/perl5/bin/perl
directly so feel free to break the symbolic link in /usr/bin.
# rm /usr/bin/perl
# ln -s /opt/perl/bin/perl /usr/bin/perl
John
groenveld@acm.org
------------------------------
Date: 27 Mar 2001 17:01:47 -0000
From: Och <och@nym.alias.net>
Subject: Re: Using Sunfreeware's perl in place of Sun's perl
Message-Id: <20010327170147.11968.qmail@nym.alias.net>
>> Mike:
>>
>> This is a perl problem, not an INN problem.
Says who?
> This is an obscure problem (one hit on deja).
>> deja is gone, how can you have one hit?
Google bought them out newbie.
http://groups.google.com/advanced_group_search
Go away little one, let the adults talk in peace.
------------------------------
Date: Tue, 27 Mar 2001 17:19:24 -0000
From: not-a-real-address@usa.net (those who know me have no need of my name)
Subject: Re: Using Sunfreeware's perl in place of Sun's perl
Message-Id: <tc1issbc20370@news.supernews.com>
[f-u set]
<20010327142629.15126.qmail@nym.alias.net> divulged:
>This is an obscure problem (one hit on deja).
>I'll be lucky if anyone in any of the groups can provide a correct answer.
actually, it seems more like a "you can't even read" problem.
># ls /usr/include/*.ph
>/usr/include/*.ph: No such file or directory
that's not where they go -- typically. ``man h2ph''
try: ``find /usr/perl5 -name '*.ph' -print'' if they are not there
_that_ is the problem.
>>> I changed cc to gcc in /usr/perl5/5.00503/i86pc-solaris/Config.pm,
>>> but the error still occurs.
meaningless, unless you also recompiled perl (which requires the proper
voodoo lest your change be lost).
--
okay, have a sig then
------------------------------
Date: 27 Mar 2001 17:28:34 -0000
From: Och <och@nym.alias.net>
Subject: Re: Using Sunfreeware's perl in place of Sun's perl
Message-Id: <20010327172834.16041.qmail@nym.alias.net>
>> Och:
>>
>> It also seems that a pkgrm SUNWpl5? fails because the Solaris 8
>> kernel now depends upon perl.
> garry:
>
> That's interesting. How did you conclude that?
A deja search returned many hits posted by people experiencing
problems using Sun's perl in a gcc environment.
My first inclination was to just download Sunfreeware's perl,
but I thought it best to remove Sun's perl first. Unfortunately,
pkgrm displays the following errors on each perl package:
_______________________________________________________________________
# pkgrm SUNWpl5m
The following package is currently installed:
SUNWpl5m Perl5 On-Line Manual Pages
(i386) 1.0,REV=2
Do you want to remove this package? y
WARNING: Stale lock installed for pkgrm, pkg SUNWpl5m quit in initial state.
Removing lock.
## Removing installed package instance <SUNWpl5m>
(A previous attempt may have been unsuccessful.)
## Verifying package dependencies.
## Processing package information.
pkgrm: ERROR: bad read of contents file
pkgrm: ERROR: pathname=/usr.dt/appconfig/icnns/C/Fpexit.s.bm
pkgrm: ERROR: problem=unable to read mode/owner/group
_______________________________________________________________________
Further deja research produced an old post from a Sun engineer
asking people not to remove Sun's perl packages because the
Solaris 8 kernel now depends upon perl.
It appears that early Solaris 8 releases used to allow people
to remove perl.
My hunch is that Sun made it impossible to remove perl from
recent Solaris 8 releases.
_______________________________________________________________________
Och finger och@nym.alias.net for public key
------------------------------
Date: 27 Mar 2001 12:33:06 -0500
From: groenvel@cse.psu.edu (John D Groenveld)
Subject: Re: Using Sunfreeware's perl in place of Sun's perl
Message-Id: <99qisi$ipf$1@gallifrey.cse.psu.edu>
In article <20010327172834.16041.qmail@nym.alias.net>,
Och <och@nym.alias.net> wrote:
>asking people not to remove Sun's perl packages because the
>Solaris 8 kernel now depends upon perl.
No, but kstat(1M) and possibly other useful commands depend on
SUNWpl5u
John
groenveld@acm.org
------------------------------
Date: 27 Mar 2001 18:04:31 -0000
From: Och <och@nym.alias.net>
Subject: Re: Using Sunfreeware's perl in place of Sun's perl
Message-Id: <20010327180431.16322.qmail@nym.alias.net>
I put the missing froups back in the header for you.
> not:
>
> actually, it seems more like a "you can't even read" problem.
That doesn't even make sense slaphead, when everyone clearly sees
that my problem lies with newbies who keep posting unsolicited
opinions.
> try: ``find /usr/perl5 -name '*.ph' -print'' if they are not there
> _that_ is the problem.
$ find /usr/perl5 -name '*.ph' -print
/usr/perl5/site_perl/5.005/i86pc-solaris/_h2ph_pre.ph
/usr/perl5/site_perl/5.005/i86pc-solaris/usr/include/syslog.ph
/usr/perl5/site_perl/5.005/i86pc-solaris/syslog.ph
Do you have any more worthless advice to offer up Einstein?
------------------------------
Date: Tue, 27 Mar 2001 12:00:37 -0600
From: brian d foy <comdog@panix.com>
Subject: Re: Wierd new response to old CGI script
Message-Id: <comdog-BDAC6D.12003727032001@news.panix.com>
In article <99qb02$sh6$1@bob.news.rcn.net>, "Janet Ruhl"
<ruhl@realrates.com> wrote:
> In the past week I've gotten two messages from would-be customers who
> received the following response after invoking my perl ordering script.
> -----
> cgi-lib.pl: Unknown Content-type:
> application/x-www-form-urlencoded,
> application/x-www-form-urlencoded
CGI.pm should be able to handle this. you could changeover to
CGI.pm and use its cgi-lib compatibility mode. it gives you
the same interface but has all of the updated and fixed code
behind the scenes :)
see the CGI.pm docs for details. (it comes with perl ;)
--
brian d foy <comdog@panix.com>
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 575
**************************************