[8648] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 2265 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 7 11:17:30 1998

Date: Tue, 7 Apr 98 08:00:26 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 7 Apr 1998     Volume: 8 Number: 2265

Today's topics:
        ??Redirect Script Won't Work With Win95??? (Bob Langdon)
    Re: ??Redirect Script Won't Work With Win95??? <grinch@whoville.com>
    Re: ??Redirect Script Won't Work With Win95??? (Bob Langdon)
    Re: [SOURCE] rot90: New and better MIME format <ghira@mistral.co.uk>
    Re: Anyone working on incorporating perl into Netscape  <grinch@whoville.com>
    Re: Buggy textarea using IE (Robert Prashad(Symantec))
        Chicago.pm Meeting April 10 (DONUTS & DANCING GIRLS) (Jim Allenspach)
    Re: Database sorting problem (Rob Greenbank)
    Re: DB_File and multiple processes <pmarquess@bfsec.bt.co.uk>
    Re: Do I really have to wait for a lengthy script to fi <merlyn@stonehenge.com>
        fgrep'ing around . . . . (Marc Perry)
    Re: How to call a function every 15 seconds or so ? (M.J.T. Guy)
        MacPerl not saving path correctly tchurch@gmu.edu
        Packing? <ben@wallroyds.demon.co.uk>
        Perl and ODBC <dangtrkhng@mail.dotcom.fr>
        Perl Resource Kit <johnc@interactive.ibm.com>
        perl w/ SAS <jaudall@students.wisc.edu.nospam>
        Perl-to-C++ translator tool ?... <uwechue@puma.att.com>
    Re: Perl5_on_Solaris_2.6 (M.J.T. Guy)
    Re: Porting HTML into CGI Perl routine with variables. (Andrew M. Langmead)
    Re: Q: Dynamic namespace change? <merlyn@stonehenge.com>
    Re: Q: Dynamic namespace change? (Andrew M. Langmead)
    Re: Ref Op in Context (was: Anon Scalar Expression) (M.J.T. Guy)
    Re: remove dir error <merlyn@stonehenge.com>
        Sort on values in associative arrays? <kenny@weng.dk>
    Re: Sort on values in associative arrays? <kenny@weng.dk>
    Re: Sort on values in associative arrays? <kompas@galaxy.uci.agh.edu.pl>
        Tom C. is "very useful" (David Alan Black)
        treeview interface with perl/cgi? mm_jones@rocketmail.com
    Re: Trimming blank lines from end of file? (Andrew M. Langmead)
    Re: using modules (Andrew M. Langmead)
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 07 Apr 1998 08:23:28 -0400
From: webmaster@retailernews.com$%^&* (Bob Langdon)
Subject: ??Redirect Script Won't Work With Win95???
Message-Id: <webmaster-ya02408000R0704980823280001@news.alt.net>


Hi,
I recently discovered that Winodws '95 users visiting my site with Explorer
4.0 can't use my popup menu. It's a simple server-side script--works fine
in all Mac browsers and I can't for the life of me figure out why it won't
work for Windows.  I mean, It's a SERVER-SIDE appl;ication.

When they selct their destination and push the "GO" (submit) button<
Ex-plorer return the error message: "Can't load page
http://RetailerNews.com/cgi-bin/suid/~retailer/clickgo.cgi?goto=http://www.b
lah bnlah blah..."  or something like that.

Any thoughts on this???

Thanx,

-- 
+++++++++++++++++++++++++++++++++++++++++++++++++++++
Bob Langdon
webmaster@retailernews.com
http://RetailerNews.com
_Retailer News Online_  Magazine -- for retail
business owners, managers, and salespeople.
                           --brought to you by:
Dealer Support Services
--website design and maintenance
++++++++++++++++++++++++++++++++++++++++++++++++++++


------------------------------

Date: Tue, 7 Apr 1998 08:54:25 -0400
From: "Grinch" <grinch@whoville.com>
Subject: Re: ??Redirect Script Won't Work With Win95???
Message-Id: <6gd6u0$92j@fridge.shore.net>

Bob Langdon wrote in message ...

>I recently discovered that Winodws '95 users visiting my site with Explorer
>4.0 can't use my popup menu. It's a simple server-side script--works fine
>in all Mac browsers and I can't for the life of me figure out why it won't
>work for Windows.  I mean, It's a SERVER-SIDE appl;ication.
>
>When they selct their destination and push the "GO" (submit) button<
>Ex-plorer return the error message: "Can't load page
>http://RetailerNews.com/cgi-bin/suid/~retailer/clickgo.cgi?goto=http://www.
b
>lah bnlah blah..."  or something like that.

Well, first off, the problem has nothing to do with Perl, or with Windows,
or even with MSIE. The cause is simply an invalid URL, and the fact that
different browsers have different ways of handling such.

Have a look at the "action" attribute of the form element. You're trying to
submit your form to "http://RetailerNews/cgi-bin..."  You've left off part
of the machine name. Specifically, you've ommitted the ".com" at the end.

Your browser is obviously detecting the error and handling it transparently
by trying to contact "RetailerNews.com" when it fails to contact
"RetailerNews"


I'd suggest one of the "comp.infosystems.www.*" newsgroups as a better
source, if you need more info on this, or help with your HTML.

-grinch

--
"Of course coffee doesn't make the world go around. It
just makes it go faster." - me

Sherm Pendley
grinch@whoville.com
http://www.whoville.com





------------------------------

Date: Tue, 07 Apr 1998 10:33:25 -0400
From: webmaster@retailernews.com$%^&* (Bob Langdon)
Subject: Re: ??Redirect Script Won't Work With Win95???
Message-Id: <webmaster-ya02408000R0704981033250001@news.alt.net>

Doh!  I didn't see that. A typo, but it still worked on Mac.  Thanx for
pointing that out to me.

In article <6gd6u0$92j@fridge.shore.net>, "Grinch" <grinch@whoville.com> wrote:

> Bob Langdon wrote in message ...
> 
> >I recently discovered that Winodws '95 users visiting my site with Explorer
> >4.0 can't use my popup menu. It's a simple server-side script--works fine
> >in all Mac browsers and I can't for the life of me figure out why it won't
> >work for Windows.  I mean, It's a SERVER-SIDE appl;ication.
> >
> >When they selct their destination and push the "GO" (submit) button<
> >Ex-plorer return the error message: "Can't load page
> >http://RetailerNews.com/cgi-bin/suid/~retailer/clickgo.cgi?goto=http://www.
> b
> >lah bnlah blah..."  or something like that.
> 
> Well, first off, the problem has nothing to do with Perl, or with Windows,
> or even with MSIE. The cause is simply an invalid URL, and the fact that
> different browsers have different ways of handling such.
> 
> Have a look at the "action" attribute of the form element. You're trying to
> submit your form to "http://RetailerNews/cgi-bin..."  You've left off part
> of the machine name. Specifically, you've ommitted the ".com" at the end.
> 
> Your browser is obviously detecting the error and handling it transparently
> by trying to contact "RetailerNews.com" when it fails to contact
> "RetailerNews"
> 
> 
> I'd suggest one of the "comp.infosystems.www.*" newsgroups as a better
> source, if you need more info on this, or help with your HTML.
> 
> -grinch
> 
> --
> "Of course coffee doesn't make the world go around. It
> just makes it go faster." - me
> 
> Sherm Pendley
> grinch@whoville.com
> http://www.whoville.com

-- 
+++++++++++++++++++++++++++++++++++++++++++++++++++++
Bob Langdon
webmaster@retailernews.com
http://RetailerNews.com
_Retailer News Online_  Magazine -- for retail
business owners, managers, and salespeople.
                           --brought to you by:
Dealer Support Services
--website design and maintenance
++++++++++++++++++++++++++++++++++++++++++++++++++++


------------------------------

Date: 03 Apr 98 20:30:21 +0000
From: "Adam Atkinson" <ghira@mistral.co.uk>
Subject: Re: [SOURCE] rot90: New and better MIME format
Message-Id: <274.397T1091T12303196@mistral.co.uk>

Well, an option to have the columns go from right to left would clearly be
nice as well. (i.e. text top to bottom within columns, column 1 at
right-hand end of page).

-- 
Adam Atkinson (ghira@mistral.co.uk)
Eschew obfuscation!



------------------------------

Date: Tue, 7 Apr 1998 08:18:38 -0400
From: "Grinch" <grinch@whoville.com>
Subject: Re: Anyone working on incorporating perl into Netscape source?
Message-Id: <6gd4qv$6k7@fridge.shore.net>

Tim Gray wrote in message ...

>Now that the source code for Netscape Communicator is out, I was
>wondering if any industrious hacker out there is working on putting
>something similar to activestate's PerlScript into the client.

There's been some discussion concerning using ActiveX controls and
Scripting. This would, of course, include PerlScript, which (once installed)
works with any app that uses Active Scripting.

For up-to-date info on Mozilla, check out (URL: http://www.mozilla.org ).

>soon after it was developed, somebody would probably make it
>compatible with MSIE somehow.

But... PerlScript already works with IE. The problem is, you can't depend on
it being installed, while JScript & VBScript are installed along with the
browser. That severely limits its usefulness for client-side scripting.


Personally, as long as I'm gonna dream, I'm dreaming of Penguin applets. ;-)

-grinch

--
"Of course coffee doesn't make the world go around. It
just makes it go faster." - me

Sherm Pendley
grinch@whoville.com
http://www.whoville.com





------------------------------

Date: Tue, 07 Apr 1998 13:57:04 GMT
From: rprashad@symantec.com (Robert Prashad(Symantec))
Subject: Re: Buggy textarea using IE
Message-Id: <352a2f41.2109000@news.symantec.com>

Thanks for the suggestion I will try the work around while I hunt down
the source of the problem.  As for the textarea I havn't altered it in
any way.

Rob.

On Tue, 07 Apr 1998 01:24:03 +0100, Matt Pryor
<matt@whiterabbit.co.uk> wrote:

>Hi Robert,
>
>(Think that last post might just start a flame war...oh well...)
>
>I'm not sure why IE inserts that... I've never encountered it before...
>Are you using clientside Javascript to alter the textarea contents at
>all?
>
>However, you could work around the problem by putting something like
>this in your Perl source:
>
>$textarea =~ s/\^M~nl~//g;
>
>Better to find out why it's happening, though, than just treat the
>symptom.
>
>
>
>Robert Prashad wrote:
>> 
>>         I have a script that saves forms to a file.  It works great
>> with Navigator.  However, Internet Explorer inserts ^M~nl~  into every
>> textarea regardless of the user typing in text or not. The ^M shows up
>> as just a box.
>>         Does anyone know how I can prevent these from getting
>> inserted?
>> 
>>         Your help is much appreciated.
>> 
>> Rob



------------------------------

Date: 7 Apr 1998 07:34:14 -0500
From: jima@MCS.COM (Jim Allenspach)
Subject: Chicago.pm Meeting April 10 (DONUTS & DANCING GIRLS)
Message-Id: <6gd6g6$7o0@Venus.mcs.net>
Keywords: chicago perl mongers meeting

	After much deliberation, the first meeting of the Chicago Perl
Mongers has been scheduled for this Friday, April 10, at Cafe Iberico, 739
N. LaSalle. Any interested parties in the Chicago area are invited to
attend. Meet there sometime after 5 for drinks and possibly dinner. (And
the traditional donuts and dancing girls, of course.)

	Some pertinent net resources:

http://www.pm.org		Perl Mongers Website
http://cafe-iberico.com		Cafe Iberico's Website
jima@mcs.com			Write away for more info!

	Remember, ONLY Chicago.pm provides donuts and dancing girls at
every meeting! Ask about our obfuscated sig!
jma



------------------------------

Date: Tue, 07 Apr 1998 14:03:54 GMT
From: rob@frii.com (Rob Greenbank)
Subject: Re: Database sorting problem
Message-Id: <352c316b.211536703@news.frii.com>

On Fri, 03 Apr 1998 10:01:27 -0600, Andy Biegel
<chefandy@culinary.com> wrote:

>I have a flatfile database like such:
>
>9|04-02-98|today|364604|today|NULL
>10|04-01-98|yesterday|364603|yesterday|NULL
>11|04-03-98|tomorrow|364605|tomorrow|NULL
>
>I'm trying to sort the database by the fourth field in each record
>(364604,364603,364605,...). Any suggestions how to do this? Thanks.
>
>Andy Biegel
>andy@culinary.com
>

Andy,

There is lots of stuff in the Perl documentation on this, but to give
you a boost (I remember how much time I spent sorting through the
documentation) here's how I would do it:
	#!/usr/local/bin/perl -w
	use strict;

	my @rawData =
	(
	    '9|04-02-98|today|364604|today|NULL',
	    '10|04-01-98|yesterday|364603|yesterday|NULL',
	    '11|04-03-98|tomorrow|364605|tomorrow|NULL'
	);

	sub byThirdField
	{
	    my ($a3, $b3);
	    (undef, undef, undef, $a3, undef) = split(/\|/, $a);
	    (undef, undef, undef, $b3, undef) = split(/\|/, $b);
	    $a3 <=> $b3;
	}

	foreach (sort byThirdField @rawData)
	{
	    print "$_\n";
	}

The "byThirdField" lets you define your own sort routine.  Learn to
use these functions and your life will be simpler.  The "undef" is a
handy way to ignore a field (documented undef "undef").

Good luck

	Rob Greenbank
	(rob@frii.com)



------------------------------

Date: Tue, 7 Apr 1998 13:08:29 +0100
From: "Paul Marquess" <pmarquess@bfsec.bt.co.uk>
Subject: Re: DB_File and multiple processes
Message-Id: <6gd506$ldd$1@pheidippides.axion.bt.co.uk>

[Posted & Mailed]

otis@POPULUS.net wrote in message <6g3ser$vu$1@nnrp1.dejanews.com>...
>Hello,
>
>I would like to do this, but I'm not sure if it is possible:
>
>script A uses DB_File and generates a DBM (by using DB_File).
>
>I want to have scripts B and C that can read that DBM file and also delete
>hash elements of that DBM that script A generates.
>
>Can that be done?
>Can scripts B and C read and modify (delete) elements of that hash at the
same
>time that script A is generating the file?
>
>Does DB_File provide some kind of internal locking/serialization mechanism
>that will allow me to have multiple processes modify the same DBM without
>having to handle those acecsses myself?


Nope. You have to manage the locking yourself.  Have a read at the section
called "Locking Databases" in the DB_File documentation.

>If I use DB_File and HAVE Berkeley DB installed oon my machine, will
DB_File
>use Berkeley DB or something else? Thanks!


DB_File is a front end to Berkeley DB.

Paul








------------------------------

Date: 07 Apr 1998 06:14:56 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: dr.schueller@forum-medizin.com
Subject: Re: Do I really have to wait for a lengthy script to finish
Message-Id: <8cn2dxdb8v.fsf@gadget.cscaper.com>

>>>>> "schueller" == schueller  <dr.schueller@forum-medizin.com> writes:

schueller> I want to run cgi scripts from my browser (or having anyone
schueller> else to do that) without having to wait for the lengthy
schueller> script to finish. It would be nice, if the script could
schueller> report something to the user and close the connection while
schueller> still doing the rest of the job.

One of my recent columns for WebTechniques showed how to do that, exactly.
See column # 20 in the online archive at:

	http://www.stonehenge.com/merlyn/WebTechniques/

schueller>  This task has been asked before (it was about a mailing
schueller> list, where someone posting an article had to wait for a
schueller> lot of emails to be sent), but the answers given there
schueller> (chron jobs doing the rest) are not suitable for me because
schueller> of lack of sufficient chron job possibilities (my ISP
schueller> restricts me here).

There are times that you will need to do a task that exceeds what
you can get from your current ISP.  I hope you're aware of that. :-)

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 147 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


------------------------------

Date: Tue, 7 Apr 1998 14:07:37 GMT
From: mdperry@gpu.utcc (Marc Perry)
Subject: fgrep'ing around . . . .
Message-Id: <Er1r8p.Luz@alfalfa.utcs.utoronto.ca>

 I have been using the unix csh fgrep command to find simple short
string patterns in files.  Life is much easier for me if I use the -f
flag to specify the filename containing the files I want to search for.
It turns out that fgrep has an upper limit (between 360-478 patterns--I
am not precisely sure where the boundary is) that I would like to get around.

I imagine a perl script exists that has the same functionality as
fgrep (but without the limitations)--but I have yet to learn perl 
programming skills.  My main foray besides purchasing several books
has been to use a program in the camel book named wordcount.  Using
a web browser I found code for cgrep, and tgrep.  Could someone please 
point me to a source for fgrep?                         

Thanks!
marc.perry@utoronto.ca


------------------------------

Date: 7 Apr 1998 14:19:32 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: How to call a function every 15 seconds or so ?
Message-Id: <6gdclk$pld$1@lyra.csx.cam.ac.uk>

Michael Shavel <mshavel@erols.com> wrote:
>I am trying to create a sub routine in perl that will  run a ps -ef |grep
>$pidnum   on the pidnum I get from running the process. I would like  to
>run the subroutine every 15 seconds or so to check and see if that
>particular query is finished.

There are cheaper and simpler ways of tracking processes than using
ps.   If the processes are your children, simply use waitpid() with the
WNOHANG option.    Or you might set $SIG{CHLD}.    See the perlipc man
page for lots of examples.

Alternatively, if the processes belong to you but are _not_ your children,

     kill 0, $pid or print "Process $pid has terminated\n";

will do what you want.


Mike Guy


------------------------------

Date: Tue, 07 Apr 1998 07:28:51 -0600
From: tchurch@gmu.edu
Subject: MacPerl not saving path correctly
Message-Id: <6gd662$2c5$1@nnrp1.dejanews.com>

I am not sure why I am having this problem, but this is what happens:
If I check the preferences before I save my application, I see
Workstation:Applications:MacPerl f:lib.  I then save the app as a standalone.
When I try to run it, I get the message that Mac::Files cannot be found in
@INC.  I then check the preferences under the MacPerl instance that came up
when I tried to run the program.  The path is see is:
Workstation:Applications:lib.  Somehow the MacPerl f folder got dropped out
of the path.  Does anyone have a clue as to why this is taking place?

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


------------------------------

Date: Tue, 7 Apr 1998 15:25:11 +0100
From: "bjf" <ben@wallroyds.demon.co.uk>
Subject: Packing?
Message-Id: <891959120.15828.0.nnrp-09.c2de5b4a@news.demon.co.uk>

Hello again ...

I was wondering, how can I remove all the dots from an IP address ... For eg
 ...

"104.204.54.57" to "1042045457" ???

Here was what I tried ...

$ip = $ENV{'REMOTE_ADDR'};
@digits = split (/\./, $ip);
$address = pack ("a8", @digits);

But, it doesn't work - I guess. It would be nice if anyone could tell me how
to do this in a right way.

Thank you very much for reading this.

Best Regards

Ben :-)





------------------------------

Date: Tue, 07 Apr 1998 14:15:16 -0700
From: "DANG-TRUNG K.N." <dangtrkhng@mail.dotcom.fr>
Subject: Perl and ODBC
Message-Id: <352A9764.119C@mail.dotcom.fr>

Hello,

I wonder how I could link my web home page with an ODBC database like
Access ? I heard that I would have to program a Perl module but I have
no more informations about that ...

Can anybody help me ?
Thanks,

Khoi.


------------------------------

Date: Tue, 07 Apr 1998 10:33:20 +0000
From: John Call <johnc@interactive.ibm.com>
Subject: Perl Resource Kit
Message-Id: <352A009C.D02B520D@interactive.ibm.com>

I was in Barnes & Noble the other day and saw a huge, bundled package
called The Perl Resource Kit. I read some of the advertising but have
lived in America long enough not to believe everything I read. Is this a
good thing to own? It was $150, which is a pretty penny for me but would
be okay if it was a super product.

I would really like to hear from people who have used it and how it has
helped with productivity, etc.

--

John Call
IBM Interactive Media



------------------------------

Date: Tue, 07 Apr 1998 09:28:20 -0500
From: Bike&Linux <jaudall@students.wisc.edu.nospam>
Subject: perl w/ SAS
Message-Id: <352A3804.C521BD78@students.wisc.edu.nospam>

I'm in the process of sorting through thousands of pages of SAS output.
I would like to write a perl script that would 'pull' out certian pages
depending on the arguments I give.

for instance, I would like to be able to pass a number of conservative
agruments specifing the p-value, F test, R-sq, etc. for the pages I want
to keep - thus I only have to look at fewer pages with significance
tests that are at least in the ball park.  There's probably something
written is sas to do it - but perl seems quite capable as well.

I'm posting because this seems like such an obvious function for perl
that someone must have written something along these lines.  I just
wanted to hear what's out there before I start writing my own scripts
from scratch.

Josh



------------------------------

Date: Tue, 07 Apr 1998 10:23:06 -0400
From: Oke Uwechue <uwechue@puma.att.com>
Subject: Perl-to-C++ translator tool ?...
Message-Id: <352A36C8.7905F270@puma.att.com>

Does anyone know of a tool that does automatic conversion of Perl
scripts to either C or C++ ?
Also, is it possible for Perl code to use C/C++ libraries directly?
thanks in advance,

-uwechue@puma.att.com



------------------------------

Date: 7 Apr 1998 13:52:43 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Perl5_on_Solaris_2.6
Message-Id: <6gdb3b$nri$1@lyra.csx.cam.ac.uk>
Keywords: 64-bit

 <rproulx@rap.East.Sun.COM> wrote:
>Does anyone know how to make perl5 use 64-bit integers on SUN Solaris 2.6?
>I need to be to have 64-bit integers like 0xFFFF.FFFF.FFFF.FFFF work!
>P.S. I am on an ultra-sparc I

You can't, currently.    See the Math::BigInt module instead (included
with the standard distribution).


Mike Guy


------------------------------

Date: Tue, 7 Apr 1998 13:35:31 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Porting HTML into CGI Perl routine with variables.
Message-Id: <Er1pr9.GIt@world.std.com>

"Charles R. Thompson" <RainCloudStudios@worldnet.att.net> writes:

>This effectively pulls in every line of an HTML file and renders it to the
>screen. However... within the source I see things like this...

><form METHOD="post" ACTION="$this_script_url">
><input type="hidden" name="setup_file" value="$form_data{'setup_file'}">
><input type="hidden" name="view" value="world">
><input type="hidden" name="session_file" value="$session_file">
><input type="hidden" name="sort_by" value="$index_of_field_to_be_sorted_by">

>The values of the fields do not get set in this loop I have created.

You are confusing the difference between what the perl interpreter
does when it reads a file and what the file reading operations of your
script do when they read a file.

Simply reading a file with the <> operator is not going to interpolate
variables, otherwise the mimalist cat clone script:

#!/usr/bin/perl -w
while(<>) {
  print;
}

wouldn't work right as soon as it hit a dollar sign.

You might want to take a look at the FAQ entry "How can I expand
variables in text strings?"<URL:http://www.perl.com/CPAN/doc/
manual/html/pod/perlfaq4/How_can_I_expand_variables_in_te.html>

You might be able to do something eith eval() or do().

You might want to take a look at the Text::Template module instead.
<URL:http://reference.perl.com/module.cgi?Text::Template>
-- 
Andrew Langmead


------------------------------

Date: 07 Apr 1998 06:29:24 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: "Simon (V. Ilyushchenko)" <simonf@rrg.msk.su>
Subject: Re: Q: Dynamic namespace change?
Message-Id: <8c90phdakr.fsf@gadget.cscaper.com>

>>>>> "Simon" == Simon (V Ilyushchenko) <simonf@rrg.msk.su> writes:

Simon> Here a goes a Tough Question. Suppose I need a module (call it A) that
Simon> would be called from module B with a code string as a parameter. Then
Simon> module A will want to 'eval' that string using variable namespace of
Simon> module B. How is this possible? 

Simon> I know that all the namespaces are accessible via a global hash, but I
Simon> am looking for an elegant way. I tried passing the package name as a
Simon> function parameter and then issuing "package $package", but compiler
Simon> barked on me.

It would make more sense for module B to pass a coderef to module A,
possibly wrapped in an eval *block* in case it "barked". :-)  Like so:

	package B;
	...
	$result = A::dothis(sub { my @args = @_; ... }, @other_parms);
	...
	package A;
	...
	sub dothis {
		my $codeblock = shift; # this is a CODEref
		my @otherparms = @_;
		...
		my $answer = eval { $codeblock->(@params_if_any) };
		$answer = "died with $@" if $@;
		$answer;
	}

Notice that the coderef passed in has access to all the lexical vars
defined at the time, as well as being in package A as a default.  Also
notice that we can pass vars from B to A, and even pass in vars from A
to B.  And finally, notice that the code is compiled *once* instead of
every time it gets passed.  This is a Big Win.

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 147 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


------------------------------

Date: Tue, 7 Apr 1998 13:43:47 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Q: Dynamic namespace change?
Message-Id: <Er1q50.Mvv@world.std.com>

"Simon (V. Ilyushchenko)" <simonf@rrg.msk.su> writes:

>Here a goes a Tough Question. Suppose I need a module (call it A) that
>would be called from module B with a code string as a parameter. Then
>module A will want to 'eval' that string using variable namespace of
>module B. How is this possible? 


Since you are going to eval() the string, why not interpolate the
package directive and the code into a larger string and eval the whole
thing.

By the way, do you know that you can get the package that the calling
function is in with the caller() function?

sub eval_code_in_callers_package {
  my(@code) = @_;
  my $package = caller;
  eval "package $package; @code";
}

The package directive cannot contain a variable, but this way, by the
time the perl compiler sees it (after the variable intepolation) it is
a constant.

-- 
Andrew Langmead


------------------------------

Date: 7 Apr 1998 13:37:47 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Ref Op in Context (was: Anon Scalar Expression)
Message-Id: <6gda7b$nc5$1@lyra.csx.cam.ac.uk>

In article <3528F7E9.22CA@min.net>, John Porter  <jdporter@min.net> wrote:
>M.J.T. Guy wrote:
>> That is currently the case, but it's a bug.  
>> \ is meant to evaluate its
>> argument in the same context as it was called in.
>> I believe this will be mended in 5.004_05.
>> 
>> Note that \($x,$y,$z) will then be equivalent to ($x,$y,\$z) in a scalar
>> context, but it's rather hard to tell the difference.

I obviously should have put a smiley there ...

>So what exactly is (will be) the difference?  I can see that if the
>results are discarded, it's inefficient to bother with taking the
>references...
>
>Is it that we want $x and $y, above, to be evaluated in list context,
>even though $z might be getting scalar context?  That would seem
>very weird to me. Why would that be better?

The argument of \ should be evaluated in scalar context.   Hence, from
the definition of the , operator, each of its arguments should be
evaluated in scalar context, and the last one returned.   This last one
has the \ operator applied to it.

Of course, this discussion is being applied to a pretty silly example  -
it just happened to be the example the thread started with.   The bug
was noticed by people using the idiom

 "Here is a scalar expression ${\ myfunc() } interpolated in a string."

myfunc() is currently called in list context, which rather spoils
the point of the exercise.


Mike Guy


------------------------------

Date: 07 Apr 1998 06:21:29 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: Haaino Beljaars <beljaars@fys.ruu.nl>
Subject: Re: remove dir error
Message-Id: <8cd8etdaxy.fsf@gadget.cscaper.com>

>>>>> "Haaino" == Haaino Beljaars <beljaars@fys.ruu.nl> writes:

Haaino> Hi,
Haaino> From Randal Schwartz I got the following code to remove empty directories:

Haaino> #!/usr/bin/perl

Haaino> use File::Find qw(finddepth $name);
Haaino>     my $guest = getpwnam "guest";
Haaino>     finddepth sub {
Haaino>         return if $name eq "/usr/guest";
Haaino>         return if (stat $_)[4] != $guest;
Haaino>         rmdir $_; # ignore errors
Haaino>     }, "/";



Haaino> But unfortunaly something goes wrong:

Haaino> "$name" is not exported by the File::Find module at ./del line 3
Haaino> Can't continue after import errors at ./del line 3
Haaino> BEGIN failed--compilation aborted at ./del line 3.

Haaino> Can anybody tell me how to what went wrong and how to correct it...

Yes.  I mis-remembered the File::Find manpage.  But it's starting to
sound like you are just taking what we say verbatim, instead of
*understanding* what the code above does.  This is the difference
between me giving you a fish, and teaching you how to fish.  I'm not
interested in merely being a fish-for-free store. :)

However, to fix this, remove $name from the export list, and change
$name in the anonymous sub to $File::Find::name.  And now I'm
wondering why File::Find doesn't optionally export $name.  How odd.

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 147 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


------------------------------

Date: Tue, 7 Apr 1998 14:09:14 +0200
From: <kenny@weng.dk>
Subject: Sort on values in associative arrays?
Message-Id: <6gd51t$1ffe$1@news-inn.inet.tele.dk>

How do I sort on the values in an associative array while
using foreach?




------------------------------

Date: Tue, 7 Apr 1998 14:31:56 +0200
From: <kenny@weng.dk>
Subject: Re: Sort on values in associative arrays?
Message-Id: <6gd6cf$5ego$1@news-inn.inet.tele.dk>

Sorry, found out.
kenny@weng.dk skrev i meddelelsen <6gd51t$1ffe$1@news-inn.inet.tele.dk>...
>How do I sort on the values in an associative array while
>using foreach?
>
>




------------------------------

Date: 7 Apr 1998 14:36:16 +0200
From: Piotr Piatkowski <kompas@galaxy.uci.agh.edu.pl>
Subject: Re: Sort on values in associative arrays?
Message-Id: <6gd6k0$b25$1@galaxy.uci.agh.edu.pl>

kenny@weng.dk wrote:
: How do I sort on the values in an associative array while
: using foreach?

foreach my $k ( sort { $hash{$a} cmp $hash{$b} } keys %hash ) {
  print "$k -> $hash{$k}\n";
}

-- 
Piotr Pi1tkowski, Uczelniane Centrum Informatyki, AGH Krakow, POLAND


------------------------------

Date: 7 Apr 1998 10:10:26 -0400
From: dblack@pilot.njin.net (David Alan Black)
Subject: Tom C. is "very useful"
Message-Id: <6gdc4i$1jl@pilot.njin.net>

Hello -

Yes, it's official.  On p. 11 of the USENIX brochure ("About the
Instructors"), there's a picture of Tom, a bio, and, in the margin,
a floating box with the endorsement "Very useful." from Kevin Conlon
at the US Census Bureau.

It's probably on account of all that stuff about the Census class
variable in perltoot.  But we've known it all along.


David Black
dblack@pilot.njin.net
dblack@icarus.shu.edu  (when that newsfeed worked :-(  )
dblack@saturn.superlink.net  (when that computer is up :-(  )


P.S. For those who have forgotten what "deadpan humor" is: yes, I
do know that the box doesn't really refer to Tom.  But it really does
look like it does.  And it could, on factual grounds, with room
to spare :-)



------------------------------

Date: Tue, 07 Apr 1998 08:39:04 -0600
From: mm_jones@rocketmail.com
Subject: treeview interface with perl/cgi?
Message-Id: <6gda9o$6do$1@nnrp1.dejanews.com>

I was wondering if anyone's managed to create a workable treeview (like
Windows explorer) type interface with Perl for use on a webpage.  Is this even
a feasible idea with a tree containing thousands of documents?  We're thinking
about this implementation for our current project, but my fear is that with
over 20000 (mostly small) text documents in our tree and more coming in daily,
this is not going to be workable.

Any ideas, suggestions or even a pointer to an example would be much
appreciated.
M. Jones
mm_jones@rocketmail.com

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


------------------------------

Date: Tue, 7 Apr 1998 14:17:18 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Trimming blank lines from end of file?
Message-Id: <Er1rou.1Ev@world.std.com>

David Lee Lambert <lamber45@EGR.msu.edu> writes:
> I want each file that's about to be diffed to have
>one and only one blank line at the end.  

The main point seems to be, if you have a blank line, you don't know
if a non-blank line follows. So you have to store all blanks you come
acrross until you find a nonblank, and then you spit out all the held
blanks. At the end of file, you'll have a bunch of blanks held in
reserve, but no nonblank to free them, so just spit out one blank at
the end.


perl -ne 'push @bl,$_ if/^$/;print @bl,$_ and @bl=() if/./;END{print "\n"}'
-- 
Andrew Langmead


------------------------------

Date: Tue, 7 Apr 1998 14:29:38 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: using modules
Message-Id: <Er1s9E.9HK@world.std.com>

amehdiza@joule.ee.calpoly.edu (Ali Mehdizadeh) writes:
>Andrew M. Langmead (aml@world.std.com) wrote:
>: 3. Windows NT is not an POSIX complient system (except for a
>: perversely comical POSIX mode that has no access to the any Win32
>: functions. Including all of the graphics functions.) so it does not
>: have a POSIX module.

>point 3 above leads me to believe that 1 and 2 do not apply to me:)
>So, what are my options? 

Your in luck, Mike Heins as implemented a subset of POSIX functions
for use on NT in his MiniVend package. 

<URL:ftp://ftp.minivend.com/pub/POSIX.pm>

(And no, I intentionally trying to be obnoxious by holding only useful
information, I just didn't look at it until this morning.)

>Probably... I can probably use the code for the ceil() function 
>in the POSIX module and just put it in my program.

Probably not, the POSIX.pm is a wrapper over the C library
functions. You wouldn't be able to find ceil anywhere in the perl part
of the module. In the .xs part, you would just be able to find the
call to the C library. If you looked a freely distristributable C
library souce, you could probably find the C implementation.

-- 
Andrew Langmead


------------------------------

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 2265
**************************************

home help back first fref pref prev next nref lref last post