[17124] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4536 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 6 00:10:27 2000

Date: Thu, 5 Oct 2000 21:10:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <970805412-v9-i4536@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 5 Oct 2000     Volume: 9 Number: 4536

Today's topics:
    Re: Reverse by paragraphs - NOT! ollie_spencer@my-deja.com
    Re: Reverse by paragraphs - NOT! ollie_spencer@my-deja.com
    Re: Reverse by paragraphs - NOT! ollie_spencer@my-deja.com
    Re: Reverse by paragraphs - NOT! ollie_spencer@my-deja.com
    Re: Reverse by paragraphs - NOT! ollie_spencer@my-deja.com
    Re: Reverse by paragraphs - NOT! ollie_spencer@my-deja.com
    Re: Reverse by paragraphs - NOT! ollie_spencer@my-deja.com
    Re: Reverse by paragraphs - NOT! ollie_spencer@my-deja.com
    Re: Reverse by paragraphs - NOT! ollie_spencer@my-deja.com
    Re: Reverse by paragraphs - NOT! <elephant@squirrelgroup.com>
    Re: Seeking script for appending text file with web-for <elephant@squirrelgroup.com>
    Re: splitting an array into a hash of sub-arrays <ren.maddox@tivoli.com>
    Re: Using my with file handles <rick.delaney@home.com>
    Re: validating and decoding a code <email@address.com>
    Re: Variable names enclosed within curly braces <ren.maddox@tivoli.com>
    Re: Win32 Widgets? <matt.stoker@motorola.com>
    Re: Win32::ChangeNotify <elephant@squirrelgroup.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 06 Oct 2000 01:52:52 GMT
From: ollie_spencer@my-deja.com
Subject: Re: Reverse by paragraphs - NOT!
Message-Id: <8rjb9j$7mi$1@nnrp1.deja.com>

I reply to you first, since it was you ( and I admit, your admirable
patience) that opened my eyes.

I seem not only to have been guilty of just lightly scanning, not really
focussing on, well-meaning replies, but also in rejecting totally
acceptable solutions. My stomach became quite upset in reading how
stupid my replies were since I wasn't prepared to accept their quite
correct solutions.

Early on I fixated that the solution *must* involve reverse, so
I rejected completely workable solutions involving split and a long
string. I later "discovered" that independently(or so I believed - I
wonder now if my discovery wasn't a subconscious feed-back of info I saw
here and didn't understand). I never returned to the early posts to see
how correct they were - *even the first reply had such a solution!*

I already outlined my problems with the web-based newsreader. I wonder
if it can be made to highlight un-read messages.

I am mortified. You and others have been right, and I have been worse
that Godzilla itself in my arrogance.

BTW- in my last post to you, I meant to say "I will try diligently to
*not* annoy you again". The "*not*" disappeared somehow.

I felt I must reiterate how right you were and rethank you for opening
my eyes. I likely will return to lurking, posting only in super
emergencies but always with this bitter experience on my mind. Maybe I
really am getting too old for this business.

Now I've got to get some messages off to some people I feel I have
horribly wronged.

ollie spencer

In article <8ri75d$dcv$1@lublin.zrz.tu-berlin.de>,
  anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> <ollie_spencer@my-deja.com> wrote in comp.lang.perl.misc
>
> [de-jeopardized]
>
>>>A whole lot of stuffsnipped here>> Correct stuff


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 06 Oct 2000 02:00:12 GMT
From: ollie_spencer@my-deja.com
Subject: Re: Reverse by paragraphs - NOT!
Message-Id: <8rjbna$83o$1@nnrp1.deja.com>

That message wasn't meant for you. It was meant ( inappropriately ) for
someone else that also didn't deserve it.

Following Anno Siegel I re-read every post to this thread ( except those
in the Godzilla sub-thread). I am mortified at my ignorance. See my
latest(and hopefully last) post to Anno Siegel for details.

The mis-directed message is only one of the many gaffes I have committed
 as you will see in that post. Really, I'm not a bad guy, but I sure
came on as one.

ollie spencer

In article <Pine.GHP.4.21.0010060159030.6562-100000@hpplus03.cern.ch>,
  "Alan J. Flavell" <flavell@mail.cern.ch> wrote:
> On Thu, 5 Oct 2000 ollie_spencer@my-deja.com wrote:
>
> > Even if you were Larry Wall himself, though I don't know that you
are
> > justified in acting as usenet policeman. Others seemed not so
offended.
>
> I can assure you, I wasn't offended.  I merely added you to the
> ever-growing list of people who were incapable of using appropriate
> advice.
>
> [entire history of usenet deleted]
>
> I never really understood thermodynamics in undergraduate lectures all
> those years ago, but this is helping me to fill the gaps about what
> entropy meant.
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 06 Oct 2000 02:07:28 GMT
From: ollie_spencer@my-deja.com
Subject: Re: Reverse by paragraphs - NOT!
Message-Id: <8rjc4t$88o$1@nnrp1.deja.com>

Following Anno Siegel's advise, I re-read every post exept the Godzilla
subthread again. See my last post to him for my great embarrassment.

You are absolutely right. I seem to have been unable to recognize the
correct solution till I "discovered" it myself - only on rereading the
posts I see that even the first reply (by amontod) contained this way of
doing it.

I appreciate your patience. You could have justifiably incinerated
me.

I've got some bridges to mend. I'm not really as arrogant as I sound in
those posts.

ollie spencer

In article
<Pine.A41.4.21.0010051130580.12502-100000@ginger.libs.uga.edu>,
  Brad Baxter <bmb@ginger.libs.uga.edu> wrote:
> On Thu, 5 Oct 2000 ollie_spencer@my-deja.com wrote:
> > Whoops, I'm getting technical. Perhaps you aren't ready for that. I
> > don't exactly have your credentials.
>
> Good grief, Ollie.  You've gotten at least half a dozen bits of code
that
> will solve your problem.  I base that statement on the fact that you
have
> successfully written an intermediate file that can be processed by
reading
> it in paragraph mode.  If you can do the one, you can to the other
using
> code you've been generously supplied.
>
> Brad
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 06 Oct 2000 02:23:48 GMT
From: ollie_spencer@my-deja.com
Subject: Re: Reverse by paragraphs - NOT!
Message-Id: <8rjd3f$935$1@nnrp1.deja.com>

I must apologize.

On suggestion from Anno Siegel, I re-read every post from the beginning.
I seem to have been guilty in this thread of every malconduct that can
be conveyed in print, except profanity. See my last post to Anno Siegel
for details.

Even the first responder had the solution to my problem, but apparently
my mind was unable to comprehend it. I wronged many well meaning
responders ( really, it was unintentional ) by my fixation that a
solution *must* contain "reverse", not split, and I got quite arrogant
in my stupidity.

You have been quite right in your assessment of me. I hope now I can get
back to the business of testing of the many approaches that have been
offered.

ollie spencer

In article <x7r95w3qtl.fsf@home.sysarch.com>,
  Uri Guttman <uri@sysarch.com> wrote:
> >>>>> "os" == ollie spencer <ollie_spencer@my-deja.com> writes:
>
>   os> Thanks for your reply.
>   os> Nope, the headers ( there are 500 of them, each about 9 lines
long, in
>   os> the file. I get rid of them successfully before I ever try to
reverse
>   os> the file> They are gone, nada, zip --they are "dead parrots".
>
> as others have stated, your usenet skills are VERY poor. stop jeopardy
> posting and stop beating around the bush with your moving spec.
>
>   os> Loudly: WHAT I WANTED TO KNOW: Why can't I do something directly
to the
>   os> original array so I get @ROF directly?
>
>   os> NOBODY HAS ANSWERED THAT ONE.
>
> how about showing some sample data and sample result data? you keep
> saying no one has answered your problem but i say you have never
clearly
> specified it. i think i am right here. i showed you another way to
read
> the file backwards (much faster than the cookbook method you quote)
and
> you don't try it.
>
>   os> But I think now *I* can.
>   os> When written to disk, a file is a long string with lines
delineated by
>   os> whatever "$\" is, or by "\n". A file in an array is ALREADY
delineated!
>   os> (I think)I should write the file to a long string variable, not
an array
>   os>  then reverse that on whatever delineator I choose.
>
> all files are just a long string. BFD. you keep saying paragraph
without
> defining it. you claim you use the wrong terms but that is not ok. you
> claim to be a physicist, so how would you like if i used pounds
instead
> of newtons? you might just crash a rocket on mars (oh, that has been
> done!)
>
> so when you post here, you follow this groups conventions: you quote
> with editing and THEN you write your reply. you show code and data and
> expected results. you don't keep rambling on about how no one has
solved
> your problem and then keep moving the problem.
>
> your basic problem is trivial. you are making it much harder than it
> is. this is all your doing, not this group so stop blaming us. post a
> COMPLETE AND PROPER SPECIFICATION OF YOUR PROBLEM and maybe we can
help
> you.
>
> until then, you have definitely exhausted your potential well of help
> here.
>
> (see i do know wher the shift key is. he yelled, so i yelled back)
>
> uri
>
> --
> Uri Guttman  ---------  uri@sysarch.com  ----------
http://www.sysarch.com
> SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX
Consulting
> The Perl Books Page  -----------
http://www.sysarch.com/cgi-bin/perl_books
> The Best Search Engine on the Net  ----------
http://www.northernlight.com
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 06 Oct 2000 02:27:58 GMT
From: ollie_spencer@my-deja.com
Subject: Re: Reverse by paragraphs - NOT!
Message-Id: <8rjdb9$96i$1@nnrp1.deja.com>

I seem to have rejected out-of-hand your completely acceptable solution.

I fixated on an different approach and inappropriately rejected yours,
preferring to quibble about headers. Please excuse my boorishness.

ollie spencer

In article <0uvmtsg0aiqattrfopd80i4d7rhe5g2a4g@4ax.com>,
  Bart Lateur <bart.lateur@skynet.be> wrote:
> ollie_spencer@my-deja.com wrote:
>
> >I wish I'd not mentioned the header, because it's NOT a my problem.
I
> >successfully excise the header and place the headerless data into
@OF,
> >even the blank lines.
>
> But it is your problem! Without header and footer, you can easily read
> the file by paragraph. Now you can't. You can read it line by line,
and
> filter out the header and footer. But you have an array of lines. You
> want an array of paragraphs.
>
> >I can write @OF to a file, then close and reopen it for reading.
> >That way WORKS. But it seems a bit clumsy!
>
> I feel the same whay too. So, let's try to turn the array of lines
into
> an array of paragraphs. I assume the line ends are still there, and I
> can simply concatenate the lines.
>
> 	my @paragraph = "";  # one element
> 	foreach(@line) {
> 	    if(/^$/) {
> 	        # blank line = new paragraph
> 	        push @paragraph, "";
> 	    } else {
> 	        # append line to current paragraph
> 	        $paragraph[-1] .= $_;
> 	    }
> 	}
> 	$, = "\n";  #blank line between paragraphs
> 	print reverse @paragraph;
>
> --
> 	Bart.
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 06 Oct 2000 02:34:46 GMT
From: ollie_spencer@my-deja.com
Subject: Re: Reverse by paragraphs - NOT!
Message-Id: <8rjdo5$9ho$1@nnrp1.deja.com>

Thanks for the kind input. I have been really slow to recognize the
merits of certain valid solutions offered for my problem. I hope you
were not one of those I offended by my belated understanding.

Problem fixation? I hope. Age? Maybe, but I hope not.

ollie spencer

In article <8rhl5n$bro$1@news.mch.sbs.de>,
  michel.dalle@usa.net (Michel Dalle) wrote:
> In article <8rggnl$tjv$1@nnrp1.deja.com>, ollie_spencer@my-deja.com
wrote:
> >Thanks for the reply.
> >
> >I've had a few thoughts on the situation since my original post.
> >Writing the array out to file and reading it in in reversed manner is
> >OK, I just wondered why it couldn't be done directly on array that is
> >written out.
> >
> >I now think that's becaue the file is written-out as one long string
> >on disk, which on read-in can be dilineated on something other than
used
> >to delineate it on writing. A file in an array has ALREADY been
> >delineated!
> >
> >Hmm.. Perhaps writing it to one long string variable and splitting it
on
> >the desired dilineating pattern will work... Back to the salt  mines!
>
> Well, you seem to have grasped the underlying problem, indeed :)
>
> You can't go from an array that looks like this :
> @array_byline = (
>         'this is the first line',
>         'of the first paragraph',
>         '',
>         'this is the first line',
>         'of the second paragraph',
> );
>
> to an array that looks like this :
>
> @array_byparagraph = (
>         "this is the first line\nof the second paragraph",
>         "this is the first line\nof the first paragraph",
> );
>
> without pulling out all elements of @array_byline
> and recombining them in another way into
> @array_byparagraph. Reversing won't work.
>
> Now you seem to have chosen to write @array_byline
> to a file, and then read back that file by paragraph
> to put it in @array_byparagraph. It's obviously not an
> ideal solution.
>
> One way to do this would be to put the file back together
> in a string, and then split it again by paragraph.
> A better approach would be to make sure you fill your
> original array directly with paragraphs instead of lines.
>
> Sample code for both approaches has already been
> given by other people in this thread, so your problem
> is solved :)
>
> HTH,
>
> Michel.
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 06 Oct 2000 02:40:41 GMT
From: ollie_spencer@my-deja.com
Subject: Re: Reverse by paragraphs - NOT!
Message-Id: <8rje38$9ua$1@nnrp1.deja.com>

Yeah, and on re-reading all posts ( at A. Siegel's suggestion) since the
beginning of this unnecessarily long thread, that's just the tip of my
ignorance iceberg.

See my last post to Anno Siegel for details.

I see now that there were many viable solutions offered and may fixation
on the need to use "reverse' caused me to reject them callously.

If yours was among them, I apologize. I am new to this web newsreader,
and that has made me look even worse.

ollie spencer

In article <Pine.GHP.4.21.0010050220240.2000-100000@hpplus03.cern.ch>,
  "Alan J. Flavell" <flavell@mail.cern.ch> wrote:
> On Wed, 4 Oct 2000 ollie_spencer@my-deja.com blurted out to some
> unspecified entity:
>
> > Thank you for your reply, even though you can't know what my
knowledge
> > level is.
>
> Well, you leave us in no doubt about the level of your usenet
> competence.
>
> If you hadn't already got your score set in the basement this would be
> the moment.
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 06 Oct 2000 02:46:56 GMT
From: ollie_spencer@my-deja.com
Subject: Re: Reverse by paragraphs - NOT!
Message-Id: <8rjeev$a2k$1@nnrp1.deja.com>

In jargon of my generation: *RIGHT ON!*.

Well, maybe it was a later(much later) generation. I think I come from
the "Kilroy was here" group.

Thanks for the input. I am only now beginning to fully understand the
problem, and that helps me cope with the answers.
Sometime the solution comes immediately if the problem is correctly
stated - or does that just paraphrase what you just said?

ollie spencer

In article <m3n1gkf8u5.fsf@dhcp11-177.support.tivoli.com>,
  Ren Maddox <ren.maddox@tivoli.com> wrote:
> ollie_spencer@my-deja.com writes:
>
> > I think now I need to express the file I need to "reverse by
paragraph"
> > as one long "super"string, not as an array at all, and reverse that
> > string on a chosen delimiter, rather than try to do it with an array
> > whose components are strings(if I can do it in a perl-ish manner).
In
> > other posts I noted that I have code(2 approaches, actually) that
does
> > what I desire, buth both are clumsy and, if you would, non-perlish.
>
> #!/usr/local/bin/perl -w
> use strict;
>
> my $string = "This is a string*BOO*that has groups of
> text and *BOO*uses a rather *BOO*interesting delimiter*BOO*(at
> least I think*BOO*so)";
>
> my $delimiter = "*BOO*";
> my $new_string = join $delimiter, reverse split /\Q$delimiter/,
$string;
> print $new_string, "\n";
> __END__
>
> It's amazing how easy problems can get once there is a clear
> specification of the problem.
>
> --
> Ren Maddox
> ren@tivoli.com
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 06 Oct 2000 02:53:32 GMT
From: ollie_spencer@my-deja.com
Subject: Re: Reverse by paragraphs - NOT!
Message-Id: <8rjera$ads$1@nnrp1.deja.com>

Hi - I was right! I didn't understand your solution. Now that I(think I)
do, I believe you're solution is the one I need.

I fixated on the need for reverse on an array, a stupid way to do it. I
will certainly test your code.

Thanks for the input.

ollie spencer

In article <8raga8$tl4$1@nnrp1.deja.com>,
  amonotod <amonotod@netscape.net> wrote:
> In article <8rabr2$pa4$1@nnrp1.deja.com>,
>   ollie_spencer@my-deja.com wrote:
> <snip>
> > in array @OF. For convenience, I would then like to reverse the file
> > so the initial paragraph is at the top, the most recent at the
bottom.
> > I seem unable to get the reversing procedure (from the Perl
Cookbook)
> > to work - the whole file is reversed line by line, not paragraph by
> > paragraph. I include the code below. Where am I going wrong?
> <snip>
> > #------------------------------------------------------------------
> > # Go through <INFILE> a line at a time...
> > #------------------------------------------------------------------
> > while(<INFILE>){
> <snip>
>
> I think that says it all....
>
> You might try something like:
> <PSUEDOCODE>
> $article = (<FILE>);
> @paras = split(/\n\n/, $article);
> foreach (@paras) {
>   while($_) {
> </PSUEDOCODE>
>
> HTH,
> amonotod
>
> --
>     `\|||/                     amonotod@
>       (@@)                     netscape.net
>   ooO_(_)_Ooo________________________________
>   _____|_____|_____|_____|_____|_____|_____|_____|
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 6 Oct 2000 14:10:01 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: Reverse by paragraphs - NOT!
Message-Id: <MPG.1447fba6ffde30d5989805@localhost>

ollie_spencer@my-deja.com wrote ..
>In article <8ri75d$dcv$1@lublin.zrz.tu-berlin.de>,
>  anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
>> <ollie_spencer@my-deja.com> wrote in comp.lang.perl.misc
>>
>> [de-jeopardized]
>>
>>>>A whole lot of stuffsnipped here>> Correct stuff
-
>I reply to you first, since it was you ( and I admit, your admirable
>patience) that opened my eyes.

  [ further prostration deleted ]

now - if only you can have your eyes opened to the point where you cease 
these jeopardy posts .. please post your reply beneath what you're 
replying to .. it is far more conducive to group discussion

  [ jeopardectomy ]

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: Fri, 6 Oct 2000 12:59:55 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: Seeking script for appending text file with web-form submissions
Message-Id: <MPG.1447eb337f36f11f989802@localhost>

m744@my-deja.com wrote ..
>I have a page on my site where users enter their name and
>email address in a form. I'd like to append this information
>to a comma-delimited text file, suitable for import to a
>database or spreadsheet. Could anyone refer me to any
>existing scripts?

there is a pretty complete example in

  perldoc Text::CSV_XS

don't know what your criteria is for 'existing script' .. but that 
example is pretty complete

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: 05 Oct 2000 19:29:39 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: splitting an array into a hash of sub-arrays
Message-Id: <m3r95ubymk.fsf@dhcp11-177.support.tivoli.com>

post_to_group <already_seen@my-deja.com> writes:

> > push @hostgroups, [ splice(@hosts, 0, $hosts_per_group) ] while @hosts;
> 
> What can I say, except THANKS!  It does exactly what my code does but
> much, much more efficiently.  It took me a while of playing around with
> your code to even understand what is going on with that one nifty line
> but now I can adapt it into my foreach loop and use it instead!

You're certainly welcome, and I'm glad that it meets your needs.

> While I now see how it works, I am still not sure of the
> correct terminology.  Are you storing scalar references to each spliced
> array set in @hostgroups?  When I try to print a segment of @hostgroups,
> I get the ARRAY address, but when prepend it with @, as you have in @$_,
> then it works.  Just curious as to the proper terminology/description of
> what is going on so I can go look this up as I am not clearly
> understanding the fundamentals.

It sounds like you have the terminology almost right.  What are
stored in @hostgroups are references to arrays.  The references
themselves are scalar, but referring to them as "scalar references"
might imply that they are references to scalars, which isn't correct.
All references are, themselves, scalars, so there is no need to refer
to them as "scalar references".  Simply say "references", or be more
specific and say "array references" or "references to arrays".  Or,
better yet, shorten "references" to "refs" and simply say "array
refs".

Watch out for that "@$_" syntax, as depending on how you're getting at
the reference you may need some braces.  For example, if you want to
reference the first array ref stored in @hostgroups directly, you
would use "@{$hostgroups[0]}".

Take a look at:

perldoc perllol

for an more in-depth treatment of this data structure.

> However for the nuts and bolts, you have definitely posted a helpful
> answer.  Also thanks to the other gent who suggested Data::Dumper.  What
> I prefer about the above is it uses direct code instead of some black
> box module and as a beginner I prefer to "code the stuff by hand."
> 
> thanks to both of you,

Your most welcome.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Fri, 06 Oct 2000 01:48:34 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Using my with file handles
Message-Id: <39DD323C.6BF298ED@home.com>

[posted & mailed]

Don Vaillancourt wrote:
> 
> sub goFirstRecord
> {
>  my $self=shift @_;
> 
>  *HANDLE = $self->{handle};

You can do this if you localize *HANDLE (as it says in the FAQ) but
there is no need to assign to a glob.  If $self->{handle} already
contains a glob or globref then you could just do:

    my $fh = $self->{handle};

and then

    if (seek $fh, 0, 0) {

etc.
 
Still, if you don't know to localize *HANDLE here, I wonder whether you
thought to do so wherever you assigned $self->{handle}.  Another way
(not mentioned in the FAQ) that you can *create* the filehandles is with
autovivification.  This requires v5.6.

    my $self = {};
    open $self->{handle}, $filename or die $!;

This has the benefit of not localizing the whole typeglob just to
localize the file handle.

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Fri, 06 Oct 2000 03:29:57 GMT
From: "Rob" <email@address.com>
Subject: Re: validating and decoding a code
Message-Id: <VGbD5.6681$aD2.18361@news-server.bigpond.net.au>

I can see how this could be done with a mixture of javascript and backend
CGI ... but it would be EXCEPTIONALLY slow, particularly if you insist on
'WITHOUT ANY KEY DEPRESSION necessitated' ... if you were to bend that to
allow for the page to be created after the person tabs off the item entry
field, then it might be feasible ... by using the onBlur event from
javascript and the calling of the backend CGI which returns values back to
the parent object again through Javascript (I have done this before).

Rob

--
The email address should read - rob at cowsnet dot com


<u0107@cheerful.com> wrote in message news:8ril39$kmj$1@nnrp1.deja.com...
> Hello,
>
> I am trying to do the following:
>
> I have a form on my webpage consisting of more than one field.  One of
> the fields, a text box,  is an item code in a flat file of some 35,000
> records.
>
> As soon as an item code is entered, I would like to call a perl script,
> (I would like to avoid using javascript as that would make my source
> accessible and reveal details I would not like to reveal about my
> website) and get the decode (item description) of that item code and
> display it in a readonly type of input.
>
> I am fairly comfortable with javascript and I can code well enough to
> detect a change in the content of the text box field to pass it to a
> javascript function.
>
> What I would like to do is:
>
> Use this passed (item code) value in the javascript function to pass it
> to a perl program which would accept this passed value and return to me
> the decode of the item (item description) which I could display on the
> page dynamically WITHOUT ANY KEY DEPRESSION necessitated.
>
> My question is:
>
> Am I going about it the right way or is there a better way? (e.g. using
> onKeyDown and onKeyUp events in forms to directly call the perl script
> instead of passing it to a javascript function...?)
>
> If there IS a better way, then can someone point me to it?
>
> Thanks in advance.
>
> I would prefer personal / direct emails to my email address.  I will
> share in this forum, all solutions which I receive and find working
> with any changes I need to effect.
>
> Cheers!
>
> Uttam
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.




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

Date: 05 Oct 2000 18:15:42 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Variable names enclosed within curly braces
Message-Id: <m34s2qdgm9.fsf@dhcp11-177.support.tivoli.com>

evanharrington@my-deja.com writes:

[details about use of ${var} versus $var omitted]
> This worked fine for most programs.  However, I recently edited a perl
> program where there was a line like this:
> 
> 	$cmd = "ctmcontb -add $ctmFileName_FILE-OK $odat";

Problems like this are what "-w" and "use strict" are meant to catch.
Either one would have caught this problem -- assuming
$ctmFileName_FILE isn't used anywhere else in the script.

> This was constructing a command string to set a condition for our
> scheduler.  Even though there was a non-null value for $ctmFileName in
> the program, $cmd became 'ctmcontb -add -OK 1004'.  That is because
> perl substituted the value of ${ctmFileName_FILE} (a null value, as it
> was a scalar never created within the program) in the double-quoted
> assignment.  Clearly, it would have been better to have stuck with my
> old technique and code the line:
> 
> 	$cmd = "ctmcontb -add ${ctmFileName}_FILE-OK $odat";

Not sure what to say about this... "_" is a valid characters in an
identifier, so I'm not sure why you would expect the variable to end
there.  That's no different than expecting "$apple24" to refer to
variable $apple, rather than $apple24.  To get the former, you would
use "${apple}24".  That's exactly the problem that those braces are
meant to solve.

> or, to be more consistent:
> 
> 	${cmd} = "ctmcontb -add ${ctmFileName}_FILE-OK ${odat}";
>         # Now in use

The problem with this is that anyone not aware of your standard of
always using the braces is likely to either be confused or simply
annoyed by their unnecessary use.  Reminds me of quoting simple
scalars:

$x = "$y";

though this is worse as it causes an unnecessary copy.

> Now, I wonder what is the best way for programmers to avoid this
> problem?  We could decide to avoid substitution altogether:

The best way to avoid the problem is simply to understand what
constitutes an identifier, and realize when the braces are necessary.
Using "warnings" and "strict" would certainly help, as they would let
you know when you are accidentally using the wrong identifier.

> 	$cmd = 'ctmcontb -add ' . $ctmFileName . '_FILE-OK ' . $odat;
> 
> However, the moment someone decides it would be 'prettier' to pull all
> this back into a double-quoted string, we would have the error again.
> For now, I have decided to leave the line as the version above -- the
> one with the comment 'Now in use'.  But, this conflicts with the style
> used elsewhere in this program and almost everywhere else.  I also had
> to put a comment near that line to warn programmers against removing
> the curly braces.
> 
> Surely this is a problem for other people?  How do they cope with it, I
> wonder?  Apparently, many feel that my preference for enclosing
> variable names within curly braces is excessive.  But is it?  Is it not
> the only way to make clear what is happening?  If I edit someone else's
> code, should I have to search through it to look for every potential
> problem that might result from the variable's use?  It is so easy to
> forget or overlook the issues.

Other people deal with this problem by first understanding what makes
an identifier, and second, letting Perl help to watch for this thing
by enabling warnings and using the "strict" pragma.

> On the other hand, if I always enclose the name in curly braces -- and
> if everyone else does, too -- the dilemma is solved.  I can be sure
> that there will be no problem with variable substitution.

Except that it is ugly, it indicates a poor understanding of
identifiers, and (as you note below) there are problems with *always*
using the braces.  What's more, the braces make it oh-so-easy to fall
into the symbolic reference trap (unless "strict refs" are enables, of
course).

> HOWEVER, I have found that variable names enclosed in curlies are not
> always safe.  For instance, one cannot open a filehandle for reading
> and process the lines as follows:
> 
>         use FileHandle;
>         my ${fh} = new FileHandle( "somefile.txt" );
> 
> 	while ( <${fh}> )   # WRONG!
> 	{
> 		...
> 	}

This is because the angle brackets serve double-duty as an interface
to both readline and glob.  Using the curlies crosses the line into
glob behavior.

> The incorrect line above is repaired byh expressing it thus:
> 
>         while ( <$fh> )     # GOOD!

Here is an excerpt from "perldoc perlop" that almost explains this:

       The <> symbol will return `undef' for end-of-file only
       once.  If you call it again after this, it will assume you
       are processing another @ARGV list, and if you haven't set
       @ARGV, will read input from STDIN.

       If angle brackets contain is a simple scalar variable
       (e.g., <$foo>), then that variable contains the name of
       the filehandle to input from, or its typeglob, or a
       reference to the same.  For example:

           $fh = \*STDIN;
           $line = <$fh>;

       If what's within the angle brackets is neither a
       filehandle nor a simple scalar variable containing a
       filehandle name, typeglob, or typeglob reference, it is
       interpreted as a filename pattern to be globbed, and
       either a list of filenames or the next filename in the
       list is returned, depending on context.  This distinction
       is determined on syntactic grounds alone.  That means
       `<$x>' is always a readline() from an indirect handle, but
       `<$hash{key}>' is always a glob().  That's because $x is a
       simple scalar variable, but `$hash{key}' is not--it's a
       hash element.

       One level of double-quote interpretation is done first,
       but you can't say `<$foo>' because that's an indirect
       filehandle as explained in the previous paragraph.  (In
       older versions of Perl, programmers would insert curly
       brackets to force interpretation as a filename glob:
       `<${foo}>'.  These days, it's considered cleaner to call
       the internal function directly as `glob($foo)', which is
       probably the right way to have done it in the first
       place.)

OK, it does better than "almost".  It even gives an explicit example
of the fact that the curly braces force glob-behavior.

> Also, there are probably other cases where this syntax clashes.

Nothing jumps to mind, though the possibility of accidentally getting
a symbolic reference to a package variable rather than the intended
lexical almost fits the bill, but you would have to have something a
bit strange like:

$x = 3;
my $x = 4;
print "${+x}\n";  # With the +, this prints 3 instead of 4
__END__

-- 
Ren Maddox
ren@tivoli.com


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

Date: Thu, 05 Oct 2000 18:12:27 -0700
From: Matthew Stoker <matt.stoker@motorola.com>
Subject: Re: Win32 Widgets?
Message-Id: <39DD26FB.B02708D@motorola.com>

H C wrote:
> 
> > One option can be to use Tk - but I can't find the Tk/Perl components for
> > Win32. I've searched the
> > FAQ's (and the Web) and found nothing.
> 
> ppm install Tk

Just in case you're confused by the previous post (or if you have a
firewall, which prevents ppm from working) see:

http://www.activestate.com/Support/ActivePerl/PPM.html

Good Luck!

-- 
/------------------------------------------------------------------\
| Matt Stoker                |     email: matt.stoker@motorola.com |
| Unit Process Modeling      | Mail Drop: M360                     |
| DigitalDNA(TM) Laboratories|     Phone: (480)655-3301            |
| Motorola, SPS              |       Fax: (480)655-5013            |
| 2200 W Broadway Road       |     Pager: (888)699-8803            |
| Mesa, AZ 85202             |                                     |
\------------------------------------------------------------------/


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

Date: Fri, 6 Oct 2000 13:28:38 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: Win32::ChangeNotify
Message-Id: <MPG.1447f1ed4bcd427a989804@localhost>

H C wrote ..
>NT 4.0 SP6a, ActiveState Perl build 618
>
>Problem:  Code exits after first change....such as a file deleted or
>added, or a
>               file size change..
>
>Code:
>my $watch = new Win32::ChangeNotify($self->{monitor_dir}, 0,
>      FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_SIZE );
>
> if ($watch) {
>  $change = $watch->wait(INFINITE);
>  if ($change) {
>   print "Change Occurred!\n";
>   $watch->reset();
>  }
>
> }
> else {
>  $self->{error} = "Could not create ChangeNotify object for
>$self->{monitor_dir}";
> }
>
>Any thoughts?

umm .. yeah .. two thoughts

1) learn to indent properly - your code is very difficult to read

2) put a loop in there somewhere so the code runs through more than once

there's nothing magical about ChangeNotify that makes your code 
automagically loop - you have to put the above in a loop .. eg.


my $watch = new Win32::ChangeNotify( $self->{monitor_dir}
                                   , 0
                                   ,   FILE_NOTIFY_CHANGE_FILE_NAME
                                     | FILE_NOTIFY_CHANGE_SIZE
                                   );

if ($watch) {
  while(1) {
    $change = $watch->wait(INFINITE);

    if ($change) {
      print "Change Occurred!\n";
      $watch->reset();
    }

  }
}
else {
  $self->{error} = "Could not create ChangeNotify object for "
                 . "$self->{monitor_dir}";
}

there are a few other enhancements that I'd make too .. like you might 
want to change that while condition to something that you can signal .. 
and the check of whether the 'new' worked is a little ambiguous - I'd do 
it as an 'and' on the call itself .. also the wait() call could be 
placed as the if condition rather than assigning it to a variable that 
you later check (a variable that will not pass the 'strict' rules)

but one thing at a time :)

-- 
  jason -- elephant@squirrelgroup.com --


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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

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

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


------------------------------
End of Perl-Users Digest V9 Issue 4536
**************************************


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