[21753] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3957 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 11 21:05:35 2002

Date: Fri, 11 Oct 2002 18:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 11 Oct 2002     Volume: 10 Number: 3957

Today's topics:
    Re: attach debugger to running process <nospam-abuse@ilyaz.org>
    Re: Convert Perl script to C program (and Why was this  <Cpt.Fredo@S.S.No.Spam>
    Re: How to get perldb's x programmatically? <comdog@panix.com>
    Re: ithreads, perl 5.8 and shared objects <nospam-abuse@ilyaz.org>
    Re: ithreads, perl 5.8 and shared objects <nospam-abuse@ilyaz.org>
    Re: ithreads, perl 5.8 and shared objects <nospam-abuse@ilyaz.org>
        OLE Automation via Perl (Daniel Mahoney)
    Re: OLE Automation via Perl <ron@savage.net.au>
    Re: Problems with MSIE in combination with MAC not show (David Efflandt)
    Re: searching an array. <ajamtgaa@cisco.com>
    Re: STDIN and choices on screen? (Tad McClellan)
    Re: Switching from Python to Perl <comdog@panix.com>
        Unrecognized character \x14 at line1 <nishi.bhonsle@oracle.com>
        Web Design Resources & Tools...  all on one page! <asg779e@earthlink.net>
    Re: Why is 'defined @x' deprecated? <heather710101@yahoo.com>
    Re: Why is 'defined @x' deprecated? <heather710101@yahoo.com>
    Re: Why is 'defined @x' deprecated? <uri@stemsystems.com>
    Re: Why is 'defined @x' deprecated? <uri@stemsystems.com>
    Re: Why is 'defined @x' deprecated? (Jay Tilton)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 12 Oct 2002 00:27:59 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: attach debugger to running process
Message-Id: <ao7qaf$cd4$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Andrew V. Tkachenko
<pobugfix@peterlink.ru>], who wrote in article <ao6sgs$hdt$1@news.sovam.com>:
> Hello All.
> Is it possible to debug already running perl program? I mean in a way as 
>    I usually do with gdb - attaching debugger to a process by its pid?

'Perl debugger' is just a tiny modification of the Perl interpreter;
there is no separate "debugger" process.  But I can modify your
question:

  can I start a Perl process so that later I may switch the Perl debugger on?

Then the answer is yes.  Just `N'onStop perl -d, and send SIGINT
later.  (If the process has no TTY attached, you need some kind of
Term::Rendezvous to use IPC to communicate the TTY to the process; or
you can use `C'reateTTY with newer Perls.)

Hope this helps,
Ilya



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

Date: Sat, 12 Oct 2002 01:02:38 GMT
From: "Fredo" <Cpt.Fredo@S.S.No.Spam>
Subject: Re: Convert Perl script to C program (and Why was this group's name changed?)
Message-Id: <OwKp9.4483$jc3.203853880@newssvr14.news.prodigy.com>

"Helgi Briem" <helgi@decode.is> wrote in message
news:3da2a0f5.2508339852@news.cis.dfn.de...
> On Mon, 07 Oct 2002 18:28:36 GMT, "MrFFrreeddoo"
> <mapSoN.S.S@oderF> wrote:
>
> >"Alan J. Flavell" <flavell@mail.cern.ch> wrote in message
> >news:Pine.LNX.4.40.0210071851000.10879-100000@lxplus075.cern.ch...
> >> On Oct 7, -F-r-e-d-o- inscribed on the eternal scroll:
> >>
> >> > But sigh, I am obviously just wasting my time,
> >>
> >> The time you're wasting isn't only your own, while we struggle to
> >> find the common factor to put into the killfile recipe.
> >
> >Thats not my problem. ^
>
> No, you have far more serious problems than that Manfred,
> Manny, Fredo, whatever you want to call yourself.
>
> >LOL how predictable of you folk. Got no balls to ACTUALLY
> >address the issue,
>
> Everybody has long forgotten what the issue was.  We are
> going mad from having an annoying whining toddler throwing
> tantrums in our newgroup.
>
> Go away, NOW!

You cna tell me that all you want, and you can try to sway from the real
issue all you want (on that note many of you would make very productive
politicans), but it will NOT make the real issue die. You want me to go
away and stop buggin you guys? Then stop giving me reasons to. Don't be
rude unneedlessly at newbies, etc. Stop denying the *fact* that there is
a problem. Only then will this group be free of the hate and torment
that has beheld it the last serveral years.




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

Date: Fri, 11 Oct 2002 17:55:13 -0500
From: brian d foy <comdog@panix.com>
Subject: Re: How to get perldb's x programmatically?
Message-Id: <111020021755135916%comdog@panix.com>

In article <ao6tvu$c37$1@reader1.panix.com>, Da Witch <heather710101@yahoo.com> wrote:

> I prefer the formatting used by Perl's debugger's "x" command than
> that produced by Data::Dumper.  Where is the code responsible for
> generating the output of the "x" command?

the debugger is just a perl script that should be in your perl5 lib.
look for perl5db.pl.

-- 
brian d foy <comdog@panix.com> - Perl services for hire
The Perl Review - a new magazine devoted to Perl 
<http://www.theperlreview.com>


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

Date: Fri, 11 Oct 2002 23:10:20 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: ithreads, perl 5.8 and shared objects
Message-Id: <ao7los$anp$1@agate.berkeley.edu>

[A complimentary Cc of this posting was NOT sent to
Benjamin Goldberg 
<goldbb2@earthlink.net>], who wrote in article <3DA5D7DF.D1E244BB@earthlink.net>:
> > [A complimentary Cc of this posting was sent to
> > Benjamin Goldberg <goldbb2@earthlink.net>],
> 
> Please don't.

My setup recognizes Mail-Copies-To=never

> > Hmm?  The STDOUT of the last process is not redirected...  *There is*
> > no last process in the chain.  BourneShell runs several of the a..zzz
> > processes asyncroneously.
> 
> For each group of asynchronous processes, there is a last one in that
> chain.  If you were to have a pipe from that last process to your own,
> and copy the output from that last process to your own stdout, you could
> wait for eof from that process.

This would not work.  If this last process checks the type of its
stdout, it would see that it is a pipe, and may behave differently.

> Thinking on this some more, I do realize that this wouldn't really work
> all that well, since it's more efficient, and prefered, for processes to
> inherit your own std streams (especially if one of them is a tty) and
> talk to them directly.

Additionally, you still assume that there is some kind of a kid
process which arranges for processes a and b in ( a || b ) etc to be
started at appropriate moments.  There is none.  It is
BourneShell.pm's responsibility to detect that a finished with non-0
status, and then start b.  So we need to know the result codes from
*all* the processes (in a "correct" order).

> > I read it as "POE can use an externally supplied event loop".  Right?
> 
> Yes, if those externally supplied event loops will indicate readability
> and writability on filehandles.

I'm confused.  *What* filehandle?  Is POE assuming that *every* event
is associated to a filehandle?

> Considering more real-worldish situations, let's consider the following
> event types:
>    F: filehandle ready for reading/writing (select)
>    P: process has die (wait)
>    L: locking events (flock)
>    S: signals
>    R: RPC (using semaphores and shared memory)
> [wouldn't it be nice if we had an event system which handled *all* of
> these? I may as well wish for the moon, considering how likely that is.]

I do not know what is L; is there a manpage available on Solaris?  I
also have no idea what is a "shared memory" event.

On OS/2 I know how to handle F, P, S and R (but *very* ugly).  On
Unix?  It is easy to handle F and S (thus P)...  [But only for S which
do not require ACKing.  The latter may be also doable, but need
further thinking.]

> POE handles events of type F.
> 
> BourneShell handles events of type P.
> 
> POE can only use BourneShell as a backend, with a bridge, if it *at
> least* handles events of type F.  If BS handled both F and P, then it
> would be doable, otherwise no.

You mean BS needs to handle events of type F, *even* if the
application would not need them?

> Now, SMTT need events of some other type F, and lets you replace it's
> event loop with any other event loop which supports type F ... since POE
> always supports events of type F, you can use POE as a backend.
> 
> If you want to use another module's event loop as a backend, using a POE
> bridge class, that backend *must* support events of type F (it may do
> other things as well, such as P, but F is a minimum).

I still suspect that you try to convey is related to *one* module
replacing (subclassing) the event loop...

> > BS handles wait() events only.
> 
> Then you can't use BS as POE's backend.

OK: BS handles requests for F events by die()ing.  Is it good enough?  ;-)

> > It does not know that somebody may need to examine the GUI event queue
> > of Win32.

> How are Win32 GUI events done?  Type R, maybe?

I doubt it.  On OS/2 it is a special kind of Queue' ("prime" because
it has a separate API, comparing to core-Queue).

> > Likewise SMTT does not know that somebody may want to
> > wait()...
> 
> Fortunatly, SMTT does not need to know about someone wanting to wait()
> if it's using POE for it's backend, since POE provides a kind of
> contract, in that it will make callbacks for whatever F type events you
> tell it to watch for.

Still do not understand what this has to do with SMTT and BS trying to
cooperate on event dispatch (using POE as an arbitrator).

Ilya



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

Date: Fri, 11 Oct 2002 23:13:21 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: ithreads, perl 5.8 and shared objects
Message-Id: <ao7luh$aor$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Uri Guttman 
<uri@stemsystems.com>], who wrote in article <x7vg4anjx8.fsf@mail.sysarch.com>:
> rpc via shared memory can be done with sockets for the semaphores so any
> normal event loop could support that.

Hmm?  Of course one can rewrite any RPC code to use pipes.  What has
this to do with the question at hand?  Suppose you need to cooperate
with a subsystem which uses semaphores *without* rewriting this
subsystem from scratch.

Ilya


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

Date: Fri, 11 Oct 2002 23:25:13 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: ithreads, perl 5.8 and shared objects
Message-Id: <ao7mkp$b2g$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Rocco Caputo 
<troc@netrus.net>], who wrote in article <slrnaqc4tl.8ma.troc@eyrie.homenet>:

[A big chunk filled with (irrelevant?) buzzwords omited.]

> But what of your sad, contrived example that uses two loops?

Take a good breath.  Or two...  Or maybe just a cup of coffee will fix
your problems?  If you cannot fix them yourselves, let us know; maybe
we will be able to help you...

> Well, first you would find a way to run both event loops at once.

You are still missing the point.  Of course *I* (given enough time and
resources) *can* make them cooperate.  But the real question is: how
to design an event looper which is *scalable*; I repeat that
scalability in this context is an API which allows third-parties to
extend the capabilities of the loop with the following properties:

     the parties should not know about each other, only about the
     extension API;

     The parties may be extending the loop in the same direction, or
     in independent directions.

> I can already hear your plaintive cry: But I wanted to use them as
> separate classes and combine them in different ways!
> 
> To which I would reply: Fine, then.  Although your demands are
> arbitrary and capricious, and while they lead to silliness and baroque
> software, POE will not stand in your way.  Create two partial bridges:
> 
>   POE::Loop::IlyasContrivedLoopXBridgePiece
>   POE::Loop::IlyasContrivedLoopYBridgePiece

Should these two bridges know about each other?

Ilya


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

Date: 11 Oct 2002 15:13:36 -0700
From: dan@wolf.com (Daniel Mahoney)
Subject: OLE Automation via Perl
Message-Id: <6c3567b4.0210111413.5da2733f@posting.google.com>

I'm trying to figure out how to automate a warehouse application
running on  one of those overgrown video games (a Windows box).
Specifically, I'm building a report as an RTF file (using RTF::Writer)
in ActiveState Perl. I'd like to be able to open up an instance of
Wordpad once the report is built and shove the data into it. I realize
I can probably do this by writing the report to a file and running
Wordpad via "system", but I'd like to use a classier technique.

I've looked over the perldocs for Win32::OLE, but I'm as lost after
reading the docs as I was before (I know nothing about OLE, beyond a
vague general understanding of the concept).

Can anyone tell me if what I'm trying to do is possible? Or maybe even
point me towards an example of how to do it?


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

Date: Sat, 12 Oct 2002 10:54:06 +1000
From: "Ron Savage" <ron@savage.net.au>
Subject: Re: OLE Automation via Perl
Message-Id: <ao7rrk$t4q$1@arachne.labyrinth.net.au>

"Daniel Mahoney" <dan@wolf.com> wrote in message news:6c3567b4.0210111413.5da2733f@posting.google.com...
> I'm trying to figure out how to automate a warehouse application
> running on  one of those overgrown video games (a Windows box).
> Specifically, I'm building a report as an RTF file (using RTF::Writer)
> in ActiveState Perl. I'd like to be able to open up an instance of
> Wordpad once the report is built and shove the data into it. I realize
> I can probably do this by writing the report to a file and running
> Wordpad via "system", but I'd like to use a classier technique.
>
> I've looked over the perldocs for Win32::OLE, but I'm as lost after
> reading the docs as I was before (I know nothing about OLE, beyond a
> vague general understanding of the concept).

You could use tut # 7 to create an MS Word file:

http://savage.net.au/Perl-tuts-1-30.html

but frankly, I wouldn't. I'd create a text or even better XML file, since such a file could be easily processed by other scripts.

Then the question arises, why not stuff the data into an MySQL db, where also it can be so easily procecessed further, eg with a CGI
interface?
--
Cheers
Ron Savage
ron@savage.net.au
http://savage.net.au/index.html




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

Date: Fri, 11 Oct 2002 23:57:34 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Problems with MSIE in combination with MAC not showing Perl generated HTML
Message-Id: <slrnaqepbe.124.efflandt@typhoon.xnet.com>

On Fri, 11 Oct 2002 21:24:20 +0200, Jan <jan@nospam.harf.nl> wrote:
> This script when run produces a fine output on every browsers on every
> operating system, except MSIE for the MAC, be it OSX or the previous
> version. You can run this script at:
> http://80.60.28.57/top1000/secure/cgi-bin/formtest.pl to see that it
> normally should work.
> 
> We are totally in the dark why it doesn't show any output on the MAC. After
> typing in the address in the location bar, the cursors starts turning for a
> second or two and nothing happens..... We've tried everything up to now.
> Clearing cache, renaming files, shutting down and restarting MSIE, but to no
> avail.
> 
> Anybody anything?

When I first tried to access it with Konqueror in Linux, its gears kept 
spinning and nothing showed.  Then I used wget and it appeared instantly.  
Then I tried Konqueror again and it worked.

Maybe it is actually routing problems, busy server, or denial of service
(DoS) attacks (the usual Windows worms).  Try a traceroute from the box 
that cannot access it and see what that shows, for example:

15  nl-asd-pmg-fsip-cp10.wxs.nl (195.121.255.226)  137 ms  141 ms  137 ms
16  195.190.245.69 (195.190.245.69)  137 ms  137 ms  135 ms
17  * * *
18  ip503c1c39.speed.planet.nl (80.60.28.57)  163 ms  162 ms  159 ms


-- 
David Efflandt - All spam ignored  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Fri, 11 Oct 2002 16:22:04 -0600
From: Arne Jamtgaard <ajamtgaa@cisco.com>
Subject: Re: searching an array.
Message-Id: <3DA74F0C.5C332354@cisco.com>

dave wrote:
> 
> Hello,
>     I'm trying to make a customized backup program, to backup a single fbsd
> box to zip drive. After declaring variables the first thing the program does
> is places the output from mount in to an array. Just for debugging purposes
> i then
> print @MountList;
> which prints out the output i need. Now i need to search that array for a
> specific pattern, and perform different actions based on wether or not the
> pattern is found. Here's my line:
> $ZipDrive = (@MountList =~ /\/dev\/da0c$/);
>     the error i'm getting i have perl using the -w warnings flag is:
> applying pattern match (m//) to @array will act on scalar(@array)
> i have no idea what i'm doing wrong.
> Thanks.
> Dave.

Isn't his what perl's "grep" is for?

Arne
-- 
Arne Jamtgaard      	| "When I became a man, I put away childish 
Boulder DevTest     	| things, including the fear of childishness
1-720-562-6331      	| and the desire to be very grown-up."    
ajamtgaa@cisco.com  	| - C.S. Lewis, 1947


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

Date: Fri, 11 Oct 2002 19:15:41 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: STDIN and choices on screen?
Message-Id: <slrnaqeqdd.408.tadmc@magna.augustmail.com>

Tavish Muldoon <tmuldoon@spliced.com> wrote:

> Is there a perl CASE statement 


   perldoc -q CASE

      "How do I create a switch or case statement?"


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 11 Oct 2002 18:01:26 -0500
From: brian d foy <comdog@panix.com>
Subject: Re: Switching from Python to Perl
Message-Id: <111020021801268316%comdog@panix.com>

In article <ao6u8o$gma$1@coranto.ucs.mun.ca>, Kondwani Spike Mkandawire <kondwani@cs.mun.ca> wrote:

> I'm trying to switch to Perl from Python...
> Still in the process of learning though...
> I was told by someone with great experience in
> both that because Python is still young there
> will be a lot of deprecation as the language is
> continuously updated and as bugs are being fixed.

> However Perl is 15 or so years old and has
> already undergone a lot of fixes and updates
> hence I was told ought to be more stable...

Python and Perl are about the same age, actually.  Both have undergone a lot
of fixes and updates.  

http://www.python.org/cgi-bin/faqw.py?query=history&querytype=simple&casefold=yes&req=search
http://history.perl.org

-- 
brian d foy <comdog@panix.com> - Perl services for hire
The Perl Review - a new magazine devoted to Perl 
<http://www.theperlreview.com>


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

Date: Fri, 11 Oct 2002 16:14:30 -0700
From: Nishi Bhonsle <nishi.bhonsle@oracle.com>
Subject: Unrecognized character \x14 at line1
Message-Id: <3DA75B55.A1573FDD@oracle.com>


--------------6B953E89C149C4F98A23F458
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit


Gurus:
I am executing the a perl script from the comand line on a unix box that
calls internally some other perl script
perl /home /home/nb/test.pl /home/nb /home/nb

and i am getting an error like Unrecognized character \x14 at line1

What does this error mean?
Used perl -d test.pl , but it was going into the perl script correctly.

test.pl
-------
#!/bin/perl

#$clearcaseDrive_latestConfigSpec="/m";
$clearcaseDrive_latestConfigSpec=$ARGV[0];
$oH_dir=$ARGV[1];
$eH_dir=$ARGV[2];
if ($ARGV[0] eq "-help") { help(); }
if (@ARGV != 3)
{
 print "Program exiting,insufficient arguments\n
        For HELP, type
        perl <path to test.pl> -help\n";
 exit 1;
}
$map_file1="$clearcaseDrive_latestConfigSpec\/a.map";
$map_file2="$clearcaseDrive_latestConfigSpec\/b.map";
$map_file3="$clearcaseDrive_latestConfigSpec\/c.map";
$map_file4="$clearcaseDrive_latestConfigSpec\/d.map";

do "$clearcaseDrive_latestConfigSpec\/overlay_Comp.pl";



--------------6B953E89C149C4F98A23F458
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
&nbsp;
<br>Gurus:
<br>I am executing the a perl script from the comand line on a unix box
that calls internally some other perl script
<br>perl /home /home/nb/test.pl /home/nb /home/nb
<p>and i am getting an error like <b>Unrecognized character \x14 at line1</b>
<p>What does this error mean?
<br>Used perl -d test.pl , but it was going into the perl script correctly.
<p>test.pl
<br>-------
<br><tt>#!/bin/perl</tt><tt></tt>
<p><tt>#$clearcaseDrive_latestConfigSpec="/m";</tt>
<br><tt>$clearcaseDrive_latestConfigSpec=$ARGV[0];</tt>
<br><tt>$oH_dir=$ARGV[1];</tt>
<br><tt>$eH_dir=$ARGV[2];</tt>
<br><tt>if ($ARGV[0] eq "-help") { help(); }</tt>
<br><tt>if (@ARGV != 3)</tt>
<br><tt>{</tt>
<br><tt>&nbsp;print "Program exiting,insufficient arguments\n</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For HELP, type</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; perl &lt;path to test.pl>
-help\n";</tt>
<br><tt>&nbsp;exit 1;</tt>
<br><tt>}</tt>
<br><tt>$map_file1="$clearcaseDrive_latestConfigSpec\/a.map";</tt>
<br><tt>$map_file2="$clearcaseDrive_latestConfigSpec\/b.map";</tt>
<br><tt>$map_file3="$clearcaseDrive_latestConfigSpec\/c.map";</tt>
<br><tt>$map_file4="$clearcaseDrive_latestConfigSpec\/d.map";</tt><tt></tt>
<p><tt>do "$clearcaseDrive_latestConfigSpec\/overlay_Comp.pl";</tt>
<br>&nbsp;
<br>&nbsp;</html>

--------------6B953E89C149C4F98A23F458--



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

Date: Sat, 12 Oct 2002 00:02:46 GMT
From: "gbd" <asg779e@earthlink.net>
Subject: Web Design Resources & Tools...  all on one page!
Message-Id: <GEJp9.23180$OB5.2153670@newsread2.prod.itd.earthlink.net>

I took a webdev class once and have spent some time researching good web
development sites (HTML, JavaScript, ASP, Perl, Java, etc.).  This page
shows all that research.  I am not marketing anything - I just want to share
this information.  Many of the webdev sites I researched were not real good
and this collection is the best of what I found on web design tools.  If you
are starting out, this will save you much time.  If you are trying to stay
as nonproprietary /
non-proprietary as possible, this one page will definitely help you!  I hope
this information is of some benefit to all.  Thanks.
http://www.goodboysdo.net/GBDwres.htm
All comments are welcome.
gbd





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

Date: Fri, 11 Oct 2002 22:15:06 +0000 (UTC)
From: Da Witch <heather710101@yahoo.com>
Subject: Re: Why is 'defined @x' deprecated?
Message-Id: <ao7iha$jql$1@reader1.panix.com>

In <x7u1jsk7qa.fsf@mail.sysarch.com> Uri Guttman <uri@stemsystems.com> writes:

>>>>>> "DW" == Da Witch <heather710101@yahoo.com> writes:

>  DW> If I use an expression like "if(defined @x)" Perl issues a
>  DW> warning:

>  DW>   defined(@array) is deprecated at foo.pl line 99.  (Maybe you
>  DW> should just omit the defined()?)

>  DW> The advice the warning gives (omitting defined()) is not useful in
>  DW> this case, since I want to distinguish between cases in which @x
>  DW> has not been assigned to and cases where @x happens to have zero
>  DW> elements.  Omitting defined() would lose this distinction.  Is
>  DW> there another (non-deprecated) way of doing what I want to do
>  DW> without using defined()?

>why do you want to know that difference? defined only reports whether
>the aggregate has ever had some memory allocated for data. it is not
>useful since that is below the hood from the rest of perl. if you
>explain your need for this info and the code around it, i am sure there
>is a better way to do it.

I have a method that needs to compute the values in an array exactly
once.  So I wrote something like:

  {
    my @array;
    sub foo {
      unless(defined @array) {
        # carryout lengthy computation of @array
      }
      @array
    }
  }

It is possible for @array to end up having 0 elements, so getting rid
of "defined()" would not ensure avoiding the redundant computation.
The alternative would be

  {
    my $first_time_flag = 1;
    my @array;
    sub foo {
      if($first_time_flag) {
	$first_time_flag = 0;
        # carryout lengthy computation of @array
      }
      @array
    }
  }

But this seems to me exceedingly inelegant, especially since, in fact,
I have several arrays that need to be computed only once.  I'd have to
have a "first_time_flag" for each: ugly.

hk



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

Date: Fri, 11 Oct 2002 22:28:04 +0000 (UTC)
From: Da Witch <heather710101@yahoo.com>
Subject: Re: Why is 'defined @x' deprecated?
Message-Id: <ao7j9k$k8s$1@reader1.panix.com>

In <x7u1jsk7qa.fsf@mail.sysarch.com> Uri Guttman <uri@stemsystems.com> writes:

>>>>>> "DW" == Da Witch <heather710101@yahoo.com> writes:

>  DW> If I use an expression like "if(defined @x)" Perl issues a
>  DW> warning:

>  DW>   defined(@array) is deprecated at foo.pl line 99.  (Maybe you
>  DW> should just omit the defined()?)

>  DW> The advice the warning gives (omitting defined()) is not useful in
>  DW> this case, since I want to distinguish between cases in which @x
>  DW> has not been assigned to and cases where @x happens to have zero
>  DW> elements.  Omitting defined() would lose this distinction.  Is
>  DW> there another (non-deprecated) way of doing what I want to do
>  DW> without using defined()?

>why do you want to know that difference? defined only reports whether
>the aggregate has ever had some memory allocated for data.

I tried this:

% perl -we '@x = (1); printf "<%s>\n", defined @x; @x = undef; printf "<%s>\n", defined @x; undef @x; printf "<%s>\n", defined @x'
<1>
<1>
<>

So undef @x will cause defined(@x) to return false even if @x has had
memory allocated for data before.



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

Date: Fri, 11 Oct 2002 22:52:45 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Why is 'defined @x' deprecated?
Message-Id: <x7it08k2pu.fsf@mail.sysarch.com>

>>>>> "DW" == Da Witch <heather710101@yahoo.com> writes:

  DW> I tried this:

  DW> % perl -we '@x = (1); printf "<%s>\n", defined @x; @x = undef;
  DW> printf "<%s>\n", defined @x; undef @x; printf "<%s>\n", defined
  DW> @x' <1> <1> <>

  DW> So undef @x will cause defined(@x) to return false even if @x has
  DW> had memory allocated for data before.

yes, because the undef causes the whole variable to be freed including
its memory.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Fri, 11 Oct 2002 23:05:53 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Why is 'defined @x' deprecated?
Message-Id: <x7bs60k23y.fsf@mail.sysarch.com>

>>>>> "DW" == Da Witch <heather710101@yahoo.com> writes:

  DW> I have a method that needs to compute the values in an array
  DW> exactly once.  So I wrote something like:

  DW>   { my @array; sub foo { unless(defined @array) { # carryout
  DW> lengthy computation of @array
  DW>       }
  DW>       @array
  DW>     }
  DW>   }

i know that is dummy code but where do you keep that array for real?

  DW> But this seems to me exceedingly inelegant, especially since, in
  DW> fact, I have several arrays that need to be computed only once.
  DW> I'd have to have a "first_time_flag" for each: ugly.

then use a hash of arrays. you can test for no array having been
computed easily with exists.

or for single arrays, use a scalar variable and stuff an array ref into
it. then you can test the scalar with any boolean op to see if you have
an array.

see, i said there are simple and better ways to do this.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Fri, 11 Oct 2002 23:37:20 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Why is 'defined @x' deprecated?
Message-Id: <3da75b55.347154521@news.erols.com>

Da Witch <heather710101@yahoo.com> wrote:

| I have a method that needs to compute the values in an array exactly
| once.  So I wrote something like:
| 
|   {
|     my @array;
|     sub foo {
|       unless(defined @array) {
|         # carryout lengthy computation of @array
|       }
|       @array
|     }
|   }
| 
| It is possible for @array to end up having 0 elements, so getting rid
| of "defined()" would not ensure avoiding the redundant computation.
| The alternative would be
| 
|   {
|     my $first_time_flag = 1;
|     my @array;
|     sub foo {
|       if($first_time_flag) {
| 	$first_time_flag = 0;
|         # carryout lengthy computation of @array
|       }
|       @array
|     }
|   }
| 
| But this seems to me exceedingly inelegant, especially since, in fact,
| I have several arrays that need to be computed only once.  I'd have to
| have a "first_time_flag" for each: ugly.

Not ugly.
The concept you've almost found in that idea is called memoization.
It's a Good Thing.

Assuming some parameter gets passed to foo() that uniquely identifies
which set of results the caller wants, foo() can return the previously
computed results associated with that identifier, or it can perform a
new set of computations and store the results for future retrieval.

    {
        my %memo;
        sub foo {
            my( $identifier ) = @_;
            unless( exists $memo{ $identifier } ) {
                my @array;
                # carry out lengthy computation of @array
                $memo{ $identifier } = \@array;
            }
            return @{ $memo{$identifier} };
        }
    }



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

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 3957
***************************************


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