[16268] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3680 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 15 21:10:22 2000

Date: Sat, 15 Jul 2000 18: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: <963709812-v9-i3680@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 15 Jul 2000     Volume: 9 Number: 3680

Today's topics:
    Re: Trying to use an array as a hash value <fedya@banet.net>
    Re: Trying to use an array as a hash value (Tad McClellan)
    Re: Upper-to-lower case problem <bart.lateur@skynet.be>
    Re: Upper-to-lower case problem (Tad McClellan)
    Re: Upper-to-lower case problem (jason)
        Webmail fgont@my-deja.com
        write to 2 dbm files simultaneously? <milosk@flashcom.net>
    Re: write to 2 dbm files simultaneously? <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sat, 15 Jul 2000 15:01:07 -0400
From: Ted <fedya@banet.net>
Subject: Re: Trying to use an array as a hash value
Message-Id: <3970B4F3.D28E73F2@banet.net>



Keith Calvert Ivey wrote:

> doglovers@rocketmail.com wrote:
>
> >$arrayref = \(a,b,c,d), then you put the reference into the the hash:
>
> You need to reread the documentation on references.  The \
> distributes over the list, so you get a list of scalar
> references, not an array reference.  To use \ here you would
> need to assign to an array variable first.
>
>    @array = qw( a b c d );
>    $arrayref = \@array;
>
> >Message => $arrayref,
> >
> >which you then dereference with @$arrayref when
> >you need it. Or you can put in an anonymous array with:
> >
> >Message => [a,b,c,d]
>
> That's the better way to do it.

I think I'm having the same exact problem.  My site is going to have a
bunch of information on players' records on the WTA Tour, and I'm using
arrays to store that information for individual players (so that I can
access a player's stats for the page that will have her matches listed).
However, I'd also like to use the information to create an alpahbetical
ranking table.  Right now, I've got arrays like the following:

@abe =( 133 , "Abe Julia"  , 2303.1 , 11 , -13 , 2336.6 , 0.5 , 2309.3 );
@abram =( 466 , "Abram Agnieszka"  , 1814.3 , 1 , -2 , 2127.5 , 6 , 2039.1
);
[...]
@auer =( 382 , "Auer Bettina"  , 1919.5 , 0 , -1 , 2318.6 , 0 , 1919.5 );
@augustus =( 362 , "Augustus Amanda" , 1938.2 , 0 , -1 , 2337.3 , 0 ,
1938.2 );

and I was going to try to create the following hash so that I could have a
loop of some sort (probably something using an if statement to stop once
an undefined value is reached since the exact number of players changes
slightly from week to week and I want to make certain the players remain
in alphabetical order) print out each scalar in each array in a separate
<td>:

%alphabetical=( 1 => @abe ,
 2 => @abram ,
 [...]
 30 => @auer ,
 31 => @augustus );

From what I've read in this thread, what I've just tried clearly isn't
going to work, and that I have to reference the array names somehow.  I've
read perlref, but that only serves to confuse me even more.  (Personal
observation -- all those documents at the Perl.com site like perldoc,
perlref, perlfaq, and so on are IMHO rather overcomplicated and not very
well organized for someone like me who's trying to learn Perl.)

Should I just be creating an anonymous hash on the order of

$alphabetical={ 1 => @abe ,
 2 => @abram ,
 [...]
 30 => @auer ,
 31 => @augustus };

and then come up with some subroutine to get the appropriate array that
goes with each number?  I'm not even certain how to get the values out of
the arrays if I create an anonymous hash.  If I were to create a loop like
the following:

while (1) {
$i=1;
if $i then print "<tr>";
for ($x=0; $x <= 7; $x++) {
print "<td>${$alphabetical}[$i][$x]<\/td>"
};
print "<\/tr>";
$i++;
else print "<\/table>";
};

would that print out at the very least the values in @abe ?  I know that
the for loop with $x probably ought to be in a subroutine to make things
clearer.  (BTW: I already have the part of the document with the
print "Content-type:text/html\n\n";
and the start of the table encoded.)  Apologies if I'm supposed to be
escaping the < and > with a \ as well.


--Ted                 I have always challenged the "psychoses." Why don't
fedya@banet.net       you have a right to say you are Jesus? And why isn't

                      the proper response to that congratulations?
                      Thomas Szasz, "Reason" Magazine, July 2000




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

Date: Sat, 15 Jul 2000 16:02:30 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Trying to use an array as a hash value
Message-Id: <slrn8n1gqm.h8q.tadmc@magna.metronet.com>

On Sat, 15 Jul 2000 15:01:07 -0400, Ted <fedya@banet.net> wrote:
>
>Keith Calvert Ivey wrote:
>
>> doglovers@rocketmail.com wrote:
>>
>> >$arrayref = \(a,b,c,d), then you put the reference into the the hash:
>>
>> You need to reread the documentation on references.  The \
>> distributes over the list,

>>    $arrayref = \@array;
                  ^
                  ^

There is an example of how to take a reference to a named array.


>I think I'm having the same exact problem.

>Right now, I've got arrays like the following:
>
>@abe =( 133 , "Abe Julia"  , 2303.1 , 11 , -13 , 2336.6 , 0.5 , 2309.3 );
>@abram =( 466 , "Abram Agnieszka"  , 1814.3 , 1 , -2 , 2127.5 , 6 , 2039.1
>);

>and I was going to try to create the following hash

>I want to make certain the players remain
>in alphabetical order) 


Sorting is easy in Perl.

Sort them alphabetically when you need them sorted alphabetically.


>%alphabetical=( 1 => @abe ,


> 2 => @abram ,
> [...]
> 30 => @auer ,
> 31 => @augustus );
>
>From what I've read in this thread, what I've just tried clearly isn't
>going to work, and that I have to reference the array names somehow.  
                                                             ^^^^^^^
                                                             ^^^^^^^

As shown above.


>I've
>read perlref, but that only serves to confuse me even more.  


You should read a "tutorial" before you read a "reference".


   perldoc perlreftut


>(Personal
>observation -- all those documents at the Perl.com site like perldoc,
>perlref, perlfaq, and so on are IMHO rather overcomplicated and not very
>well organized for someone like me who's trying to learn Perl.)


They are not _designed_ for someone trying to learn Perl, so 
that shouldn't be too surprising.

They are nearly all reference documentation.

If you need tutorial information (other than the 4 perl.*tut.pod files),
you need to look elsewhere.

A good book for Programmers wanting to learn Perl is

   "Learning Perl"

A good book for non-programmers wanting to learn programming
(and Perl) is:

   "Elements of Programming with Perl"


>Should I just be creating an anonymous hash on the order of


There is no need for anonymity, you can name your hash if you like.

There is no need for the numerical keys.

There is even no need for the named arrays...


>and then come up with some subroutine to get the appropriate array that
>goes with each number?  I'm not even certain how to get the values out of
>the arrays if I create an anonymous hash.  If I were to create a loop like
>the following:
>
>while (1) {
>$i=1;
>if $i then print "<tr>";


syntax error.


   print '<tr>' if $i;

But since $i is set true on the line right before this,
it is pointless to test its truth anyway, so you might as well:

   print '<tr>';


>for ($x=0; $x <= 7; $x++) {


Whenever you find yourself explicitly indexing an array, you
should pause for a moment to make sure that you are not
writing C (where you have to manage the indexing yourself)
in Perl (where you can use Perl's list functions and have
Perl do the indexing for you).


>print "<td>${$alphabetical}[$i][$x]<\/td>"
>};
>print "<\/tr>";
         ^
         ^ useless character
>$i++;
>else print "<\/table>";
              ^
              ^ useless character
>};


That code is formatted too horribly to be looked upon.

Format your code sensibly if you expect people to read it.


>would that print out at the very least the values in @abe ?

No. It won't do much of anything if it cannot compile.



>Apologies if I'm supposed to be
>escaping the < and > with a \ as well.


Eh?

You only need to escape characters that have a special meaning.

< and > do not have any special meaning in a string, so it
would be *bad* if you did escape them.

It is bad that you have escaped the slash, which is also not
special in a string.

It is bad that you have used a double quoted string where
a single quoted string will do.



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

# make a HoL
my %players = (
   abram => [466 , "Abram Agnieszka"  , 1814.3 , 1 , -2 , 2127.5 , 6 , 2039.1],
   abe => [133 , "Abe Julia"  , 2303.1 , 11 , -13 , 2336.6 , 0.5 , 2309.3],
);

# show them in alphabetical order
foreach my $player ( sort keys %players ) {
   foreach my $index ( 0 .. $#{$players{$player}} ) {
      print "$index: $players{$player}[$index]\n";
   }
   print "-----------\n";
}
 ------------------------------


-- 
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Sat, 15 Jul 2000 23:40:55 +0200
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Upper-to-lower case problem
Message-Id: <tbd1nsk9c5caf6p2bpo7ddjab3kd9lejef@4ax.com>

Alan Page wrote:

>When you say Perl5 does that mean Perl 5.xxx or 5.005? Does 5.6 really mean
>5.006? I think I have 5.004 based on my shebang of  #!/usr/bin/perl54. I have a
>note out to my ISP to find out what I've really got access to.

Try "perl -v" at the command line (telnet), or print out $] in a CGI
script. And yes, 5.6 is actually 5.006.

lc() exists from the very first incarnation of Perl 5, i.e. 5.000, as
does, for example, chr(), and references.

-- 
	Bart.


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

Date: Sat, 15 Jul 2000 16:10:33 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Upper-to-lower case problem
Message-Id: <slrn8n1h9p.h8q.tadmc@magna.metronet.com>

On 15 Jul 2000 14:58:21 GMT, Alan Page <alandpage@aol.comnospam> wrote:
>>Indeed . Much neater. Requires Perl5, though. The only Perl that
>>matters, nowadays.
>>
>>p.s. Very often I have to fix broken scripts, so that they run under
>>5.004. Amazingly how much that has been added in 5.005 -- and in 5.6;
>>although I don't think I've yet used any new features of that.
>
>Bart,
>
>When you say Perl5 does that mean Perl 5.xxx or 5.005? 


It means 5.xxx in that context (I think. You have snipped the
context! I think he was talking about the lc() function?).



>Does 5.6 really mean
>5.006? 


No, because there is no perl 5.006.

The p5p have changed how they number Perl versions.

   5.004
   5.005
   5.6
   5.6.1 (eventually)
   ...


So 5.6 is the "real" version number.


>I think I have 5.004 based on my shebang of  #!/usr/bin/perl54. I have a
>note out to my ISP to find out what I've really got access to.


Ask perl what version it is:

   /usr/bin/perl54 -V

or, if it is a pretty old version (where there is no -V):

   /usr/bin/perl54 -v


-- 
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Sat, 15 Jul 2000 23:59:20 GMT
From: elephant@squirrelgroup.com (jason)
Subject: Re: Upper-to-lower case problem
Message-Id: <MPG.13db98239b3b48e99896c1@news>

Tad McClellan wrote ..
>On 15 Jul 2000 14:58:21 GMT, Alan Page <alandpage@aol.comnospam> wrote:
>>I think I have 5.004 based on my shebang of  #!/usr/bin/perl54. I have a
>>note out to my ISP to find out what I've really got access to.
>
>
>Ask perl what version it is:
>
>   /usr/bin/perl54 -V
>
>or, if it is a pretty old version (where there is no -V):
>
>   /usr/bin/perl54 -v

Alan has no telnet access Tad .. he'll want something more like

  #!/usr/bin/perl54
  print "Content-type: text/html\n\nVersion: $]\n";
  __END__

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


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

Date: Sat, 15 Jul 2000 18:31:34 GMT
From: fgont@my-deja.com
Subject: Webmail
Message-Id: <8kqam6$i7m$1@nnrp1.deja.com>

Hi!

I'm programming a webmail client.
It's a CGI script that connects to a POP3 server, so that it can get
the messages and show them on the web.

Even though I can login to the server get the messages, and logout,
some problems araise:

For example, I know that I should include username and password
information in the HTML code (so that when a user clicks on a message
to get it, the HTML form passes the username, password and message
number to the CGI).

But I don't know which way would be the best to include that data.
There's no problem with the message number and the username (I could
include them as "HIDDEN")...
But... how about the password? It should be encrypted in some way that
if someone looks at the "cache" of the web browser, he cannot decode it.
Got the picture?

Besides that, I've come with another problem:
I'd need something to split and decode the files that are MIME-encoded
in the body of the messages, so that I could show them on the web. What
would be the best module for it?

Kind Regards,
Fernando Ariel Gont

fgont@SPAMSUCKS.softhome.net

[Remove SPAMSUCKS if you want to send a personal reply]



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


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

Date: Sat, 15 Jul 2000 14:47:12 -0700
From: lounge lizard <milosk@flashcom.net>
Subject: write to 2 dbm files simultaneously?
Message-Id: <3970DBE0.1267256B@flashcom.net>

Can I write to 2 open dbm files at the same time or do I have to close
one first - relevant code is:

 dbmopen (%DATA, $keyIDfile, 0666) || die "can't open file\n";
 dbmopen (%MAIN, $keyMainfile, 0666) || die "can't open file\n";
        $DATA{$i} = $member_array[3];
        $MAIN{$member_array[3]} = $newline;
 dbmclose (%MAIN);
 dbmclose (%DATA);

I'm getting that I have no write permissoin  for MAIN - DATA was created
by this program MAIN by another of my programs that I have had no
trouble writing to before - anyone help?  Thanks



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

Date: Sun, 16 Jul 2000 00:53:33 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: write to 2 dbm files simultaneously?
Message-Id: <397107CB.267DD4B@rochester.rr.com>

lounge lizard wrote:
> 
> Can I write to 2 open dbm files at the same time or do I have to close
> one first - relevant code is:
> 
>  dbmopen (%DATA, $keyIDfile, 0666) || die "can't open file\n";
>  dbmopen (%MAIN, $keyMainfile, 0666) || die "can't open file\n";
>         $DATA{$i} = $member_array[3];
>         $MAIN{$member_array[3]} = $newline;
>  dbmclose (%MAIN);
>  dbmclose (%DATA);
> 
> I'm getting that I have no write permissoin  for MAIN - DATA was created
> by this program MAIN by another of my programs that I have had no
> trouble writing to before - anyone help?  Thanks

You should have no trouble writing to two or more DBM-type files
simultaneously as long as you are not using either DBM or NDBM (I am
running a program with 11 simultaneous dbmopen's open for write as I
type this).  You need to be sure your system supports whatever DBM-type
(like DBM, NDBM, GDMB, SDMB, DB_File, etc) your dbmopen uses.  Note that
if you use Windoze with a FAT or FAT32 file system, SDBM won't work (it
will seem like it does, but it will drop a significant fraction of the
keys as the file size gets larger than trivial).  Note that SDBM was the
default type used by most Windoze versions of Perl prior to Perl version
5.6 (it looks like the default is now DB_File, which will work with
FAT/FAT32 filesystems).  Question:  was the "main" data file written
using the same DBM-type?  If it was on another computer, maybe it
wasn't.  Also, there may be a possibility the implementation of a given
DBM-type may differ between different operating systems, so it may be
that a file written on one system might not be usable on a different
system.
-- 
Bob Walton


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

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


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