[18762] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 930 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 18 11:05:37 2001

Date: Fri, 18 May 2001 08: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)
Message-Id: <990198307-v10-i930@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 18 May 2001     Volume: 10 Number: 930

Today's topics:
        Adding lines to the beginning of a data file? <nick@NOSPAM3db.co.uk>
    Re: An Example Of A Polite FAQ lvirden@yahoo.com
    Re: Building ActivePerl under Win9x <admin@ase-ga.com>
    Re: Building ActivePerl under Win9x <bowman@montana.com>
        chmod frustrations... <coyoteman@sympatico.ca>
    Re: chmod frustrations... (John Joseph Trammell)
    Re: chmod frustrations... (Bernard El-Hagin)
    Re: chmod frustrations... <coyoteman@sympatico.ca>
    Re: chmod frustrations... (John Joseph Trammell)
    Re: chmod frustrations... <tony_curtis32@yahoo.com>
    Re: Curious Newbie asks a question <admin@ase-ga.com>
        Hash: keys to variable names, or variable names to keys <pauljohn@ukans.edu>
    Re: Hash: keys to variable names, or variable names to  (Anno Siegel)
    Re: Hash: keys to variable names, or variable names to  <koos_pol@nl.compuware.com.NOJUNKMAIL>
        Importing variables <real@earthling.net>
    Re: Importing variables <bart.lateur@skynet.be>
    Re: Importing variables <real@earthling.net>
        Looking for a console based file selection module <andrew@mvt.ie>
    Re: module for umlauts <ubl@schaffhausen.de>
    Re: Random Numbers Script <a.v.a@home.nl>
        Templates for Generating Calls to External Functions <sam.lay@mindspring.com>
        Zlib on Win32 <ommadawn@club-internet.fr>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 18 May 2001 16:00:38 +0100
From: "Nick" <nick@NOSPAM3db.co.uk>
Subject: Adding lines to the beginning of a data file?
Message-Id: <tgae6kcsc49s69@corp.supernews.co.uk>

Hello,

I'm using the following (simplified from what I'm actually doing) code to
save a line of data to a text file:

open(USERLOG, ">>log.dat");
 seek(USERLOG,0,0);
 print USERLOG "New line of information.\n";
close(USERLOG);

which appends the new line onto the end of the current document. My question
is: Is there a way of adding lines of data to the top of a text file
instead. In essence, is it possible to put the newest stuff at the top and
have everything else 'bumped' down a line?

Any wisdom would be much appreciated.

Thank you.

Nick.




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

Date: 18 May 2001 13:27:09 GMT
From: lvirden@yahoo.com
Subject: Re: An Example Of A Polite FAQ
Message-Id: <9e37vd$h3u$1@srv38.cas.org>


According to Godzilla! <godzilla@stomp.stomp.tokyo>:
:As a teacher, with each beginning of a new quarter, one of my
:first objectives is to test all my students and set a personalized
:baseline knowledge level, for each and every student, all two-hundred
:or so passing through my classroom daily. 

I am amazed that this appears to happen so infrequently.  So many
people seem unaware that there are different learning styles and
levels of comprehensive - or perhaps, it is that they are unwilling to
take these factors into consideration, deciding instead that everyone
must on their own come up to their level - regardless of how long they
have been doing something.

I've been using USENET since before there was a Compuserve , AOL, or
Prodigy ( sometimes, I feel very ancient) .  Only occasionally do I 
see technical communities take varying levels of experience into account
intentionally.

-- 
-- 
"See, he's not just anyone ... he's my son."  Mark Schultz
<URL: mailto:lvirden@cas.org> <URL: http://www.purl.org/NET/lvirden/>
Even if explicitly stated to the contrary, nothing in this posting


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

Date: Fri, 18 May 2001 10:58:23 GMT
From: "GArlington" <admin@ase-ga.com>
Subject: Re: Building ActivePerl under Win9x
Message-Id: <jf7N6.6667$hk3.838527@news1.cableinet.net>

Any particular reason why you try to build it if the Win install is
available?
G.A.

Ian Dash <I.J.Dash@cs.cf.ac.uk> wrote in message
news:9e1120$gkr7$1@ID-90042.news.dfncis.de...
> Hi,
>    has anyone actually managed to build ActivePerl under Win9x? I
> installed dmake and tried many times (even having tried a couple of
> different command shells, cygwin & 4DOS and trying nmake/dmake), but it
> bombs out telling me that something somewhere has passed too many
> parameters to something :-(.
>
> I'm trying (with not much success /:-|  ) to build ActivePerl build 626,
> using MS Visual C++ 5.0 Enterprise Edition. I would really like to get
> this to work - as I can't build extensions under the binary release of
> 626 that Activestate give out, unfortunately they've used VC6.0 and the
> .lib file structure has changed so I can't link in perl56.lib!!
>
> Any help would be much appreciated :-)
>
> =Ian=
>




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

Date: Fri, 18 May 2001 07:21:09 -0600
From: "bowman" <bowman@montana.com>
Subject: Re: Building ActivePerl under Win9x
Message-Id: <0j9N6.289$QW1.1831@newsfeed.slurp.net>


"GArlington" <admin@ase-ga.com> wrote in message
news:jf7N6.6667$hk3.838527@news1.cableinet.net...
> Any particular reason why you try to build it if the Win install is
> available?

read the post again. If you want to build against the AS lib, you need
VC++6.0, as the lib is not compatible with VC++5.0, This is a MS thing, not
a AS one. If one wants to use MS tools, one keeps mailing money to
Redmond.......





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

Date: Fri, 18 May 2001 09:20:26 -0400
From: "tcm" <coyoteman@sympatico.ca>
Subject: chmod frustrations...
Message-Id: <Dk9N6.239191$Z2.2621639@nnrp1.uunet.ca>

I'm having a strange time with chmod here - I need to recurse directories
and chmod every file, perform an update then close....

In my recursing code:

 $chfile="$basedir2/$file";
 chmod (0777, '$chfile') or &cgierr("Unable to change permissions for
'$chfile' to '0777'. Reason: $!");

 open(FILE, "$basedir2/$file");
 # etc


Anyway, the cgierr handler is quitting reporting this:
Unable to change permissions for
'/usr/home/groovy/groovypostcards.com/members/demo/index.html' to '511'.
Reason: No such file or directory


HOWEVER, if I comment out the chmod request, the open() function works just
fine and the file is there. (This same proceedure runs flawlessly on a
different web server - just I don't have the chmod in place as for some
reason their server doesn't 'care' about the permissions?!?).


Any insight as to why chmod is giving me a hard time with this
configuration??

Thanks!

--

Ernie Johnson - webmaster@win50grand.com
Win Big Bucks from win50grand.com






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

Date: Fri, 18 May 2001 13:25:04 GMT
From: trammell@bayazid.hypersloth.invalid (John Joseph Trammell)
Subject: Re: chmod frustrations...
Message-Id: <slrn9ga695.6sc.trammell@bayazid.hypersloth.net>

On Fri, 18 May 2001 09:20:26 -0400, tcm <coyoteman@sympatico.ca> wrote:
> I'm having a strange time with chmod here - I need to recurse directories
> and chmod every file, perform an update then close....
> 
> In my recursing code:
> 
>  $chfile="$basedir2/$file";
>  chmod (0777, '$chfile') or &cgierr("Unable to change permissions for
                ^^^^^^^^^
Lose the single quotes.

> '$chfile' to '0777'. Reason: $!");
> 
>  open(FILE, "$basedir2/$file");

-- 
The cost of software has always been development cost, not replication
cost.  Sharing that cost among even a few users radically cuts the
per-user cost.
      -- F. Brooks fails to predict IP disputes in _No Silver Bullet_


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

Date: Fri, 18 May 2001 13:35:56 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: chmod frustrations...
Message-Id: <slrn9ga8ov.d8j.bernard.el-hagin@gdndev25.lido-tech>

On Fri, 18 May 2001 09:20:26 -0400, tcm <coyoteman@sympatico.ca> wrote:
>I'm having a strange time with chmod here - I need to recurse directories
>and chmod every file, perform an update then close....
>
>In my recursing code:
>
> $chfile="$basedir2/$file";
> chmod (0777, '$chfile') or &cgierr("Unable to change permissions for
               ^^^^^^^^^

Get rid of the single quotes. With the quotes you're really looking
for a file literally named "dollar sign"-c-h-f-i-l-e.

Cheers,
Bernard


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

Date: Fri, 18 May 2001 09:47:48 -0400
From: "tcm" <coyoteman@sympatico.ca>
Subject: Re: chmod frustrations...
Message-Id: <JJ9N6.239197$Z2.2621444@nnrp1.uunet.ca>

Here's another one then ;)

With the single quotes gone, I get "Operation not permitted" - a bit better
than file not found, but do you have any experience on why this would not be
permitted?


Thanks!

Ernie Johnson - webmaster@win50grand.com
Win Big Bucks from win50grand.com


John Joseph Trammell <trammell@bayazid.hypersloth.invalid> wrote in message
news:slrn9ga695.6sc.trammell@bayazid.hypersloth.net...
> On Fri, 18 May 2001 09:20:26 -0400, tcm <coyoteman@sympatico.ca> wrote:
> > I'm having a strange time with chmod here - I need to recurse
directories
> > and chmod every file, perform an update then close....
> >
> > In my recursing code:
> >
> >  $chfile="$basedir2/$file";
> >  chmod (0777, '$chfile') or &cgierr("Unable to change permissions for
>                 ^^^^^^^^^
> Lose the single quotes.
>
> > '$chfile' to '0777'. Reason: $!");
> >
> >  open(FILE, "$basedir2/$file");
>
> --
> The cost of software has always been development cost, not replication
> cost.  Sharing that cost among even a few users radically cuts the
> per-user cost.
>       -- F. Brooks fails to predict IP disputes in _No Silver Bullet_




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

Date: Fri, 18 May 2001 13:51:53 GMT
From: trammell@bayazid.hypersloth.invalid (John Joseph Trammell)
Subject: Re: chmod frustrations...
Message-Id: <slrn9ga7rd.716.trammell@bayazid.hypersloth.net>

On Fri, 18 May 2001 09:47:48 -0400, tcm <coyoteman@sympatico.ca> wrote:
> Here's another one then ;)
> 
> With the single quotes gone, I get "Operation not permitted" - a bit better
> than file not found, but do you have any experience on why this would not be
> permitted?

Please trim messages.  Please don't top-post.

Do you actually have the permissions to do the operation you're
trying?

-- 
[W]hen the manager knows his boss will accept status reports without
panic or preeemption, he comes to give honest appraisals.
                               - F. Brooks, _The Mythical Man-Month_


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

Date: 18 May 2001 08:57:54 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: chmod frustrations...
Message-Id: <878zjug3od.fsf@limey.hpcc.uh.edu>

>> On Fri, 18 May 2001 09:20:26 -0400,
>> "tcm" <coyoteman@sympatico.ca> said:

> I'm having a strange time with chmod here - I need to
> recurse directories and chmod every file, perform an
> update then close....

> In my recursing code:

>  $chfile="$basedir2/$file"; chmod (0777, '$chfile') or
                                           ^^^^^^^^^

Single quotes stop interpolation.  That argument is
*literally* the string "$chfile".

> Anyway, the cgierr handler is quitting reporting this:
> Unable to change permissions for
> '/usr/home/groovy/groovypostcards.com/members/demo/index.html'
> to '511'.  Reason: No such file or directory

I suspect: the script is not running as "you", but as
"nobody" or some other unprivileged ID.

    http://www.boutell.com/openfaq/cgi/8.html


hth
t
-- 
Just reach into these holes.  I use a carrot.


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

Date: Fri, 18 May 2001 10:57:05 GMT
From: "GArlington" <admin@ase-ga.com>
Subject: Re: Curious Newbie asks a question
Message-Id: <5e7N6.6663$hk3.838046@news1.cableinet.net>

What kind of registration do you want?
If it is server based "restricted access" type then all you have to do is to
write to all .htaccess and .htpasswd files in all protected directories the
same registration info.
If it is server side script based - then have the script(s) look at only one
registration DB.
If it is neither - then try what was proposed in posting by Brandon
Thornburg.
G.A.

Sinema <Sinema_BTVS@SPAM-hotmail.com> wrote in message
news:1NTM6.2292$OS1.441314@news1.iquest.net...
> It seems no one knows how to do this.. ( well not sure If I posted here as
> of yet )
>
> I'm wanting to find a cgi script that will allow users to register from
one
> area instead of having to register in each of the areas provided on my
> website.
>
> I was told to make one and add some line to the bottom but I'm a novice I
> have no idea what that means and then I heard that I should try Javascript
> and then I didn't think that would work because if there was an error it
> would cause a huge mess
>
> ( like if a nick name is not available in that area )
>
> I'm totally lost .. I even thought that maybe there was a way to make
check
> boxes and let the user register in the areas they wish .. but again no
clue
> how to do that either lol
>
> Any help would be great
>
> --
> Regards
>
> Sinema - Sinema_BTVS@SPAM-hotmail.com
> < remove SPAM- to reply >
>
> --- Start Codex Buffy Code 0.1 -------------------------------------
> ECa S+++(S++)>S+ O! M+++(M+)>M P B* G(G-) W+(W)>W-- X! C* A+++ Z!
> --- End Codex Buffy Code --- http://www.planetx.com/buffy/code/ ----
>
>
>
>




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

Date: Fri, 18 May 2001 06:34:12 -0500
From: "Paul Johnson" <pauljohn@ukans.edu>
Subject: Hash: keys to variable names, or variable names to keys?
Message-Id: <tga2a0fkbru2e3@corp.supernews.com>

I wrote a CGI script that processes a bunch of string variables and saves
them into a dataset.  I find my self doing the same repetitive, stupid
things, one variable after another.  I wonder why can't I find a way to
make a hash of variable names and then just iterate over the hash?

I am no perl veteran, as you may guess.  So I'm not ashamed to share with
you my ignorance.  Here's a subroutine that checks the lengths of the
variables that have been inputted.  Earlier, the script has already read
the values out of the CGI input with declarations like

$lastname = $cgi_input->param('lastname');

Please excuse my mixture of HTML shortcuts from cgi and the actual HTML.
I've not been able to make the transition all the way...

sub validateLengths {
    
    if ( 
	 30 < (my $lastnameLength = length("$lastname")) || 
	 
	 20 < (my $firstnameLength = length("$firstname")) || 
	 20 < (my $middleLength = length("$middle")) || 
	 25 < (my $addr1Length = length("$addr1")) ||
         25 < (my $addr2Length = length("$addr1")) ||
	 25 < (my $cityLength = length("$city")) ||
	 15 < (my $stateLength = length("$state")) ||
	 11 < (my $zipLength = length("$zip")) ||
	 25 < (my $countryLength = length("$country")) ||
	 40 < (my $emailLength = length("$email")) ||
	 25 < (my $otherFieldLength = length("$otherField")) ||
	 256 < (my $careerLength = length("$career")) || 
	 256 < (my $usePolsLength = length("$usePols")) ||
	 256 < (my $profStoryLength = length("$profStory")) ||
	 20 <  (my $passwordLength = length("$password")) )
	{
	    
	    print "The Length of my lastNameLength $lastnameLength <P>";
	
	print " <HTML> ";
	
	print $cgi_input->h1('Sorry');
	print $cgi_input->h1({-align=>'center'},'You exceeded the length 
                          limit for one or more variables');
	print "<p>";
	print "Here are the particulars:<p><p>";
	if ($lastnameLength > 30) {
            print qq[Your entry for last name is too long.  
           We allowed 30 characters, but your name took $lastnameLength.
            Sorry, can you give us something shorter <p>];
        }
	     
        if ($firstnameLength > 20) { 
             print qq[Your first name entry is too long. 
            We allowed 20 characters, but your input took $firstnameLength.
             Sorry, can you find an alias or abbreviate somehow?<p>] ;
             }

	if ($middleLength > 20 ) {
             print qq[Your middle name entry is too long. 
            We allowed 20 characters, but your input took $middleLength.
            Sorry, can you find an alias or abbreviate somehow?<p>] ;
            }
	     
	if ($addr1Length > 25 ) {print qq[Your first address line entry is too long.
              We allowed 25 characters, but your input took $addr1Length.
              Sorry, can you abbreviate somehow?<p>];
              }

	if ($addr2Length > 25 ) { 
             print qq[Your second address line entry is too long.
            We allowed 25 characters, but your input took $addr2Length. 
            Sorry, can you abbreviate somehow?<p>];
              }

	if ($cityLength > 25 ) { print qq[Your city entry is too long. 
         We allowed 25 characters, but your input took $cityLength. 
         Sorry, can you abbreviate somehow?<p>];
         }
	     
	if ($stateLength > 15 ) { print qq[Your state entry is too long. 
          We allowed 15 characters, but your input took $stateLength. 
           Sorry, can you abbreviate somehow?<p>];
          }
	if ($zipLength > 11 ) { print qq[Your zip entry is too long. 
           We allowed 15 characters, but your input took $zipLength. 
           Sorry, can you abbreviate somehow?<p>] ;
           }
	if ($countryLength > 25 ) {
	 print qq[Your country entry is too long. 
 	     We allowed 25 characters, but your input took $countryLength. 
             Sorry, can you abbreviate somehow?<p>];
           }
	if ($emailLength > 40 ) { 
            print qq[Your email entry is too long. 
           We allowed 40 characters, but your input took $emailLength. 
            Sorry, can you abbreviate somehow?<p>]; 
           }
		 
	if ($otherFieldLength > 25 ){
           print qq[Your other field entry is too long.
           We allowed 25 characters, but your input took $otherFieldLength.
           Sorry, can you abbreviate somehow?<p>] ;
           }

	if ($careerLength > 256 ){ 
	    print qq[Your description of your career is too long. 
           We allowed 256 characters, but your input took $careerLength.
            Sorry, can you abbreviate somehow?<p>] ;
            }
	if ($usePolsLength > 256 ) {
             print qq[Your description of your use of politics is too long.
            We allowed 256 characters, but your input
             took  $usePolsLength. Sorry, can you abbreviate somehow?<p>] ;
         }

	if ($profStoryLength > 256 ) { 
           print qq[Your professor story is too long. 
          We allowed 256 characters, but your input took $profStoryLength.
            Sorry, can you abbreviate somehow?<p>] ;
           }

	    print q[<p><p>];
	    print q[Hit the browser back button and make those babies fit!<p>];
	     
	    print "  </HTML> ";  
	    return 1;
	}
    else {
	return 0;
    }
}


My idea is that I could create a hash using the variables as keys and the
contents would be arrays, say holding the maximum length allowed and the
observed length, and then I could iterate.  I need to be able to take the
keys and use them both as variable names like $lastname as well as
convert them to strings like "lastname" for printing out.

Am I just looking for a too-easy/simple minded approach?

All the examples of hashes I find have keys that are strings or such, not
variable names.  

And I can't understand the writeup I get from this
perldoc -q "How can I use a variable as a variable name?"

If you have advice, I'm listening.

Well, so long, and thanks for all the Perl.

PJ
http://lark.cc.ukans.edu/~pauljohn


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

Date: 18 May 2001 13:46:30 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Hash: keys to variable names, or variable names to keys?
Message-Id: <9e393m$f1b$1@mamenchi.zrz.TU-Berlin.DE>

According to Paul Johnson <pauljohn@ukans.edu>:
> I wrote a CGI script that processes a bunch of string variables and saves
> them into a dataset.  I find my self doing the same repetitive, stupid
> things, one variable after another.  I wonder why can't I find a way to
> make a hash of variable names and then just iterate over the hash?
> 
> I am no perl veteran, as you may guess.  So I'm not ashamed to share with
> you my ignorance.  Here's a subroutine that checks the lengths of the
> variables that have been inputted.  Earlier, the script has already read
> the values out of the CGI input with declarations like
> 
> $lastname = $cgi_input->param('lastname');
> 
> Please excuse my mixture of HTML shortcuts from cgi and the actual HTML.
> I've not been able to make the transition all the way...
> 
> sub validateLengths {
>     
>     if ( 
> 	 30 < (my $lastnameLength = length("$lastname")) || 
> 	 
> 	 20 < (my $firstnameLength = length("$firstname")) || 
> 	 20 < (my $middleLength = length("$middle")) || 
> 	 25 < (my $addr1Length = length("$addr1")) ||
>          25 < (my $addr2Length = length("$addr1")) ||
> 	 25 < (my $cityLength = length("$city")) ||
> 	 15 < (my $stateLength = length("$state")) ||
> 	 11 < (my $zipLength = length("$zip")) ||
> 	 25 < (my $countryLength = length("$country")) ||
> 	 40 < (my $emailLength = length("$email")) ||
> 	 25 < (my $otherFieldLength = length("$otherField")) ||
> 	 256 < (my $careerLength = length("$career")) || 
> 	 256 < (my $usePolsLength = length("$usePols")) ||
> 	 256 < (my $profStoryLength = length("$profStory")) ||
> 	 20 <  (my $passwordLength = length("$password")) )
> 	{
> 	    
> 	    print "The Length of my lastNameLength $lastnameLength <P>";
> 	
> 	print " <HTML> ";
> 	
> 	print $cgi_input->h1('Sorry');
> 	print $cgi_input->h1({-align=>'center'},'You exceeded the length 
>                           limit for one or more variables');
> 	print "<p>";
> 	print "Here are the particulars:<p><p>";
> 	if ($lastnameLength > 30) {
>             print qq[Your entry for last name is too long.  
>            We allowed 30 characters, but your name took $lastnameLength.
>             Sorry, can you give us something shorter <p>];
>         }
> 	     
>         if ($firstnameLength > 20) { 
>              print qq[Your first name entry is too long. 
>             We allowed 20 characters, but your input took $firstnameLength.
>              Sorry, can you find an alias or abbreviate somehow?<p>] ;
>              }

[more of same snipped]

You are right, this is an unsatisfactory state of affairs.
 
> My idea is that I could create a hash using the variables as keys and the
> contents would be arrays, say holding the maximum length allowed and the
> observed length, and then I could iterate.  I need to be able to take the
> keys and use them both as variable names like $lastname as well as
> convert them to strings like "lastname" for printing out.

Well, you are on the right track.  There are many ways to realize this
approach.  I'll sketch one, pretending we have only to deal with a last
name, a first name and a prof story to keep it short.

So what do we need to check the validity of an entry?  We want the
actual entry, the maximal length, and some sort of text that identifies
the entry to the user (for the message).  Note that the variable name
is not required.

We shall set these up in a pair of hashes %values (the entries) and
%lengths (the maximal length for each entry).  The keys of the hashes
will be the labels we assign to each variable.  Because we want to
process them in a given sequence, we want them in an array:

    my @labels = ( 'last name', 'first name', 'prof story');
    my ( %values, %lengths);
    @lengths{ @labels} = ( 30, 20, 256, 20);
    @values{ @labels} = ( $firstname, $lastname, $profStory);

Now we can define the routine validateLengths (which I would prefer
to call validate_length) in terms of (references) to the array of
labels and the two hashes:

    sub validateLengths {
        my ( $labels, $values, $lengths) = @_;
        my @too_long;
        for ( @$labels ) {
            push @too_long, $_ if length( $values->{ $_}) > $lengths->{ $_};
        }
        print "You fool!\n" if @too_long;
        for ( @too_long ) {
            print "You can only have $lengths->{ $_} characters in your $_.\n";
        }
    }

You may want to restore common politeness and I didn't bother with
the HTML, but you get the idea.

Once you're here, you may consider doing away with the individual
scalar variables and keep the values in a hash from the start.  In
that case, it could be preferable to use short compact strings for
keys, like the original variable names.  The labels would then be
kept in another hash.  Even if it's too late for this program, keep
"parallel hashes" in mind when you next encounter similarly structured
data.

Anno


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

Date: Fri, 18 May 2001 15:22:47 +0200
From: Koos Pol <koos_pol@nl.compuware.com.NOJUNKMAIL>
Subject: Re: Hash: keys to variable names, or variable names to keys?
Message-Id: <9e37n7$eho@news.nl.compuware.com>

Paul Johnson wrote:

> I wrote a CGI script that processes a bunch of string variables and saves
> them into a dataset.  I find my self doing the same repetitive, stupid
> things, one variable after another.  I wonder why can't I find a way to
> make a hash of variable names and then just iterate over the hash?
> 
> [big snip]


How about something like:
@list_of_checks (
  {
    criterium => '$lastnameLength > 30',
    message   => "Your entry for last name is too long. ".
                 "We allowed 30 characters, but your name took ".
                 "$lastnameLength. Sorry, can you give us something ".
                 "shorter";
  },
  {
    criterium => '$middleLength > 20' ,
    message   => "Your middle name entry is too long. " .
                 "We allowed 20 characters, but your input took " .
                 "$middleLength. Sorry, can you find an alias or ".
                 "abbreviate somehow?"
  }
)
foreach $testrun (@list_of_checks) {
   print $testrun->{message} if (eval $testrun->{criterium});
}


I am positive this code does not run as written here. But I hope I 
demonstrated how you can keep the data and logic seperated.

HTH

-- 
Koos Pol - Systems Administrator - Compuware Europe B.V. - Amsterdam
koos_pol@nl.compuware.com_NO_JUNK_MAIL



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

Date: Fri, 18 May 2001 13:02:30 +0200
From: "Real" <real@earthling.net>
Subject: Importing variables
Message-Id: <9e2vg9$pvk$1@news.surfnet.nl>

Hay all,

I've got a problem using variables globally. This whole scope-thing is just
not clear to me. I'll explain;

There's a "main" program and a library that is "required" in this program. I
want to define a global array which routines in both scripts can use. The
main program fill the array with values. When the main program calls a
routine from the library, this routine also accesses this array.  Both
script have a "use strict" line and perl-warnings are on (perl -w).

I thought I could reference the array using;
   *Global_Array = \@MainProgram::Global_Array;

 ... if I also define this main program as a package using;
   package MainProgram;
   my(@Global_Array);
   main
   {
      .... rest of the program
   }

But it doesn't work and now I'm a kind confused ;)  I have tried all kinds
of possibillities using Exporter, funny "import" routines found in Google,
etc, but the number of error-messages just seem to grow with every
"improvement".

Thanks,
Real





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

Date: Fri, 18 May 2001 11:15:55 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Importing variables
Message-Id: <e31agtk8erofe4qap34v93ehu7qrvt35nf@4ax.com>

Real wrote:

>There's a "main" program and a library that is "required" in this program. I
>want to define a global array which routines in both scripts can use. The
>main program fill the array with values. When the main program calls a
>routine from the library, this routine also accesses this array. 
>
>I thought I could reference the array using;
>   *Global_Array = \@MainProgram::Global_Array;

>... if I also define this main program as a package using;
>   package MainProgram;
>   my(@Global_Array);

Drop the "my".

Jeezes, strict is doing more harm than good again. 

	use vars '@Global_Array';

is ok.

-- 
	Bart.


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

Date: Fri, 18 May 2001 13:50:26 +0200
From: "Real" <real@earthling.net>
Subject: Re: Importing variables
Message-Id: <9e32a4$rck$1@news.surfnet.nl>

"Bart Lateur" <bart.lateur@skynet.be> wrote in message
news:e31agtk8erofe4qap34v93ehu7qrvt35nf@4ax.com...
> >There's a "main" program and a library that is "required" in this
program. I
> >want to define a global array which routines in both scripts can use. The
> >main program fill the array with values. When the main program calls a
> >routine from the library, this routine also accesses this array.
> >
> >I thought I could reference the array using;
> >   *Global_Array = \@MainProgram::Global_Array;
>
> >... if I also define this main program as a package using;
> >   package MainProgram;
> >   my(@Global_Array);
>
> Drop the "my".
>
> Jeezes, strict is doing more harm than good again.
>
> use vars '@Global_Array';
>
> is ok.

Yes, this works !  Thanks a lot. The trick is in the "use vars
'@Global_Array';" line. I'll include a minimal-version of both scripts for
future Google-searchers :)

Cheers,
Real


--------- Main program "main.pl" ----------
#!/usr/bin/perl -w

package MainPrg;

use strict;

require "sub.pr";

use vars '@Global_Array';

   print "Main program\n";
   push(@Global_Array, 'First');
   push(@Global_Array, 'Second');
   push(@Global_Array, 'Last');

&SubFunc;

   print "Back in main again ...\n";
   foreach (@Global_Array) { print "-  $_\n"; }


--------- Library "sub.pr" ----------

sub SubFunc
{
   # Display the current contents and add a new element
   print "This is SubFunc\n";

   *GA = \@MainPrg::Global_Array;

   foreach (@GA) { print "GLOBAL: $_\n"; }

   push(@GA, 'Extra');

   return;
}

1;





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

Date: Fri, 18 May 2001 11:56:11 +0100
From: "Andrew" <andrew@mvt.ie>
Subject: Looking for a console based file selection module
Message-Id: <9e304t$bc3$1@kermit.esat.net>

Hi,

I'm trying to find a module which will give a console based file selector /
directory browser.  I've checked on CPAN, and found Tk based solutions
(FileDialog, for example), but I'm looking for a console based equivalent of
the functionality it offers.

Ideally this module would be called with a start directory and file
extension filter, and would then return the selected filename.

Does anyone know if such a module exists?

Thanks,

Andrew




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

Date: Fri, 18 May 2001 14:02:33 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: module for umlauts
Message-Id: <3B051D69.64B4CFD9@schaffhausen.de>

Rafael Garcia-Suarez schrieb:
> What's the problem with HTML::Entities ?

None, fits perfectly. Guess I dint find it because its conteined in
HTML::Parser and
not listed by itself in the CPAN search.

Thank You,
->malte


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

Date: Fri, 18 May 2001 11:38:28 GMT
From: AvA <a.v.a@home.nl>
Subject: Re: Random Numbers Script
Message-Id: <3B04E1CD.1EC85ACE@home.nl>

Craig Berry wrote:

> Easier, faster, and better distributed:
>
>   $id = 10_000 + int rand 90_000

Nice coding Craig.
Could you point me to the documentation where from you learned that?



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

Date: Fri, 18 May 2001 10:46:24 -0400
From: "Sam Lay" <sam.lay@mindspring.com>
Subject: Templates for Generating Calls to External Functions
Message-Id: <9e3cna$765$1@slb4.atl.mindspring.net>
Keywords: grammer; parsers; templates

I'm trying to create a Perl/Tk GUI for generating calls to external
functions.  The function calls simply
define "rules" for testing an external data object, so the actual code
generation is simple except for
the templates for hte external functions.

I have several functions that take quite a varied set of arguments and
return different types of results.  Some of the functions take different
2nd, 3rd args based on the 1st arg; 3rd, 4th based on 2nd, etc.
Of course, the returned values and types also depend on the argument lists.
Hence, the generation of
arguments follows a decision tree of sorts.

Are you aware of a module that would support the expression of the "grammer"
for such calls and
the creation of a decision tree to support the synthesis of suitable call
sequences.  I can handle the
Tk part having played with that a bit.  It is the creation of the data
structure to serve as a template
for the function calls that has me stumped.  Alas, I have no experience in
implementing parsers or
compilers and I shudder at the thought of having to write different
functions to support each of the
many forms that the external functions follow.

Thanks, Sam




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

Date: Fri, 18 May 2001 16:51:47 +0100
From: "Sgluarb" <ommadawn@club-internet.fr>
Subject: Zlib on Win32
Message-Id: <9e3ctk$k11$1@reader1.imaginet.fr>

Hi,

Did somebody alreaday used zlib on Win32 ?

I've downloaded
Compress-Zlib-1.12.tar.gz

I think I need Zip Info and I binary version of Zlib (??)...

If somebody can give me a sample script zipping a file or another lib to do
it that would be great...

(I don't want to use a command line to PKzip cause i must do more complex
thing that i can't do with a single command line)

Thanx







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

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


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