[19055] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1250 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 5 11:05:31 2001

Date: Thu, 5 Jul 2001 08:05:08 -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: <994345507-v10-i1250@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 5 Jul 2001     Volume: 10 Number: 1250

Today's topics:
    Re: Chmod and File::Find (Tad M) (Tad McClellan)
    Re: Chmod and File::Find (Tad McClellan)
    Re: clean up an array of references from references whi <godzilla@stomp.stomp.tokyo>
    Re: clean up array from "holes"... <godzilla@stomp.stomp.tokyo>
    Re: Counting occurances on a line (Rafael Garcia-Suarez)
    Re: Counting occurances on a line <peb@bms.umist.ac.uk>
    Re: Counting occurances on a line <peb@bms.umist.ac.uk>
    Re: Counting occurances on a line <tschmelter@statesman.com>
    Re: Counting occurances on a line <tom.melly@ccl.com>
    Re: Counting occurances on a line (Tad McClellan)
    Re: FAQ 9.4:   How do I extract URLs? (Tad McClellan)
    Re: Help: Carriage Returns in strings (Tad McClellan)
    Re: How I came to love Perl... (dave)
    Re: Keen, experienced, or improving Perl author require (Tad McClellan)
    Re: Net::Telnet logging on problem..... <r1ckey@home.com>
    Re: Odd scalar equality problem <ren@tivoli.com>
    Re: parallel processes w/perl <tschmelter@statesman.com>
        passing information between mutiple forms <ub98aa@brocku.ca>
        perldoc -q <thelma@alpha2.csd.uwm.edu>
    Re: perldoc -q <tom.melly@ccl.com>
    Re: Re Counting occurances on a line (Twarren10)
    Re: Text based menuing system in Perl with submenus??? <mjcarman@home.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 5 Jul 2001 09:31:37 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Chmod and File::Find (Tad M)
Message-Id: <slrn9k8r1o.gev.tadmc@tadmc26.august.net>

BUCK NAKED1 <dennis100@webtv.net> wrote:
>I added a sub to change index.blah to main.blah, and a sub to delete any
>htaccess or htpasswd file. Here's what I ended up with...


>        sub del_htaccess {
>        my ($file) = @_;
>        my $newname = $file;
>             return unless $newname =~ m/\.htaccess|\.htpasswd$/i;


That will unlink files with names like:

   .htaccessable
   foo.htpasswd

You should anchor _both_ ends of the pattern. You need parenthesis
for grouping:

   return unless $newname =~ m/^(\.htaccess|\.htpasswd)$/i;

or factor out the common parts:

   return unless $newname =~ m/^\.ht(access|passwd)$/i;


>             unlink($newname); 


Aren't you interested in whether or not the unlink() call actually
unlinked or not?

You failed to check the return value from the unlink() function.

You should check the return value from the unlink() function.

   unlink($newname) or die "could not unlink '$newname'  $!"; 



>        sub rename_index {
>        my ($file) = @_;
>        my $newname = $file;
>             return unless $newname =~ s/\index/main/i;
                                          ^
                                          ^ yet another useless backslash


That will rename 'poindexter' to 'pomainter'. Is that what you want?

\i has no meaning. Using it there should be generating a warning about
an "Unrecognized escape".

Did you get a warning like that when you ran your code?

You should fix your code so that it does not generate any warning messages.


>        sub safe_rename { 
>        my ($oldfile, $newfile) = @_;
>        return if ($oldfile eq $newfile);
>        if (-f $newfile) { 
             ^^
             ^^

Q: What if $newfile already exists as a directory, symlink, pipe...?

A: It gets rename()d too.

   if (-e $newfile) {   # seems safer



>I hope that does it. No, I'm not trying to push work off on anyone. I
>spent much time on this. 


I apologize for the accusation then.

I found it suspicious that you did not mention that the code
did not even perform its intended function though.


>I made a new subject 
>because I thought I should've included File::Find
>in the subject. 


You can change the Subject and leave the References intact.

That way it still appears in the same thread, but with the
new Subject.


>Sorry about bad wrap and no quoting; but that's a fault
>of my OS, WTV.
           ^^^

You should get software that is not broken.

Using broken software will reduce the visibility of your posts.


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


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

Date: Thu, 5 Jul 2001 08:50:49 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Chmod and File::Find
Message-Id: <slrn9k8ol9.gev.tadmc@tadmc26.august.net>

BUCK NAKED1 <dennis100@webtv.net> wrote:
>JFYI... Tad: I have been taking advice and testing it. After someone
>suggested checking return values, I did that, cleaned it up to where I
>didn't get any errors, and then I posted it. 


Good. Thank you.

But you need to add "does it perform its intended function?" to
the list of things to consider when testing.

:-)


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


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

Date: Thu, 05 Jul 2001 07:11:23 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: clean up an array of references from references which are pointing  into empty arrays
Message-Id: <3B44758B.8D518BED@stomp.stomp.tokyo>

Uri Guttman wrote:

(sointly snipped)
 
> Alexvalara wrote:
 
> > an array of arrays you want to get rid of empty arrays of the array!

> well, you learned quickly enough to ignore moronzilla.
 
> forst, do you mean...

Why Sointly!


> @non_empty = grep { @{$_} } @mixed ;
 
> @non_empty = grep { length $_->[0] } @mixed ;


Well look at you Uri! You are beginning to learn a little Perl!
Yes, you sointly are!


Godzilla!   Queen Of Zeroes.


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

Date: Thu, 05 Jul 2001 07:04:37 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: clean up array from "holes"...
Message-Id: <3B4473F5.52B04F5A@stomp.stomp.tokyo>

Alexvalara wrote:
 
 
> The following message is for "Godzilla"...:
> I am happy because  i gave you the opportunity
> to prove that you are alive out there, programming...living...thinking...
> Do not take it personally!


I enjoyed revealing you as our resident troll.

Godzilla!


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

Date: 5 Jul 2001 13:02:34 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Counting occurances on a line
Message-Id: <slrn9k8pbp.obt.rgarciasuarez@rafael.kazibao.net>

Blstone77 wrote in comp.lang.perl.misc:
> Hiow would I go about counting the number of times the : character occurs on a
> line? I looked in the manual, but maybe I am phrasing the question wrong. Can
> anyone help?

perldoc -q count gives the answer :
  my $count = ($string =~ tr/://);
Other methods are possible, but this one is [one of the] most efficient.

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Thu, 05 Jul 2001 14:21:04 +0100
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: Counting occurances on a line
Message-Id: <3B4469C0.5F7D0CE5@bms.umist.ac.uk>

Tom Melly wrote:
> 
> "Blstone77" <blstone77@aol.com> wrote in message
> news:20010705081348.16088.00002757@ng-xc1.aol.com...
> > Example
> > trouble:walk:taken:moose:sandlot:time
> >
> > Hiow would I go about counting the number of times the : character occurs on a
> > line? I looked in the manual, but maybe I am phrasing the question wrong. Can
> > anyone help?
> 
> $string = "hello:world:goodbye:world";
> $count = -1 + split /\:/, $string;
> print "$count\n";

Or, without having to split the string

$string = "hello:world:goodbye:world";
$count++ while($string =~ /:/g);
print "$count\n";

Paul


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

Date: Thu, 05 Jul 2001 14:33:18 +0100
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: Counting occurances on a line
Message-Id: <3B446C9E.F7B0103A@bms.umist.ac.uk>

Paul Boardman wrote:
> 
> Tom Melly wrote:
> >
> > "Blstone77" <blstone77@aol.com> wrote in message
> > news:20010705081348.16088.00002757@ng-xc1.aol.com...
> > > Example
> > > trouble:walk:taken:moose:sandlot:time
> > >
> > > Hiow would I go about counting the number of times the : character occurs on a
> > > line? I looked in the manual, but maybe I am phrasing the question wrong. Can
> > > anyone help?
> >
> > $string = "hello:world:goodbye:world";
> > $count = -1 + split /\:/, $string;
> > print "$count\n";
> 
> Or, without having to split the string
> 
> $string = "hello:world:goodbye:world";
> $count++ while($string =~ /:/g);
> print "$count\n";

I thought I'd benchmark these to see which was faster & came accross an
error I don't understand.

"Use of implicit split to @_ is deprecated at
perl/benchmark_while_split.pl line 14"

I understand what the error means.  I just can't see the implicit split!

#!/usr/bin/perl -w
use strict;

use Benchmark;
my $string = "hello:world:goodbye:world";

sub while_version{
   my $a;
   $a++ while($string =~ /:/g);
}

sub split_version{
   my $a;
   $a = -1 + split(/:/, $string);
}

timethese(200000, { While => 'while_version()',
                    Split => 'split_version()'});

OUTPUT:-

Use of implicit split to @_ is deprecated at
perl/benchmark_while_split.pl line 14.
Benchmark: timing 200000 iterations of Split, While...
     Split:  5 wallclock secs ( 3.10 usr +  0.02 sys =  3.12 CPU) @
64102.56/s (n=200000)
     While:  2 wallclock secs ( 2.02 usr +  0.02 sys =  2.04 CPU) @
98039.22/s (n=200000) 

Paul


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

Date: Thu, 05 Jul 2001 14:09:51 GMT
From: Tim Schmelter <tschmelter@statesman.com>
Subject: Re: Counting occurances on a line
Message-Id: <3B44752E.875812DB@statesman.com>

Tom Melly wrote:

> "Blstone77" <blstone77@aol.com> wrote in message
> news:20010705081348.16088.00002757@ng-xc1.aol.com...
> > Example
> > trouble:walk:taken:moose:sandlot:time
> >
> > Hiow would I go about counting the number of times the : character occurs on a
> > line? I looked in the manual,

Blstone77, What manual? "perldoc -q count" gives a pretty whiz-bang answer to this
problem.


> but maybe I am phrasing the question wrong. Can
> > anyone help?
>
> $string = "hello:world:goodbye:world";
> $count = -1 + split /\:/, $string;
> print "$count\n";

This solution has several problems.
First, the colon isn't a special character: don't backslash it.

Next, the "split" is probably always going to be slower on the OPs problem, even
allowing for different lengths of $string:
#!/usr/local/bin/perl -w
# tastmp.pl 20010705
use strict;
use Benchmark;

my $string = "trouble:walk:taken:moose:sandlot:time";
my $count  = 0;
timethese( 1<<16, {
        split_short => sub { $count = -1 + split /\:/, $string; },
        tr_short    => sub { $count = ($string =~ tr/://); },
});

$string = join(':', map { rand($_)*$_ } (0..2048));
$count  = 0;
timethese( 1<<12, {
        split_long => sub { $count = -1 + split /\:/, $string; },
        tr_long    => sub { $count = ($string =~ tr/://); },
});
[tas@fozzie tas]$ perl tastmp.pl
Use of implicit split to @_ is deprecated at tastmp.pl line 9.
Use of implicit split to @_ is deprecated at tastmp.pl line 16.
Benchmark: timing 65536 iterations of split_short, tr_short...
split_short:  0 wallclock secs ( 0.44 usr +  0.00 sys =  0.44 CPU) @ 148945.45/s
(n=65536)
  tr_short:  1 wallclock secs ( 0.07 usr +  0.00 sys =  0.07 CPU) @ 936228.57/s
(n=65536)
            (warning: too few iterations for a reliable count)
Benchmark: timing 4096 iterations of split_long, tr_long...
split_long:  7 wallclock secs ( 7.11 usr +  0.00 sys =  7.11 CPU) @ 576.09/s
(n=4096)
   tr_long:  1 wallclock secs ( 0.97 usr +  0.00 sys =  0.97 CPU) @ 4222.68/s
(n=4096)


But, TMTOWTDI, so sacrificing speed for readability isn't a big problem if you can
live with the performance hit. Unfortunately, "-1 + split /\:/, $string;" doesn't
strike me as any more readable than "($string =~ tr/://)". Maybe not *less*
readable, however. :-)

The most important issue, though, is indicated by the warning generated with -w:
    Use of implicit split to @_ is deprecated at foo.pl line XX.

In other words, split returns an array, but you don't capture the array, so perl
assigns the value to the parameter array @_. Heaven help you if you're using that
inside a subroutine, and you haven't captured the parameters yet. Or if you later
call another subroutine using &foo:
    $ perldoc -q "&foo" # To bypass all the other stuff returned by "perldoc -q
function"
        <snip>
        When you call a function as "&foo", you allow that
        function access to your current @_ values, and you
        bypass prototypes.  The function doesn't get an
        empty @_--it gets yours!

In that case, &foo now gets @_==qw(trouble walk taken moose sandlot time), which may
not be what you mean for it to get. If it is, it's probably better to be explicit
about it and save some poor future maintainer some heartache, hence the warning.

Morals: consult "perldoc -q count", stick with "tr", and always always use strict
and -w.

--
Tim Schmelter
Public Key available from http://www.keyserver.net
CAD7 2ABB 05A4 2F00 4CAE 7D2F 127C 129A 7173 2951




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

Date: Thu, 5 Jul 2001 15:54:26 +0100
From: "Tom Melly" <tom.melly@ccl.com>
Subject: Re: Counting occurances on a line
Message-Id: <3b447fa2$0$3764$ed9e5944@reading.news.pipex.net>

"Tim Schmelter" <tschmelter@statesman.com> wrote in message
news:3B44752E.875812DB@statesman.com...

> This solution has several problems.
> First, the colon isn't a special character: don't backslash it.
>

Oops, I can only remember the specials when there's an R in the month...

>
> The most important issue, though, is indicated by the warning generated
with -w:
>     Use of implicit split to @_ is deprecated at foo.pl line XX.
>

<snip>

Ouch! Live and learn... (my "Perl in a Nutshell" must be out of date).

Thanks for the info.




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

Date: Thu, 5 Jul 2001 09:54:19 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Counting occurances on a line
Message-Id: <slrn9k8scb.gev.tadmc@tadmc26.august.net>

Paul Boardman <peb@bms.umist.ac.uk> wrote:
>Paul Boardman wrote:
>> Tom Melly wrote:
>> > "Blstone77" <blstone77@aol.com> wrote in message
>> > news:20010705081348.16088.00002757@ng-xc1.aol.com...

>> > > Hiow would I go about counting the number of times the : character occurs on a
>> > > line? 

>I thought I'd benchmark these to see which was faster & came accross an
>error I don't understand.


you should add tr/// too. tr/// is Really Good at counting characters:

   $a = $string =~ tr/://;


>"Use of implicit split to @_ is deprecated at
>perl/benchmark_while_split.pl line 14"
>
>I understand what the error means.  I just can't see the implicit split!


   perldoc -f split

 ------------------------------
If not in list context, returns the number of fields found and splits into
the C<@_> array.
 ------------------------------


>sub split_version{
>   my $a;
>   $a = -1 + split(/:/, $string);


And there is a split() that is "not in list context".


"Add a negative one" seems an obfuscation of "subtract one":

   $a = split(/:/, $string) - 1;


>timethese(200000, { While => 'while_version()',
>                    Split => 'split_version()'});


A tr_version() will kick ass compared to either of those...


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


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

Date: Thu, 5 Jul 2001 08:54:00 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: FAQ 9.4:   How do I extract URLs?
Message-Id: <slrn9k8or8.gev.tadmc@tadmc26.august.net>

BUCK NAKED1 <dennis100@webtv.net> wrote:

>I understand now. Thanks for explaining it to me.


But your References header is still broken.

Please get your "newsreader" working properly.


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


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

Date: Thu, 5 Jul 2001 09:59:12 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Help: Carriage Returns in strings
Message-Id: <slrn9k8slg.gev.tadmc@tadmc26.august.net>

J.D. Fieldsend <u9jdf@csc.liv.ac.uk> wrote:
>I have some string and they contain carriage returns in them. I would
>like to remove them. I have tried using
>
>$string =~ s/\r//g; # to remove \r from the string
>
>But this doesn't work.


Yes it does.

There is something you are not telling us (like you are running
on Windows where perl adds CRs when you get around to outputting.
Maybe you just need binmode()? ).

tr/// is Much Better that s/// when working with characters rather
than with strings or patterns:

   $string =~ tr/\r//d;


>Could anyone please help


If we had a short and complete program that we could run to
duplicate your problem we could.

But we don't, so we can't.  (hint)


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


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

Date: 5 Jul 2001 07:22:37 -0700
From: usted@cyberspace.org (dave)
Subject: Re: How I came to love Perl...
Message-Id: <e2c00ae.0107050622.7caf46a9@posting.google.com>

Then I see
> > it!  When I was learning Perl it was all about text, words, data and
> > what I could do with it.  Math (the bad thing) wasn't involoved!
> > Whenever I opened a programming book there was all this math (which I
> > didn't get in high school and avoided in college) that muddied things
> > up for me.
> >
> > --So inconclusion I fell in love with Perl b/c _for me_ it's all about
> > words, text and data with which I am particularly comfortable.

To the OP and anyone else who has that same love text/hate numbers thing:

http://web.meganet.net/yeti/PCarticle.html

dave


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

Date: Thu, 5 Jul 2001 10:04:02 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Keen, experienced, or improving Perl author required
Message-Id: <slrn9k8sui.gev.tadmc@tadmc26.august.net>

Steve <steve@zeropps.uklinux.net> wrote:
>On Wed, 4 Jul 2001 23:54:43 +0100, Tony wrote:

>>This venture will only be on a mutual profit sharing method where some 20%
>>of the income revenue will be the reward over a 3 to 5 year period. 25% is
>>being offered to partner affiliates. Therefore this is not a once off pay up
>>front deal - but an experienced analysis of some of the ideas that solid
>>bricks to clicks converts need.
>
>So what you're saying is that you want someone to work for nothing for six
>months on a venture that will probably fail (as most do). 


Readers should also note that if it really was a Good Idea, then
it would have attracted venture capital and be able to make
payroll, rather than promise to "pay some time in the future".


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


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

Date: Thu, 05 Jul 2001 14:31:36 GMT
From: Rickey Ingrassia <r1ckey@home.com>
Subject: Re: Net::Telnet logging on problem.....
Message-Id: <cT_07.14147$wr.68920@news1.frmt1.sfba.home.com>

In comp.lang.perl.misc Yas <yasser@x-unity-x.demon.co.uk> wrote:
>In article <maI07.12100$wr.62100@news1.frmt1.sfba.home.com>, "Rickey
>Ingrassia" <r1ckey@home.com> wrote:
><snip>

--snip--

>Thns for your help.... now there is a new problem....

>below is my code:

>#!/usr/bin/perl -w

>use Net::Telnet;

>$HOST = new Net::Telnet(Port => "10001", Errmode => "return", Prompt => '/[?>:#\]][ ]*$/');
>$HOST->open("MY IP");

>$username="admin";
>$password="<PASSWORD>";

>$HOST->input_log("/tmp/input.log");

>$HOST->login("$username","$password");

>@test = $HOST->cmd("help");
>$HOST->close;

>print @test."\n";

>It should print loads of help commands... but instead prints 0... ive
>tried other commadns and instead prints just numbers....

>thnx in advance for any help

What's in your input.log file?  Does the prompt regex match your prompt?

-- 
       ____        __                 
______/_   | ____ |  | __ ____ ___.__.
\_  __ \   |/ ___\|  |/ // __ <   |  |
 |  | \/   \  \___|    <\  ___/\___  |
 |__|  |___|\___  >__|_ \\___  > ____|
_________________\/_____\/____\/\/_____
---------------------------------------


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

Date: 05 Jul 2001 00:58:22 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Odd scalar equality problem
Message-Id: <m3d77fdiip.fsf@dhcp9-173.support.tivoli.com>

On 4 Jul 2001, vrigas@hotmail.com wrote:

> Ren Maddox <ren@tivoli.com> wrote in message
> news:<m3g0cenluw.fsf@dhcp9-173.support.tivoli.com>...
>> On 3 Jul 2001, vrigas@hotmail.com wrote:
>> 
>> Well, you could check the value of $value[1] with something like:
>> 
>> printf "%3d [$_]\n", ord for $value[1] =~ /./gs;
> 
> That sound's a good idea. I m not familiar with this procetion, but
> I ll try it any way.

Let us know how that goes.  I expect it will reveal the problem.

> Some people in IRC tald me that there must be a problem with pack()
> funtion. I use a rutine that I copied/pasted from another script, to
> convert the elements of a form to plain text, and it worked fine
> until now. I m a newbe, and not familiar with the pack function. Is
> there a possibility I m doing something wrong there?
> 
> the rutine is:
> 
> read(STDIN, $buffer , $ENV{"CONTENT_LENGTH"});
> print "Content-type: text/html\n\n";
> my(@value);
> @pairs=split(/\&/,$buffer);
> $i=0;
> foreach $pair (@pairs){
>         ($name[$i],$value[$i])=split(/\=/,$pair);
>         $value[$i] =~ tr/+/ /;
>         $value[$i] =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",
> hex($1))/eg;
>         $i++;
> }

Well, aside from the fact that I would highly recommend using CGI.pm
instead of the above, that looks fine.

> Is it posible that I m having false when I compare a text line from
> a file with a scalar with a value taken after the above rutine
> runned?

Well, given that that's the behavior you're seeing, I guess it's
possible... :)

-- 
Ren Maddox
ren@tivoli.com


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

Date: Thu, 05 Jul 2001 13:09:11 GMT
From: Tim Schmelter <tschmelter@statesman.com>
Subject: Re: parallel processes w/perl
Message-Id: <3B4466F7.A57FC06E@statesman.com>

Michael Gilfix wrote:

> However, Perl does have threading support. It started around the
> earlier versions of 5. It used to be experimental but I haven't heard any
> warnings about it being experimental so it might be worth taking a look.

<snip>

From the 5.6.1 "Configure" script:
    Perl can be built to take advantage of threads on some systems.
    To do so, Configure can be run with -Dusethreads.

    Note that threading is a highly experimental feature, and
    some known race conditions still remain.  If you choose to try
    it, be very sure to not actually deploy it for production
    purposes.  README.threads has more details, and is required
    reading if you enable threads.

I don't know anything about Perl6 threads, though. You can check out the perl6
mailing list.

--
Tim Schmelter
Public Key available from http://www.keyserver.net
CAD7 2ABB 05A4 2F00 4CAE 7D2F 127C 129A 7173 2951




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

Date: Thu, 05 Jul 2001 10:25:26 -0400
From: Umair Tariq Bajwa <ub98aa@brocku.ca>
Subject: passing information between mutiple forms
Message-Id: <3B4478D5.C069D1C5@brocku.ca>


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

I have a main script called "awards.pl" from where i execute another
script called "investigator.pl" in a seperate popup window. Once the
user enters all the information in investigator.pl he/she hits "Done"
button. What I would like to do is once the user will hit Done,
I would like to store all information in hash and pass it to "awards.pl"
(the main script from where its being executed or called) something like
that. Any suggestions? Does anyone know how can i do that? Any idea is
most welcome. Thanks in advance.

regards,

Umair

Favorite Quotes:
===============
"The box said 'Windows 95 or better', so I installed Linux"
                                                          -- Unknown
"A computer without Windows is like a chocolate cake without mustard."
                                                           -- Unknown



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

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
I have a main script called "awards.pl" from where i execute another script
called "investigator.pl" in a seperate popup window. Once the user enters
all the information in investigator.pl he/she hits "Done" button. What
I would like to do is once the user will hit Done,
<br>I would like to store all information in hash and pass it to "awards.pl"
(the main script from where its being executed or called) something like
that. Any suggestions? Does anyone know how can i do that? Any idea is
most welcome. Thanks in advance.
<p>regards,
<p>Umair
<pre>Favorite Quotes:&nbsp;
===============
"The box said 'Windows 95 or better', so I installed Linux"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- Unknown
"A computer without Windows is like a chocolate cake without mustard."
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- Unknown</pre>
&nbsp;</html>

--------------D9AA986823F9592EBAB79A18--



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

Date: 5 Jul 2001 14:38:31 GMT
From: Thelma Lubkin <thelma@alpha2.csd.uwm.edu>
Subject: perldoc -q
Message-Id: <9i1u57$v4b$2@uwm.edu>

We are often urged to use perldoc -q to search the documentation for
help on something that we can describe in a short phrase, but where we
don't know associated function names.  
The perldoc on my system does not support the -q option.  I am in no 
position to get the administrators to do anything about this, so can 
you suggest alternatives for me?

---------------------------------------------------------------------
Here are the first few lines of the system's perldoc program:

#!/usr/local/bin/perl
    eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'
	if $running_under_some_shell;

@pagers = ();
push @pagers, "/usr/local/bin/less" if -x "/usr/local/bin/less";

#
# Perldoc revision #1 -- look up a piece of documentation in .pod format that
# is embedded in the perl installation tree.
#
# This is not to be confused with Tom Christianson's perlman, which is a
# man replacement, written in perl. This perldoc is strictly for reading
# the perl manuals, though it too is written in perl.

if(@ARGV<1) {
	$me = $0;		# Editing $0 is unportable
	$me =~ s,.*/,,;
	die <<EOF;
Usage: $me [-h] [-v] [-t] [-u] [-m] [-l] PageName|ModuleName|ProgramName

  
                               --thanks, thelma


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

Date: Thu, 5 Jul 2001 16:01:46 +0100
From: "Tom Melly" <tom.melly@ccl.com>
Subject: Re: perldoc -q
Message-Id: <3b44815a$0$3763$ed9e5944@reading.news.pipex.net>

"Thelma Lubkin" <thelma@alpha2.csd.uwm.edu> wrote in message
news:9i1u57$v4b$2@uwm.edu...

<snip>

Have you got access to a Windows machine? You could install active state perl on
that which would give you perldoc.




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

Date: 05 Jul 2001 13:25:55 GMT
From: twarren10@aol.com (Twarren10)
Subject: Re: Re Counting occurances on a line
Message-Id: <20010705092555.08460.00002443@ng-cj1.aol.com>

>? is it me or did opening this message try to access my email addresses ????

It's just you!


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

Date: Thu, 05 Jul 2001 08:42:01 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Text based menuing system in Perl with submenus???
Message-Id: <3B446EA9.5C1D234@home.com>

David Mohorn wrote:
> 
> Does anyone have any sample code of a text base menu system in
> Perl that is flexible and easy to maintain?  I could have nested
> menus, meaning: menu 1 could have an option to menu 2.  Menu 2
> could have an option for menu 3.  As users back out from menu 3,
> it should return to menu 2, then back to menu 1.

I don't know what the Curses module provides as I've never used it, but
it may be helpful for you. If not, here's a chunk of code I wrote a
while back when I was trying to do something similar and got tired of
writing a bunch of code for each menu. It won't handle the state machine
stuff, you'll have to do that yourself, but it should make it easy to
create multiple menus.

#!/usr/local/bin/perl5 -w
use strict;

# EXAMPLE:
my %menu_hash = (
    E => 'Echo',
    C => 'Charlie',
    A => 'Alpha',
    D => 'Delta',
    B => 'Bravo',
    F => 'Foxtrot');
    
my $choice = Pick_From_Menu(numeric_keys   => 0, 
                            sort_by_values => 1,
                            max_display    => 4,
                            prompt         => 'Whatcha want?',
                            menu           => \%menu_hash);
print "You chose $choice.\n";

sub Clear_Screen {
    if ($^O =~ /MSWin/) {
        system('cls');   # Win* platforms
    }
    else {
        system('clear'); # Guess that it's a *nix platform
    }
}

#-----------------------------------------------------------------------
# Subroutine : Pick_From_Menu(%)
# Purpose    : Generic and flexible subroutine for creating a menu
#              using a hash as the menu items.
# Notes      : Call with named aggregate notation. Aside from 'menu', 
#              all arguments are optional. 'menu' must be given a hash
#              reference, not a hash!
#-----------------------------------------------------------------------
sub Pick_From_Menu {
    my %args = ( 
        # Default parameter values
        confirm        => 0, # 0 -> Return on first valid response
                             # 1 -> Confirm selection before returning
        max_errors     => 3, # N -> Give up after N invalid choices
        clear_on_err   => 1, # 0 -> Just keep streaming down the screen
                             # 1 -> Clear screen on error/next page
        sort_by_values => 0, # 0 -> Display items sorted by hash keys
                             # 1 -> Display items sorted by hash values
        numeric_keys   => 1, # 0 -> Sort keys numerically
                             # 1 -> Sort keys alphabetically
        max_display    => 0, # 0 -> Display the full menu
                             # N -> Display menu N items at a time
        return_key     => 0, # 0 -> Returns hash value
                             # 1 -> Returns hash key
        prompt         => 'Please make a selection:',
        menu           => undef,
        @_);
    my @list;
    my $count;
    my $response;
    my $returnval;
    my ($first_item, $last_item);
    my $select_prompt;
    
    die ('No menu to pick from') unless ref($args{menu}) eq 'HASH';

    if ($args{sort_by_values}) {
        @list = sort {$args{menu}->{$a} cmp $args{menu}->{$b}} 
                     keys %{$args{menu}};
    }
    elsif ($args{numeric_keys}) {
        @list = sort {$a <=> $b} keys %{$args{menu}};
    }
    else {
        @list = sort {$a cmp $b} keys %{$args{menu}};
    }

    # If the caller didn't specify a maximum number of menu items to
    # display at a time, default to the number of items in the menu.
    $args{max_display} ||= @list;

    #-------------------------------------------------
    # Initializes limits on menu items to be displayed
    #-------------------------------------------------
    my $Init_Disp_Limits = sub {
        $first_item = 0;
        if ($args{max_display} < @list) {
            $last_item = $args{max_display} - 1;
            $select_prompt = 'Selection (ENTER for more): ';
        }
        else {
            $last_item = $#list;
            $select_prompt = 'Selection: ';
        }
    };

    $Init_Disp_Limits->();

    for ($count = 0; $count < $args{max_errors}; $count++) {

        printf ("%s\n", $args{prompt});
        foreach ($first_item .. $last_item) {
            printf ("%3s - %s\n", $list[$_], $args{menu}->{$list[$_]});
        }
        print "\n";
        
        print $select_prompt;
        $response = <STDIN>;
        chomp $response;

        if ($response =~ /^\s*$/) {
            if ($last_item >= $#list) {
                $Init_Disp_Limits->();
            }
            else {
                $first_item = $last_item + 1;
                if ($#list > $last_item + $args{max_display}) {
                    $last_item += $args{max_display};
                }
                else {
                    $last_item = $#list;
                }
            }
            Clear_Screen() if $args{clear_on_err};
            redo;
        }
        
        if (defined $args{menu}->{$response}) {
            $returnval = ($args{return_key}) 
                ? $response
                : $args{menu}->{$response};
            if ($args{confirm}) {
                print "Selection = $response\n";
                print 'Is this correct? [Y]/N : ';
                my $confirm = <STDIN>;
                if ($confirm =~ /^(y|\n)/i) {
                    return ($returnval);
                }
                else {
                    $Init_Disp_Limits->();
                    $count = 0;
                    Clear_Screen() if ($args{clear_on_err});
                    redo;
                }
            }
            else {
                return ($returnval);
            }
        }
        else {
            Clear_Screen() if ($args{clear_on_err});
            print "Your response '$response' is not valid.\n\n";
            $Init_Disp_Limits->();
        }
    }
    print "Too many invalid attempts. Exiting.\n";
    exit;
} # END Pick_From_Menu()


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

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


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