[19959] in Perl-Users-Digest
Perl-Users Digest, Issue: 2154 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 19 00:06:00 2001
Date: Sun, 18 Nov 2001 21:05:07 -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: <1006146307-v10-i2154@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 18 Nov 2001 Volume: 10 Number: 2154
Today's topics:
Re: Algorithm question -- need help <c_clarkson@hotmail.com>
Re: Directory problem... again <uri@stemsystems.com>
Help: Handling browser windows. <hamilton@nospam.ihug.co.nz>
Re: Help: Handling browser windows. <tony_curtis32@yahoo.com>
HTTP Server using Sockets <rohit.nadhani@tallysolutions.com>
Re: Intrusion Vulerability ActiveState ActivePerl 5.6.1 <godzilla@stomp.stomp.tokyo>
Re: Intrusion Vulerability ActiveState ActivePerl 5.6.1 <flavell@mail.cern.ch>
Re: Is two-dim hash inefficient? <goldbb2@earthlink.net>
Re: Is two-dim hash inefficient? <goldbb2@earthlink.net>
Re: Passing captured data to Apache server?? <${spam}$@sneakerpimp.fsnet.co.uk>
perl cgi question: <e.quesada@verizon.net>
Re: Perl generating JavaScript problem <danny@lennon.postino.com>
Re: Perl generating JavaScript problem <bart.lateur@skynet.be>
perl script for finding users (AleX)
Sorting files by date on Win32 (Maynard)
Re: Sorting files by date on Win32 (Tad McClellan)
Re: Sorting of arrays by an element of each <uri@stemsystems.com>
Re: Sourcing with a twist of Parsing ? <goldbb2@earthlink.net>
Re: Sourcing with a twist of Parsing ? (Tad McClellan)
subroutines in separate file <jonah@@adtrackz.com>
Re: subroutines in separate file <nobody@nowhere.com>
Re: system(), PERL5SHELL won't work <goldbb2@earthlink.net>
Re: temporary file deleting too soon <goldbb2@earthlink.net>
Re: temporary file deleting too soon <nobody@nowhere.com>
Re: unresolved symbol Perl_Tstack_sp_ptr from Fcntl.so <goldbb2@earthlink.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 18 Nov 2001 18:38:20 -0000
From: "Charles K. Clarkson" <c_clarkson@hotmail.com>
Subject: Re: Algorithm question -- need help
Message-Id: <tvh2g39hm2o109@corp.supernews.com>
"Arkady" <apinkhasov@hotmail.com> wrote:
in message news:30d03e1.0111170540.196d9838@posting.google.com...
: I have a list of machines and their respective parents. One machine
: is a root, and the others follow from it. However, I cannot get the
: right idea for a kind of data sttructure to work properly and
: algorithm to populate it.
:
: If anybody has any suggestions, please do not hesistate to help.
:
You might pick up a book called: Mastering Algorithms with Perl.
It introduces various tree structures and gives some code
examples for perl.
http://www.oreilly.com/catalog/maperl/
HTH,
Charles K. Clarkson
Clarkson Energy Homes, Inc.
We receive three educations:
one from our parents,
one from our schoolmaster, and
one from the world.
The third contradicts all that the first two teach us.
- Baron de Montesquieu
------------------------------
Date: Sun, 18 Nov 2001 23:31:47 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Directory problem... again
Message-Id: <x7elmvfye9.fsf@home.sysarch.com>
>>>>> "BN" == BUCK NAKED1 <dennis100@webtv.net> writes:
BN> What can I say? If I don't understand, I don't understand. Some of the
BN> docs I understand, and some of them I don't. I think most of the docs
BN> are unclear and unthorough; but maybe it's just me.
well, then it must be you. thousands of others find them to be among the
best of technical docs out there.
BN> mgjv@tradingpost.com.au (Martien=A0Verbruggen)
>> Was there anything not clear about the utime() entry in perlfunc?
BN> Yes.... this statement... "The first two elements of the list must
BN> be the NUMERICAL access and modification times, in that order." To
BN> me that still doesn't explain why you use the same 2 scalar
BN> arguments together. It seems to me that you'd need 2 different
BN> scalars, such as in the case of rename $oldfile, $newfile .. in
BN> order to change the old value to the new value.
huh? $oldfile, $newfile are needed (i assume rename here) because you
have to identify the oldfile to rename. utime modifies the time stamps
of a single file. notice the plural use of 'timestamps'.
utime LIST
Changes the access and modification times on each file of a list
of files.
ok, you pass to utime a list. you do know what a list is in perl. i know
you know. notice that you can pass MULTIPLE files. you can't rename
multiple files in one call so it only takes oldfile and newfile.
The first two elements of the list must be the NUMERICAL access
and modification times, in that order.
so, element one must be the access time. element two must be the
modification time. then the REST of the list must be the files to set
the times on. is that clear?
and the reason you need both times is because otherwise how could you
set one time and not the other without 2 separate calls? utime sets BOTH
times. so you must pass 2 time values.
if you want to keep one the same, then you read the times with stat and
use a current time value for one of the arguments. simple.
BN> And URI, considering your history with me, I can't take your
BN> comments seriously. You've never helped me. All you've ever done
BN> is criticize and send me angry emails when I was recently being
BN> civil to someone here in this group.
i have definitely offered you help. i just gave up when stright logic
didn't seem to penetrate. i jumped back in here due to seeing martien's
frustration trying to explain the docs. so i just did it here so you
can understand. there is logic behind how (decent) api's are
designed. they just don't randomly pick arguments and stuff with no
rhyme nor reason. utime takes 2 times so you can set either or both of
them in one call. it takes multiple files since you can set the times on
all of them without writing your own loop. so how do you demark which
arguments are the times and which are the files? well, you ALWAYS need 2
time arguments so you make them the first 2 in the list. THEN you have
the varying list of files. simple and basic api design and very logical
and described in the docs.
hth,
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Mon, 19 Nov 2001 14:59:09 +1300
From: "Spidah" <hamilton@nospam.ihug.co.nz>
Subject: Help: Handling browser windows.
Message-Id: <9t9p17$7g5$1@lust.ihug.co.nz>
Is there a way to close a browser window with perl?
My webpage opens a popup window. My perl script is run when a user clicks
the submit button on this popup window. Can I close the popup from my perl
script after it has finished doing its job?
Thanks
H G Laughland
------------------------------
Date: Sun, 18 Nov 2001 20:03:41 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Help: Handling browser windows.
Message-Id: <876687qzya.fsf@limey.hpcc.uh.edu>
>> On Mon, 19 Nov 2001 14:59:09 +1300,
>> "Spidah" <hamilton@nospam.ihug.co.nz> said:
> Is there a way to close a browser window with perl? My
> webpage opens a popup window. My perl script is run when
> a user clicks the submit button on this popup
> window. Can I close the popup from my perl script after
> it has finished doing its job?
If you're talking about CGI programs: no.
CGI programs run on the server, so they cannot directly
affect the browser, or whatever software is at the other
end.
You can make perl output javascript of course (not that it
will help necessarily), but this and related topics moves
us into a newsgroup like
comp.infosystems.www.authoring.cgi
hth
t
--
Oh! I've said too much. Smithers, use the amnesia ray.
------------------------------
Date: Mon, 19 Nov 2001 09:47:49 +0530
From: "Rohit Nadhani" <rohit.nadhani@tallysolutions.com>
Subject: HTTP Server using Sockets
Message-Id: <9tb4kt$pcn$1@news.vsnl.net.in>
Hi,
I am new to Perl and am trying to develop a HTTP server using sockets.
Everything works fine till accept(), but I don't know how to read the
complete HTTP POST and then send a response back to the client.
Thanks in advance,
Rohit
------------------------------
Date: Sun, 18 Nov 2001 15:29:36 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Intrusion Vulerability ActiveState ActivePerl 5.6.1.630
Message-Id: <3BF84460.561E3F4A@stomp.stomp.tokyo>
Chris Welch wrote:
> Last week I installed ActivePerl 5.6.1.630 on Windows 2000 Server with
> IIS 5.0. Days later our email was down.
> '/scripts/..%5c../winnt/system32/cmd.exe' with parameters '%2'
Your IIS server is infected with Code Red IIc.
Godzilla!
------------------------------
Date: Mon, 19 Nov 2001 00:35:59 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Intrusion Vulerability ActiveState ActivePerl 5.6.1.630
Message-Id: <Pine.LNX.4.30.0111190029510.20604-100000@lxplus023.cern.ch>
On Nov 18, Chris Welch inscribed on the eternal scroll:
> The script started from the URL
> '/scripts/..%5c../winnt/system32/cmd.exe' with parameters '%2' has not
> responded within the configured timeout period.
Looks like one of those worms that's going around these days,
attacking MS IIS web servers, such as Nimda. If you're running such a
server, the last thing you need to do is go chasing red herrings.
I really don't believe that Perl is implicated in this.
http://www.cert.org/advisories/CA-2001-26.html might be a good
starting point.
------------------------------
Date: Sun, 18 Nov 2001 22:12:58 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Is two-dim hash inefficient?
Message-Id: <3BF878BA.93F358B2@earthlink.net>
Michael Carman wrote:
[snip]
> foreach my $key1 (%hash) {
> foreach my $key2 (%{$hash{$key1}}) {
> # do something to $hash{$key1}{$key2}
> }
> }
Surely you mean (keys %hash), not (%hash), and similar in the other
spot?
--
Klein bottle for rent - inquire within.
------------------------------
Date: Sun, 18 Nov 2001 22:16:07 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Is two-dim hash inefficient?
Message-Id: <3BF87977.1D22AB5B@earthlink.net>
Markus Dehmann wrote:
[snip]
> And now, just looping over each hash key is so slow, it's
> unbelievable. Does Perl store the two-dimensional hash in an
> inefficient way?
Not especially, although you might possibly be *looping* in an
inefficient way. Your code should look a bit like this:
while( my ($key, $subhash) = each %hash ) {
while( my ($subkey, $value) = each %$subhash ) {
# do something with $key, $subkey, $value.
}
}
--
Klein bottle for rent - inquire within.
------------------------------
Date: Mon, 19 Nov 2001 01:52:54 +0000
From: John Ineson <${spam}$@sneakerpimp.fsnet.co.uk>
Subject: Re: Passing captured data to Apache server??
Message-Id: <mlo9t9.gf7.ln@sneakerpimp.fsnet.co.uk>
In article <7qsI7.1486$n55.163313@news11-gui.server.ntli.net>, Josh wrote:
> I am wanting to capture all data coming into a network card by using a
> socket that will listen to traffic on port 80.
That sounds like a tcpdump/ngrep type job. Or perhaps libpcap if you
want to do it yourself.
> I have two apache servers and I want the program to then pass this captured
> request onto a random apache server.
That doesn't, that sounds more like load balancing. What are you trying
to achieve?
--
John Ineson
`sounds like an interesting text editor... is it included in distros, or a
separate sentient entity in itself?' -- Phil Howard
------------------------------
Date: Mon, 19 Nov 2001 01:39:54 GMT
From: "Scaramouche" <e.quesada@verizon.net>
Subject: perl cgi question:
Message-Id: <KpZJ7.2165$yx5.556991@dfiatx1-snr1.gtei.net>
my question is two fold.
i'm working on a cgi script (to run on ms win2kserver/iis5) and i can
successfully create temp directories and copy files using system().
i was wondering if there was a way to associate a file name to a variable so
i can then make it available to the browser for the user to save. this file
may be a zipped archive or a self extracting executable; this is
specifically a distribution script i'm working on.
if i can do the above, how can i make it available to the browser?
i was thinking of trying the following:
$location = "Location:
http://123.4.567.890/scripts/workTempDir/someVarPointingToFile";
print "$location";
thank you,
rick
------------------------------
Date: Mon, 19 Nov 2001 01:43:02 GMT
From: Danny Aldham <danny@lennon.postino.com>
Subject: Re: Perl generating JavaScript problem
Message-Id: <9t9nov$1im$1@lennon.postino.com>
Amer Neely <aneely@softouch.on.ca> wrote:
> "Mina Naguib" <spam@thecouch.homeip.net> wrote in message news:<Ar_I7.5771$Nq2.307478@weber.videotron.net>...
>> On the web browser's side, do a "VIEW SOURCE". What does the above line get
>> displayed as ?
> It shows up as <script src="mycd.js"></script> or
> <script src="http://127.0.0.1/cgi-bin/sql/mycd.js"></script> depending
> on how I define it. In IE, the page loads fine, but as soon as a call
[snip]
You are expecting the webserver to parse & process this file like it
would standard html. But because the file is not processed by the
web server, the web server does not do the substitution you expect.
You need to print out the contents of mycd.js in the output of your
perl/cgi program.
--
Danny Aldham Providing Certified Internetworking Solutions to Business
www.postino.com E-Mail, Web Servers, Web Databases, SQL PHP & Perl
------------------------------
Date: Mon, 19 Nov 2001 01:49:08 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Perl generating JavaScript problem
Message-Id: <d7pgvtg216kqfjcdgkpr1n8740t61964m7@4ax.com>
Amer Neely wrote:
>> > and like this:
>> > my $SCRIPT_SRC = "http://127.0.0.1/cgi-bin/sql/mycd.js";
Is this the proper URL for a browser coming from the outside world?
--
Bart.
------------------------------
Date: 18 Nov 2001 15:37:49 -0800
From: thegman54@hotmail.com (AleX)
Subject: perl script for finding users
Message-Id: <2fdf3c7a.0111181537.ba8b4bb@posting.google.com>
im looking for anyone that can point me towards a script that will
query doamin controllers in a specific domain for users that are
online at the time.
does anyone have any ideas?
thegman54@hotmail.com
Alex Glickman
Radiant Telecom
------------------------------
Date: 18 Nov 2001 17:49:18 -0800
From: rev_maynard3@hotmail.com (Maynard)
Subject: Sorting files by date on Win32
Message-Id: <a4847dc.0111181749.571e91d5@posting.google.com>
Hello all,
I'm hoping that I'm close to getting this right, but obviously not
quite there. On my server, I process the logs for general stats once
a week; on Sunday, when the log closes, a new one opens and the
process begins again. I'm trying to get a directory of files, sort
them by date, and grab the SECOND newest one (the newest one is the
running log for THIS week, not the complete log from last week).
I can get the dir listing just fine, it's the sorting that I seem to
be struggling with. Perhaps someone can point me in the right
direction... I've looked at the Perldoc pages for "readdir" and "sort"
but still seem unable to make it work.
Below is my code... I haven't yet implemented the processing of the
file, I'm first just trying to get the list of files to look right.
# ----- BEGIN -----
opendir (LogDir,'d:\\logs');
@sorted = sort { -C "LogDir/$a" <=> -C "LogDir/$b"}
grep(!/^\./,readdir(LogDir));
closedir LogDir;
print join ("\n", @sorted);
# ----- END -----
Thanks in advance.
------------------------------
Date: Mon, 19 Nov 2001 02:50:36 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Sorting files by date on Win32
Message-Id: <slrn9vgq8n.e0b.tadmc@tadmc26.august.net>
Maynard <rev_maynard3@hotmail.com> wrote:
>
>I'm hoping that I'm close to getting this right, but obviously not
>quite there.
>I can get the dir listing just fine, it's the sorting that I seem to
>be struggling with. Perhaps someone can point me in the right
>direction...
Try printing out the values that you are filetesting, eg:
print "LogDir/$a";
That should make your problem rather obvious.
>Below is my code... I haven't yet implemented the processing of the
>file, I'm first just trying to get the list of files to look right.
>
># ----- BEGIN -----
>opendir (LogDir,'d:\\logs');
It is conventional to use UPPER CASE for filehandles.
You should check the return value to see if it did what you
asked it to do:
opendir (LOGDIR, 'd:\\logs') or die "could not open $!";
>@sorted = sort { -C "LogDir/$a" <=> -C "LogDir/$b"}
^^^^^^
That is a hard-coded start for the path. They are just "six characters
in a string", not a filehandle.
you want
-C 'd:\\logs/' . $a <=> -C 'd:\\logs/' . $b
or some such instead.
Better yet, use forward slashes instead of backwards slashes
in your paths, then you don't have to double up in double
quoted strings.
>grep(!/^\./,readdir(LogDir));
Space characters are not a scarse resource. Feel free to use as
many as you like to make your code easier to read:
grep( !/^\./, readdir(LogDir) );
Some people like to dispense with unnecessary parenthesis too:
grep !/^\./, readdir LogDir;
You may choose to move the negation into the regex too:
grep /^[^.]/, readdir LogDir;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 19 Nov 2001 00:01:02 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Sorting of arrays by an element of each
Message-Id: <x77ksnfx1i.fsf@home.sysarch.com>
>>>>> "MC" == Michael Cook <mikecook@cigarpool.com> writes:
MC> foreach $CHOSENPRODNUM (@CHOSENPRODNUMS)
MC> {
MC> if ( $CHOSENPRODNUM eq "$row[12]" )
MC> {
MC> $LoL[$count]=( [ "$row[0]", "$row[1]", "$row[2]", "$row[12]",
MC> "$row[13]", "$row[14]", "$row[15]", "$row[16]", "$row[17]" ] );
MC> $count++;
MC> }
MC> }
why the quotes around the elements? that only stringifies them which not
needed. also an array slice will do marvels with that:
$LoL[$count]=( [ @row[0, 1, 2, 12, 13, 14, 15, 16, 17 ] );
now, the paren's there are also not needed as you are assigning a scalar
(the anon array ref). and let's reduce the list of indices using ..
$LoL[$count] = [ @row[0 .. 2, 12 .. 17 ] ;
and that looks a lot nicer.
now, you don't need count there as you are always adding to the end of
the Lol. use push instead:
push @LoL, [ @row[0 .. 2, 12 .. 17 ] ;
now with just that LoL, you can do a basic sort on $row[0] without any
trouble:
@sorted = sort { $a->[0] cmp $b->[0] } @LoL ;
MC> I need to display these items in alphabetical order, sorted by $row[0]
MC> (brand name). I am stumped...
there is no major win to using the ST as it also requires a deref of
$a/$b in the compare block. if you had to extract out the compare key
then it would be a win to use it.
and unless your list is very long then using the GRT is not a win either
as it has more overhead. it is faster in doing the actual sort as it
loses the deref and also the compare block altogether.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Sun, 18 Nov 2001 21:31:54 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Sourcing with a twist of Parsing ?
Message-Id: <3BF86F1A.A90B62B3@earthlink.net>
slightlysprintingdog@ntlworld.com wrote:
>
> I've got some files (cov_sourceme and prot_sourceme) that need
> sourcing before a program is called.
Sourcing means interpreting by a shell. I dunno which shell, since you
haven't said, though I would guess csh.
> When sourced each one makes the program behave differently and I'd
> like to be able to switch "modes" with a Perl script.
>
> I've tried :
>
> | system ($source_cov, $run_sim);
>
> where $source_cov contains the string to source cov_sourceme and
> $run_sim contains the string to execute the program - in this case a
> simulator i.e. :
>
> | $source_cov = "source /path/cov_sourceme";
> |
> | $run_sim = "<long line of swtiches>";
>
> The file cov_sourceme contains a load of 'setenv' and 'set' commands.
Sounds like csh.
> I get errors because cov_sourceme also sources some files itself when
> run. In bash this would be okay but the system command doesn't like
> it.
Because you're using the system command wrong. If you pass a single
item, it splits on whitespace: the first item in the resulting list is
the program, either a relative or absolute path, or something findable
in the PATH environment variable, and each of the other things in the
result list are arguments; each element is one argument. If you pass a
list of items, then the first must be the program, either a relative or
... in the PATH, and each of the other things in the list are arguments
etc.
You've combined the program [well, it isn't really a program, which is
why you're having problems, but anyway], "source", with it's first
argument /path/cov_sourceme, and you've combined all the switches into
one string.
If "source" were a real program, you would be calling it something like
this:
my @switches = split ' ', $run_sim;
system("source", "/path/cov_sourceme", @switches);
or like this:
system("$source_cov $run_sim");
Unfortunatly for you, "source" isn't a real program -- it's a shell
builtin command... so of course system won't find it.
Even if it did find it, you would still have a problem -- system starts
a new, seperate environment, and in that environment, runs the program
which was given as it's argument. Any changes made in that environment
do not exist within perl's environment... so any setenvs which occur
there won't affect the perl process.
> Now, I've written environmental variable parsers before that pick out
> the 'setenv' and 'set' commands and make use of %ENV in perl.
Neat idea... but what does your parser do if these variables are set to
things more complicated than simple strings, or if there is shell flow
control in the file? [Flow control means things like if/else/ etc.]
> I wondered whether I'd be better to write a somewhat more complicated
> version which searches out 'source' commands, locates the files they
> source and applies the environment parsing on them until everything is
> parsed. This could be quite complicated looking a little deeper into
> the files.
You mean that in addition to recognizing 'set' and 'setenv', recognize
'source', and apply it [recursively]?
If you follow that route, you might end up with a csh parser written in
perl. Blech.
> I was wondering what you guys/girls thought of this, is there another
> way ?
Parsing csh isn't really that great an idea... a better would be:
my %acceptable_imports = list of things it's ok to get from the script.
my %acceptable_imports = map { $_ => 1 } @acceptable_imports;
foreach (qx[$source_cov $run_sim >> /dev/null; /bin/env]) {
no re 'taint';
next unless my ($key, $val) = /^([^=]*)=(.*)/;
next unless $acceptable_imports{$key};
$ENV{$key} = $val;
}
Not having some sort of filter to *only* import things you consider safe
to import would be quite unsafe, and could also lead to strange and hard
to find bugs. If you don't know all the names of the things you
consider 'acceptable', but do know what they "look like", then use a
regex. For example, if your source files contained stuff for setting up
a database environment, your code might look like this:
foreach (qx[. /path/setup_database >> /dev/null; /bin/env]) {
no re 'taint';
next unless my ($key, $val) = /^([^=]*)=(.*)/;
next unless $key =~ /^DB[ID]_/;
$ENV{$key} = $val;
}
This would import only DBI_* and DBD_* variables, but no others.
--
Klein bottle for rent - inquire within.
------------------------------
Date: Mon, 19 Nov 2001 03:03:48 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Sourcing with a twist of Parsing ?
Message-Id: <slrn9vgqvl.e28.tadmc@tadmc26.august.net>
Benjamin Goldberg <goldbb2@earthlink.net> wrote:
>my %acceptable_imports = list of things it's ok to get from the script.
^
^
^ I'm sure Benjamin meant @acceptable_imports there instead.
>my %acceptable_imports = map { $_ => 1 } @acceptable_imports;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 18 Nov 2001 22:03:08 -0800
From: "Jonah" <jonah@@adtrackz.com>
Subject: subroutines in separate file
Message-Id: <hx_J7.1608$op.428949@news20.bellglobal.com>
Hi
I want to separate the display subroutines into
another file but they need to have access to
the global variables declared in the main script.
The globals are hidden field values and stuff from
the query string.
Is this possible? I have use strict on.
Example: Main CGI script:
#some code here
#declare globals - get them from $q->param('whatever');
#call display subs from other file that have access to global vars
I can't pass the variables through the function parameters
because on each call of the script, the variable list is different, or
sometimes, not used at all. (depending on which button
is clicked) Doing it that way will be tedious at best.
I would have to create a parameter list for every possible
variable, and then put "" for the value when they are not being
used.
Thanks for any help
------------------------------
Date: Mon, 19 Nov 2001 13:47:46 +1000
From: "Gregory Toomey" <nobody@nowhere.com>
Subject: Re: subroutines in separate file
Message-Id: <Pe%J7.369181$8x1.108864@newsfeeds.bigpond.com>
"Jonah" <jonah@@adtrackz.com> wrote in message
news:hx_J7.1608$op.428949@news20.bellglobal.com...
> Hi
>
> I want to separate the display subroutines into
> another file but they need to have access to
> the global variables declared in the main script.
>
> The globals are hidden field values and stuff from
> the query string.
>
> Is this possible? I have use strict on.
>
You may need packages variables, which are global:
http://perl.plover.com/FAQs/Namespaces.html
gtoomey
------------------------------
Date: Sun, 18 Nov 2001 22:01:35 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: system(), PERL5SHELL won't work
Message-Id: <3BF8760F.F7197C47@earthlink.net>
J wrote:
[snip]
> and it still didn't work. Then I found that the perlport manpage goes
> on to say that "As an optimization, system(LIST) may not call the
> command shell specified in $ENV{PERL5SHELL}." Can this "optimization"
> be disabled or circumvented?
If that optimization occurs, then the program is called directly, with
no shell at all... it doesn't mean that it would call a different shell
instead of perl5shell.
> Any ideas?
Hmm. How about this [untested] code:
use IPC::Open2;
use File::Spec;
open(NUL, "<", File::Spec->devnull())
or die "Couldn't open 'nul' file for read: $!";
my $pid = open2(">&STDOUT", "<&NULL", @your_command);
if( waitpid( $pid, 0 ) ) {
my ($sig, $ret) = ($?&255, $?>>8);
die "@your_command died from signal $sig" if $sig;
die "@your_command exited with code $ret" if $ret;
} else {
die "waitpid failed: $!";
}
To emulate backticks, obviously you would replace ">&STDOUT" with a more
normal filehandle [such as you would use as the first argument of open],
and then read from that filehandle. eg:
my $pid = open2(BACKTICKS, "<&NULL", @your_command);
my $str = join '', <BACKTICKS>;
if( waitpid( $pid, 0 ) ) {
etc.
Since open2 will [in the parent process] close the thing passed as input
filehandle, *don't* pass "<&STDIN" if the prog needs to read from the
keyboard ... instead dup stdin first, and then use the dup. eg:
open(DUP_STDIN, "<&STDIN") or die "Couldn't dup stdin: $!";
my $pid = open2(">&STDOUT","<&DUP_STDIN", @your_command);
As a last resort, you could use Win32::Process to run the program... if
you want to do parent/child io with it, then pick apart IPC::Open3 and
look at the wierd logic in open3(), and write your own version of it,
replacing the system(1, @list) call with something resembling:
Win32::Process::Create(blah,$list[0],"@list",1,blah,blah);
Or something like that. Maybe. I think.
Have you considered switching to *nix? You wouldn't be having this
problem if you did that.
--
Klein bottle for rent - inquire within.
------------------------------
Date: Sun, 18 Nov 2001 20:51:09 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: temporary file deleting too soon
Message-Id: <3BF8658D.91D2216C@earthlink.net>
Keith Clay wrote:
>
> Folks,
>
> I am using modperl to read a picture out of a database, create a temp
> file, using an <img> to display the image and then deleting the file
> using an Apache->request->register_cleanup(\&cleanup).
[snip]
> After this, I build two tables of different user information with data
> from a mysql database. The problem is that I get the 'alt'
> description and the file gets removed before it can be displayed.
Some browsers don't start loading images until after the html page is
entirely loaded. For that matter, image loading might not occur until
the user presses the images button, if he has automatic image loading
turned off. If you're going to print the image out to a temporary file,
you need to make sure it's not cleaned up for quite some time after the
html is sent.
Really, the best thing would be if you could avoid having a temporary
file. Here's a few possible ways of doing it.
You could print out the html and the image as a single two-part http
response, using a content type of multipart/related as the containing
mime-type. The first part would be html, referencing the image using a
"cid:" style url, the second part would be the image, with [along with
the other headers] a Content-Id header. Many browsers don't support
multipart/related, or may only support them within their mail/news
readers.
If the image is small enough is to put it right in the url directly,
using the "data:" type of url. Many browsers don't support this at all.
Best might be to *not* extract the image when generating the html, but
instead have the image url point to a url for a cgi or mod-perl script
which extracts the image and prints it out to the browser... For
example:
if( $database_has_photo ) {
print qq[<img align=left
src="http://foo.bar.com/cgi-bin/getimage.cgi?uid=$uid"
alt="Photo of $uid">\n];
This has the added overhead of having to run a seperate script for
extracting the image, and will result in an extra database query [one
for the stuff for the main html section, and an extra [in a seperate
http request] for the image]. However, not a temp file on disk is a big
bonus -- if the httpd crashes, you don't have to clean anything up.
And, unlike my other two suggestions, the browser wouldn't need any
special capabilities, and if the user has auto image loading off, making
the image a seperate request truly honors that preference, whereas
either a data: url, or a multipart/related with a cid: url would not
[since the image would be loaded regardless of what the user wanted].
--
Klein bottle for rent - inquire within.
------------------------------
Date: Mon, 19 Nov 2001 12:42:40 +1000
From: "Gregory Toomey" <nobody@nowhere.com>
Subject: Re: temporary file deleting too soon
Message-Id: <Lh_J7.369152$8x1.109170@newsfeeds.bigpond.com>
"Benjamin Goldberg" <goldbb2@earthlink.net> wrote in message
news:3BF8658D.91D2216C@earthlink.net...
> Best might be to *not* extract the image when generating the html, but
> instead have the image url point to a url for a cgi or mod-perl script
> which extracts the image and prints it out to the browser... For
> example:
>
> if( $database_has_photo ) {
> print qq[<img align=left
> src="http://foo.bar.com/cgi-bin/getimage.cgi?uid=$uid"
> alt="Photo of $uid">\n];
>
> This has the added overhead of having to run a seperate script for
> extracting the image, and will result in an extra database query [one
> for the stuff for the main html section, and an extra [in a seperate
> http request] for the image]. However, not a temp file on disk is a big
> bonus -- if the httpd crashes, you don't have to clean anything up.
>
Thanks a lot for this suggestion. I never knew you could call a cgi as part
of an IMG tag - I thought you had to link directly to a gif or jpg.
After testing I found you need to: print "Content-Type: image-gif\n\n" then
just write the gif to stdout.
You are a genius!!!
gtoomey
------------------------------
Date: Sun, 18 Nov 2001 22:28:57 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: unresolved symbol Perl_Tstack_sp_ptr from Fcntl.so when invoking perl via Java
Message-Id: <3BF87C79.8886850F@earthlink.net>
Instead of invoking perl from java, try invoking java from perl.
There are any number of modules on CPAN to help you do this.
--
Klein bottle for rent - inquire within.
------------------------------
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 2154
***************************************