[19061] in Perl-Users-Digest
Perl-Users Digest, Issue: 1256 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 6 14:06:18 2001
Date: Fri, 6 Jul 2001 11:05:11 -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: <994442711-v10-i1256@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 6 Jul 2001 Volume: 10 Number: 1256
Today's topics:
Re: calling a PERL script from Matlab (Steve Miller)
dimensional arrays = ? in Perl <lmoran@wtsg.com>
Re: dimensional arrays = ? in Perl (Rasputin)
Re: dimensional arrays = ? in Perl <andras@mortgagestats.com>
Re: dimensional arrays = ? in Perl <ren@tivoli.com>
Re: dimensional arrays = ? in Perl <mjcarman@home.com>
Re: dimensional arrays = ? in Perl <lmoran@wtsg.com>
Re: dimensional arrays = ? in Perl (Tad McClellan)
Re: dimensional arrays = ? in Perl <pne-news-20010706@newton.digitalspace.net>
Re: Floating point accuracy? Is this a bug? <pne-news-20010706@newton.digitalspace.net>
Help Please FASTCGI and CGILIB.PL (bubba)
Re: how do you move a created file (Smiley)
Re: how do you move a created file <shop@wehug.com>
Re: How to delete consecutive blank lines <pne-news-20010706@newton.digitalspace.net>
Re: IF statement madness <koos_pol@nl.compuware.com.NOJUNKMAIL>
Re: IF statement madness <mjcarman@home.com>
Re: IF statement madness <andras@mortgagestats.com>
Re: IF statement madness <Graham.T.Wood@oracle.com>
Re: login script with cgi? <andras@mortgagestats.com>
ODBC calls no working <ben@bensommer.com>
ODBC commands don't work <ben@bensommer.com>
Parsing an html document for the title (don't flame, I (dave)
Re: Parsing an html document for the title (don't flame <comdog@panix.com>
Perl & Outlook/Exchange <sg@loralskynet.com>
Placing a variable's contents into an array <epanagio@frontiernet.net>
Re: Q: Global variables <ren@tivoli.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 6 Jul 2001 09:39:31 -0700
From: steveaux@my-deja.com (Steve Miller)
Subject: Re: calling a PERL script from Matlab
Message-Id: <12db7b5d.0107060839.2771a2f9@posting.google.com>
Resolution:
1. Once I downloaded Perl, I was able to shell out from Matlab and use
split.pl.
2. I tried shelling out to use Cygwin, but to no avail.
Thanks for the help. That solves a future computing bottleneck we were
going to have in the lab.
Steve
------------------------------
Date: Fri, 06 Jul 2001 09:41:53 -0400
From: Lou Moran <lmoran@wtsg.com>
Subject: dimensional arrays = ? in Perl
Message-Id: <rrfbktcgfraja6s939ndjgv3g7odutdelv@4ax.com>
--As I trudge on on other languages I feel like it would be nice to be
able to relate things to something I am comfortable with.
--Seems like:
1D array = array in Perl
2D array = hash in Perl
3D array = ? in Perl
any insight would be useful, especially other correlations.
------------------------------
Date: Fri, 06 Jul 2001 14:05:31 GMT
From: rasputin@shaft.techsupport.co.uk (Rasputin)
Subject: Re: dimensional arrays = ? in Perl
Message-Id: <slrn9kbhf5.ahr.rasputin@shaft.techsupport.co.uk>
In article <rrfbktcgfraja6s939ndjgv3g7odutdelv@4ax.com>, Lou Moran wrote:
> --As I trudge on on other languages I feel like it would be nice to be
> able to relate things to something I am comfortable with.
>
> --Seems like:
>
> 1D array = array in Perl
> 2D array = hash in Perl
> 3D array = ? in Perl
>
> any insight would be useful, especially other correlations.
Naah, I think you'd be better off thinking of 'lists of lists'
as multidimensional arrays. perldoc perllol, maybe?
--
"These are the propulsion systems used by NASA for the moonshots,"
said Tom apologetically.
Rasputin :: Jack of All Trades - Master of Nuns ::
------------------------------
Date: Fri, 06 Jul 2001 10:17:53 -0400
From: Andras Malatinszky <andras@mortgagestats.com>
Subject: Re: dimensional arrays = ? in Perl
Message-Id: <3B45C891.AFE70B69@mortgagestats.com>
Lou Moran wrote:
> --As I trudge on on other languages I feel like it would be nice to be
> able to relate things to something I am comfortable with.
>
> --Seems like:
>
> 1D array = array in Perl
> 2D array = hash in Perl
No, hashes are not two-dimensional arrays. If you want to think about them
as arrays, think about them as 1D arrays where the indices are words, not
numbers.
>
> 3D array = ? in Perl
>
> any insight would be useful, especially other correlations.
You can work with multidimensional arrays in Perl. Just say
$matrix[3][5]=9; when you want to set column 5 of row 3 of the array
@matrix to the value of 9.
------------------------------
Date: 06 Jul 2001 08:45:55 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: dimensional arrays = ? in Perl
Message-Id: <m37kxmmar0.fsf@dhcp9-173.support.tivoli.com>
On Fri, 06 Jul 2001, lmoran@wtsg.com wrote:
> --As I trudge on on other languages I feel like it would be nice to
> be able to relate things to something I am comfortable with.
>
> --Seems like:
>
> 1D array = array in Perl
Yes.
> 2D array = hash in Perl
No.
2D array = array of array refs (aka LoLs, see perllol(1))
> 3D array = ? in Perl
... array of refs to arrays of array refs
> any insight would be useful, especially other correlations.
Have a read of:
perlref(1)
perllol(1)
perldsc(1)
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Fri, 06 Jul 2001 09:16:17 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: dimensional arrays = ? in Perl
Message-Id: <3B45C831.17BA6B01@home.com>
Lou Moran wrote:
>
> As I trudge on on other languages I feel like it would be nice to
> be able to relate things to something I am comfortable with.
>
> Seems like:
>
> 1D array = array in Perl
Yep -- well, for the simple case anyway. Perl hackers distinguish
between arrays and lists, as well as between named arrays and anonymous
ones.
> 2D array = hash in Perl
Nope. Hashes and arrays are different beasts. In the old days, we used
to call hashes "associative arrays" but that nomenclature has changed.
There is certainly nothing 2D about them. They are sets of key/value
pairs.
A 2D array, in Perl, is referred to as a LoL (list of lists). This is a
reflection on how they are implemented. Perl doesn't have true
multidimensional arrays. To emulate a 2D array in Perl, you must
actually create an array of array references. While this may sound like
a shortcoming at first, it's actually very powerful, because it lets you
create arbitrarily complex data structures, including mixtures of arrays
and hashes.
> 3D array = ? in Perl
LoLoL (etc., etc., ad naseum)
-mjc
------------------------------
Date: Fri, 06 Jul 2001 11:33:33 -0400
From: Lou Moran <lmoran@wtsg.com>
Subject: Re: dimensional arrays = ? in Perl
Message-Id: <6gmbktknksnq52q2k7erh7p9oiq2ue6alo@4ax.com>
On Fri, 06 Jul 2001 09:16:17 -0500, Michael Carman <mjcarman@home.com>
wrote wonderful things about sparkplugs:
>
>A 2D array, in Perl, is referred to as a LoL (list of lists).
>
>-mjc
I am so ashamed. Until you pointed out that LoL meant lists of lists
I thought everyone was laughing at me...
------------------------------
Date: Fri, 6 Jul 2001 11:16:04 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: dimensional arrays = ? in Perl
Message-Id: <slrn9kblhk.k6v.tadmc@tadmc26.august.net>
Lou Moran <lmoran@wtsg.com> wrote:
>--As I trudge on on other languages I feel like it would be nice to be
>able to relate things to something I am comfortable with.
>
>--Seems like:
>
>1D array = array in Perl
Right.
>2D array = hash in Perl
Not really. A hash is a whole different animal.
2D array = array of references to arrays in Perl.
( but they look like "arrays of arrays" with some syntactic sugar:
$foo[2][5]; # same as $foo[2]->[5]
)
>3D array = ? in Perl
3D array = array of references to arrays of references to arrays
in Perl. ( $foo[2][5][4] or $foo[2]->[5]->[4] )
>any insight would be useful,
Seek the insight already installed on your hard drive:
perldoc perlreftut
perldoc perlref
perldoc perllol
perldoc perldsc
>especially other correlations.
You can have multilevel data structures with hash "levels" in
addition to array "levels", as discussed in that last reference above.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 06 Jul 2001 19:11:22 +0200
From: Philip Newton <pne-news-20010706@newton.digitalspace.net>
Subject: Re: dimensional arrays = ? in Perl
Message-Id: <90sbkt0g6309ca3kc32hmcref3kg0ikq28@4ax.com>
On Fri, 06 Jul 2001 09:41:53 -0400, Lou Moran <lmoran@wtsg.com> wrote:
> --As I trudge on on other languages I feel like it would be nice to be
> able to relate things to something I am comfortable with.
>
> --Seems like:
>
> 1D array = array in Perl
Yup.
> 2D array = hash in Perl
Er, no. A hash is one-dimensional as well. (Or, if you want, both arrays
and hashes are two-dimensional but the second dimension is fixed to size
2.) For example, you can't map the following table:
* | 1 2 3
---+-------
1 | 1 2 3
2 | 2 4 6
3 | 3 6 9
, which is a two-dimensional array, into a hash in Perl. (At least, not
unless you join the row and column identifier together into one so you
can use it as a hash key.)
If you want a 2D array, use an array containing arrayrefs. 'perllol'
should talk about this (lol = list of lists).
> 3D array = ? in Perl
Array of refs to arrays containing refs to arrays.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Fri, 06 Jul 2001 19:11:22 +0200
From: Philip Newton <pne-news-20010706@newton.digitalspace.net>
Subject: Re: Floating point accuracy? Is this a bug?
Message-Id: <4srbkt0cj7ngj72mdus6d6kiu2jn4ur7kt@4ax.com>
On Fri, 6 Jul 2001 19:49:05 +1000, "Gregory Toomey" <gtoomey@usa.net>
wrote:
> The Perl interpreter may use 'constant folding' to expand 10**5 to 100000.
That is what I would expact. And it seems to be so:
C>perl -MO=Deparse -e "$value = $value * 10**5"
-e syntax OK
$value = $value * 100000;
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: 6 Jul 2001 10:24:36 -0700
From: mwerner@digitalmojo.com (bubba)
Subject: Help Please FASTCGI and CGILIB.PL
Message-Id: <d0f04db6.0107060924.69d40d0e@posting.google.com>
Hello:
I have read an re-read the documentation and scanned the digests and
am still
unable to find the answer to the following question.
ANY help would be appreciated as I am Quite Lost.
I have a dirt simple Perl CGI (below) which is basically taken
verbatim from the FastCGI
documentation
The only difference is that I try to use the standard cgi-lib.pl to
get data passed to the cgi.
This causes the error below in the /etc/httpd/conf/errors file:
ERROR
------------------
Server built: Mar 29 2001 12:52:37
[Fri Jul 6 06:13:15 2001] [warn] FastCGI: (dynamic) server
"/var/www/cgi-bin/myfast.fpl" started (pid 1315)
Can't locate object method "BINMODE" via package "FCGI::Stream" at
cgi-lib.pl line 67.
[Fri Jul 6 06:13:16 2001] [error] [client 10.10.1.69] FastCGI: server
"/var/www/cgi-bin/myfast.fpl" stderr: Can't locate object method
"BINMODE" via package "FCGI::Stream" at cgi-lib.pl line 67.
[Fri Jul 6 06:13:16 2001] [error] [client 10.10.1.69] (2)No such file
or directory: FastCGI: incomplete headers (0 bytes) received from
server "/var/www/cgi-bin/myfast.fpl"
[Fri Jul 6 06:13:16 2001] [warn] FastCGI: (dynamic) server
"/var/www/cgi-bin/myfast.fpl" (pid 1315) terminated by calling exit
with status '107'
PERL CODE
--------------------------
#!/usr/bin/perl
use FCGI; # Imports the library; required line
push (@INC,"/cgi-bin");
require("cgi-lib.pl");
# Initialization code
$cnt = 0;
# Response loop
while (FCGI::accept() >= 0) {
ReadParse(*input);
$var= $input{'VAR'};
print "Content-type: text/html\r\n\r\n";
print "<head>\n<title>FastCGI Demo Page (perl)</title>\n</head>\n";
print "<h1>FastCGI Demo Page (perl)</h1>\n";
print "This is coming from a FastCGI server.\n<BR>\n";
print "The Variable VAR is $var\n<BR>\n";
print "Running on <EM>$ENV{SERVER_NAME}</EM> to
<EM>$ENV{REMOTE_HOST}</EM>\n<BR>\n";
$cnt++;
print "This is connection number $cnt\n";
}
------------------------------
Date: Fri, 06 Jul 2001 17:44:30 GMT
From: gurm@intrasof.com (Smiley)
Subject: Re: how do you move a created file
Message-Id: <3b45f688.263928348@news1.on.sympatico.ca>
It could be a directory permission problem. You really should set it
to give you an error message if it's unable to create the directory -
instead of :
umask(000); # UNIX file permission junk
mkdir("$config{'megalist'}", 0777) unless (-d "$config{'megalist'}");
try something like this :
unless (-d "$config{'megalist'}")
{
umask(000); # UNIX file permission junk
mkdir("$config{'megalist'}", 0777) or &oops("Unable to create
directory $config{'megalist'}");
}
That won't solve your problems, but it will conveniently tell you that
the problem hasn't been solved yet ;). What are the permissions on
your directory set to? Try 777.
Tell me how it goes :)
On Fri, 06 Jul 2001 13:01:29 GMT, Crystal Ball <shop@wehug.com> wrote:
>Thanks for trying Smiley,
>I have already tried
>######sub variable for megalist
>$config{'megalist'} = '/usr/www/users/nuspirit/megalist/';
>and
>######sub variable for megalist
>$config{'megalist'} = '/usr/www/users/nuspirit/public_html/megalist/';
>I do not get any errors the script runs through, but no directory
>megalist and no file mega.htm
>it just wont write these to my public html area only will create
>them if I point to the cgi-bin area like so:
>######sub variable for megalist
>$config{'megalist'} = '/usr/www/users/nuspirit/cgi-bin/megalist/';
>
>I still appreciate your help, thanks again, I know there is
>a solution, I'll keep trying.
>Mike
>
------------------------------
Date: Fri, 06 Jul 2001 10:34:06 -0500
From: "The Crystal Ball Inc." <shop@wehug.com>
Subject: Re: how do you move a created file
Message-Id: <3B45DA6E.82F99F97@wehug.com>
Thanks for all the help. This is a very nice group!
Smiley,
SUCCESS!!!!!!!!!!
thank you , I think it was the permissions on the public_html dir
that did the trick, because I had tried the path you said before
with no luck. Thanks a bunch.
Let me know when you get your auction up and running I'll
give it a link from my links page.
Best Wishes,
Mike
"The Crystal Ball Inc." wrote:
>
> Hello all,
> Need some help,
>
> I'm getting 403 errors and must resolve.
>
> I'm using a cgi/perl script that creates a file called
> mega.htm and puts that file in my cgi-bin area. When I
> try to look at that file by typing the url in my browser,
> it gives me a 403 permissions error.
>
> The file is given 666 level permissions by the script,
> which seems adequate but still returns a 403 error.
>
> My problem is that the file called mega.htm must be accessed
> and read by a spider from an outside website.
>
> There is a peculiar thing , I do not see the directory named
> megalist but I do see the file mega.htm in my cgi-bin
> area.
>
> I can physically download and then upload this file to my
> public html area and then can look at it with my browser.
>
> So what is the best way to fix this, create another few lines
> of perl code that can move this file to my public html area ?
>
> Apparently there is a block in the cgi-bin area that wont
> allow a browser see files located there by a browser.
>
> here is the sub that creates the file:
>
> ###################################
> ### Sub: BidFind List
> ### Prints out a very "basic" HTML page for BidFind to use to
> ### index your web site auction contents.
>
> sub megalist {
> umask(000); # UNIX file permission junk
> mkdir("$config{'megalist'}", 0777) unless (-d "$config{'megalist'}");
>
> open (MEGAFILE, ">$config{'megalist'}/mega.htm");
> print MEGAFILE
> "<HTML>\n<HEAD>\n<TITLE>BidFind MegaList at
> $config{'sitename'}</TITLE>\n</HEAD>\n<BODY>\n";
> close (MEGAFILE);
>
> my $key;
> foreach $key (sort keys %category) {
> opendir (THEDIR, "$config{'basepath'}$key") || &oops("Category directory
> $key could not be opened.");
> readdir THEDIR;
> readdir THEDIR;
> my @allfiles = sort { $a <=> $b } readdir THEDIR;
> closedir THEDIR;
>
> my $file;
> foreach $file (sort { int($a) <=> int($b) } @allfiles) {
> if (-T "$config{'basepath'}$key/$file") {
> $file =~ s/^$config{'basepath'}$key\///;
> $file =~ s/\.dat$//;
> open THEFILE, "$config{'basepath'}$key/$file";
> my ($title, $reserve, $inc, $desc, $image, @bids) =
> &read_item_file($key,$file);
> close THEFILE;
> chomp($title, $reserve, $inc, $desc, $image, @bids);
> my ($alias, $email, $bid, $time, $add1, $add2, $add3) =
> &read_bid($bids[$#bids]);
> my ($selleralias, $selleremail, $sellerbid, $sellertime, $selleradd1,
> $selleradd2, $selleradd3) = &read_bid($bids[0]);
>
> my @closetime = localtime($file);
> $closetime[4]++;
>
> open (MEGAFILE, ">>$config{'megalist'}/mega.htm");
> print MEGAFILE
> "<A
> HREF=$config{'scripturl'}$ENV{'SCRIPT_NAME'}\?category=$key\&item=$file>$title</a>
> <PRICE>$bid<CAT>$category{$key}<ENDS>$closetime[4]/$closetime[3]<BR>\n";
> close (MEGAFILE);
> }
> }
> }
> open (MEGAFILE, ">>$config{'megalist'}/mega.htm");
> print MEGAFILE
> "</BODY>\n</HTML>\n";
> close (MEGAFILE);
> }
>
> the sub is called or executed by this
> &megalist;
> which is placed in another sub that creates a listing for something else.
>
> here is the variable:
> $config{'megalist'} = '/usr/www/users/nuspirit/cgi-bin/';
>
> there is an earlier line:
> local %config;
>
> also here is some stuff fron the top of the script:
> #!/usr/bin/perl
> use vars qw(%config %category %form);
> require "postal.pl"; #this calls a script that has to do with email and works
> fine.
> use strict;
> #####################
>
> Anyway there it is, would appreciate any suggestions and thanks in advance.
> I'm not a cgi or perl programmer, just trying to muddle my way through,
> I didn't write this sub or the main script. The script and the addon sub are
> for an auction program called everysoft auction. I tried to get some help
> from the EA auction forum, but it seems that no one is willing to reply.
>
> Mike
> mike@wehug.com
------------------------------
Date: Fri, 06 Jul 2001 19:11:21 +0200
From: Philip Newton <pne-news-20010706@newton.digitalspace.net>
Subject: Re: How to delete consecutive blank lines
Message-Id: <rmrbkt8hcfa2gjtbsutu91r0kg9v70sd0j@4ax.com>
On Thu, 5 Jul 2001 16:31:51 -0700, "Jim McTiernan"
<james.mctiernan@rcn.com> wrote:
> I have a text file with multiple blank lines before and after paragraphs.
> How can I get rid of them?
Read it in with $/ set to "" (paragraph mode) and $\ set to "\n\n",
chomp each record, and write it out again.
Since chomp removes multiple \n's when in paragraph mode, this will
normalise the spacing.
> How also to delete paragraphs that contain certain words, or would it be
> easier to save the paragraphs that contain only certain words.
If you're reading the file in paragraph mode, simply don't print out the
current record if it contains a certain word.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Fri, 6 Jul 2001 14:55:12 +0200
From: Koos Pol <koos_pol@nl.compuware.com.NOJUNKMAIL>
Subject: Re: IF statement madness
Message-Id: <9i4cfg$lma@news.nl.compuware.com>
Rik wrote:
> The code that I managed to get working is this:
>
> foreach $name (keys %cookies) {
> if ($cookies{$name} != "User")
> {
> print "\n$name = $cookies{$name}<br>";
> }
> }
>
> which to me seems completely weird... can anyone tell me where I'm
> going wrong here?
>
> Ta,
> Richard
This is good code. However it is possible that is doesn't do what you
*think* it does.
First display the complete hash to see if the information in the hash is
correct. Decide from there on where the problem is:
foreach $name (keys %cookies) {
print "key = [$name] value = [$cookies{$name}]\n";
}
BTW, I usually enter print statements for relevant vars when the true (or
false) clause has been entered to help debug IF problems.
--
Koos Pol - Systems Administrator - Compuware Europe B.V. - Amsterdam
koos_pol@nl.compuware.com_NO_JUNK_MAIL
------------------------------
Date: Fri, 06 Jul 2001 08:10:04 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: IF statement madness
Message-Id: <3B45B8AC.B2112D87@home.com>
Rik wrote:
>
> I'm trying to extract a single cookie element. I found some
> code for reading from cookies,
>
> foreach $name (keys %cookies) {
> print "\n$name = $cookies{$name}<br>";
> }
The only thing that code has to do with "cookies" is the name of the
hash. It just loops over the hash and prints out each name/value pair.
> so I thought to extract the single user item, I would have to iterate
> through.
No, to get a value out of a hash, you just ask for it with the key:
print "user is $cookies{user}\n";
> The code that I managed to get working is this:
>
> foreach $name (keys %cookies) {
> if ($cookies{$name} != "User")
^^
== and != are for comparing numbers.
eq and ne are for comparing strings.
> {
> print "\n$name = $cookies{$name}<br>";
> }
> }
Define "working." Why are you filtering out entries with a value of
"User"? Did you want to filter out that key instead? Or get just that
key? I don't have the foggiest idea what you're trying to accomplish
here...
> which to me seems completely weird...
Seems a little weird to me too. :)
> can anyone tell me where I'm going wrong here?
Not without knowing what it is that you're trying to accomplish.
-mjc
------------------------------
Date: Fri, 06 Jul 2001 10:09:02 -0400
From: Andras Malatinszky <andras@mortgagestats.com>
Subject: Re: IF statement madness
Message-Id: <3B45C67E.CDFFC16@mortgagestats.com>
Rik wrote:
> Hi all,
> I'm a complete novice when it comes to perl, so be easy with this
> dumb question!
>
> Basicaly, I'm trying to extract a single cookie element. I found some
> code for reading from cookies,
>
> foreach $name (keys %cookies) {
> print "\n$name = $cookies{$name}<br>";
> }
>
> so I thought to extract the single user item, I would have to iterate
> through. The code that I managed to get working is this:
>
> foreach $name (keys %cookies) {
> if ($cookies{$name} != "User")
> {
> print "\n$name = $cookies{$name}<br>";
> }
> }
>
> which to me seems completely weird... can anyone tell me where I'm
> going wrong here?
>
> Ta,
> Richard
I think your basic problem is that you are trying to modify code that you
don't understand. If you haven't yet, you should read the documentation of
the CGI module. One source to find it is
http://stein.cshl.org/WWW/software/CGI/cgi_docs.html. There is a section
devoted to cookies at
http://stein.cshl.org/WWW/software/CGI/cgi_docs.html#cookies.
Also, I'm not sure you understand how hashes work. You might want to pick
up a Perl book and read up on them. If your cookies are stored in a hash
called %cookies with the cookie names as keys and you want to refer to the
cookie named 'User' then just say $cookies{'User'}; no need to iterate
through all the cookies.
Finally, there is the if statement in your code:
if ($cookies{$name} != "User")
This will look at the %cookies hash, look for a key that is stored in the
variable $name, convert the corresponding value to a number (because you
are using the != comparison, which is for numbers) and then convert the
string "User" to a number and it will look to see if the two numbers are
equal. This is not what you want, is it?
------------------------------
Date: Fri, 06 Jul 2001 16:42:54 +0100
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: IF statement madness
Message-Id: <3B45DC7E.1A880722@oracle.com>
This is a multi-part message in MIME format.
--------------7EDCA52141876C0B7FB205C6
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Rik wrote:
> Hi all,
> I'm a complete novice when it comes to perl, so be easy with this
> dumb question!
>
> Basicaly, I'm trying to extract a single cookie element. I found some
> code for reading from cookies,
>
> foreach $name (keys %cookies) {
> print "\n$name = $cookies{$name}<br>";
> }
>
> so I thought to extract the single user item, I would have to iterate
> through. The code that I managed to get working is this:
>
> foreach $name (keys %cookies) {
> if ($cookies{$name} != "User")
> {
> print "\n$name = $cookies{$name}<br>";
> }
> }
>
> which to me seems completely weird... can anyone tell me where I'm
> going wrong here?
>
> Ta,
> Richard
When you say "working" what do you mean. I'm not sure I understand what
you are trying to do but here is a guess.
You have a hash called %cookies which contains the word "user" as a key
and you want to know the corresponding value in the hash.
To do this you don't need to iterate, you just access it via
$cookies{user} as in
print "$cookies{user}\n";
or
$user_cookie_value = $cookies{user};
That's one of the reasons for using a hash. You don't need to look at
them all to find the one you want if you know the key you're looking for.
The problem with your if statement may be that you are comparing the value
(of unknown type) in $cookies{$name} with the text "User" but you are
using the numeric operator != to test for its inequality. You need to use
ne to compare 2 text values or perl will evaluate your text "User", and
any other text value with no digits in it, as zero.
Graham Wood
--------------7EDCA52141876C0B7FB205C6
Content-Type: text/x-vcard; charset=UTF-8;
name="Graham.T.Wood.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Graham Wood
Content-Disposition: attachment;
filename="Graham.T.Wood.vcf"
begin:vcard
n:;Graham
x-mozilla-html:FALSE
adr:;;;;;;
version:2.1
email;internet:Graham.T.Wood@oracle.com
fn:Graham Wood
end:vcard
--------------7EDCA52141876C0B7FB205C6--
------------------------------
Date: Fri, 06 Jul 2001 10:31:30 -0400
From: Andras Malatinszky <andras@mortgagestats.com>
Subject: Re: login script with cgi?
Message-Id: <3B45CBC1.1CAFE206@mortgagestats.com>
Flipper wrote:
> G'day all
>
> I am making a website and I wish to quasi protect it.
> I have set up a popup window which appears over a bland normal window.
> On the popup is a form with 2 fields, username and password and I want
> to make it so when the correct combination is entered, the popup
> closes and the back window becomes a new page.
Isn't basic authentication with .htaccess/.htpassword available to you? It
would be a lot cleaner and simpler.
>
>
> NOT ultra secure and more for entertainment
> but HOW do I do this?
>
> I tried the perl\cgi turorial at http://www.cgi101.com/ and am still
> not very enlightened
>
> obviously I need an
> if($username == USERNAME)
> and ($password == PASSWORD)
Obviously not. The last thing you want to do is compare the username and
the password as numeric values because that will let in anybody who enters
a non-numeric password/username combination. You will want to use eq
instead of == here.
>
> then "the required actions"
>
> but what aer the "required actions?"
That's really a JavaScript question, isn't it?
>
>
> thanks in advance
>
> David
------------------------------
Date: Fri, 6 Jul 2001 11:57:09 -0400
From: "Ben Sommer" <ben@bensommer.com>
Subject: ODBC calls no working
Message-Id: <9i4mvg$27p$1@news.jump.net>
Hello. Please Please help with this:
My little script will (apparently) connect to a DSN with the line:
$dbEmployees = new Win32::ODBC('employees');
where 'employees' is my DSN.
But I get an error when
------------------------------
Date: Fri, 6 Jul 2001 12:01:55 -0400
From: "Ben Sommer" <ben@bensommer.com>
Subject: ODBC commands don't work
Message-Id: <9i4n8d$2ab$1@news.jump.net>
Hello. Please Please help with this:
My little script will (apparently) connect to a DSN with the line:
$dbEmployees = new Win32::ODBC('employees');
where 'employees' is my DSN.
But I get an error when the script hits its first ODBC command:
This:
Can't locate auto/Win32/ODBC/SQL.al in @INC (@INC contains: C:/Perl/lib
C:/Perl/site/lib .) at viewemp.pl line 15
Comes after this:
$dbEmployees->Sql($sql);
Same thing when I try this
while ((!$dbEmployees->EOF()) { ....etc....}
Thanks so much!
------------------------------
Date: 6 Jul 2001 07:20:51 -0700
From: usted@cyberspace.org (dave)
Subject: Parsing an html document for the title (don't flame, I have searched around)
Message-Id: <e2c00ae.0107060620.61d09b18@posting.google.com>
Flame away if you like, but:
while (<LINKS>) {
my $url = $_;
next if $_ =~ /^$/;
my $page = get($url);
my $title = get_title($page);
print "<h3>$title </h3>";
print "<a href=\"$url\">$url</a>\n <br><br>";
}
sub get_title {
my $text = shift;
use HTML::HeadParser;
my $p = HTML::HeadParser->new;
$p->parse($text);
my $title = $p->header("Title");
return $title;
}
After only getting the title correctly out in 9/10 cases, I tried to
use the HeadParser module, but not 4/10 current links return nothing!
Any ideas? I don't want to have to roll my own regular expression to
do this..
thanks,
dave
------------------------------
Date: Fri, 06 Jul 2001 07:24:56 -0700
From: brian d foy <comdog@panix.com>
Subject: Re: Parsing an html document for the title (don't flame, I have searched around)
Message-Id: <comdog-498235.07245606072001@news.panix.com>
In article <e2c00ae.0107060620.61d09b18@posting.google.com>,
usted@cyberspace.org (dave) wrote:
> After only getting the title correctly out in 9/10 cases, I tried to
> use the HeadParser module, but not 4/10 current links return nothing!
> Any ideas?
what's happening in those 4/10 links?
--
brian d foy <comdog@panix.com>
CGI Meta FAQ - http://www.perl.org/CGI_MetaFAQ.html
Troubleshooting CGI scripts - http://www.perl.org/troubleshooting_CGI.html
------------------------------
Date: Fri, 06 Jul 2001 09:29:34 -0400
From: Stephan Gross <sg@loralskynet.com>
Subject: Perl & Outlook/Exchange
Message-Id: <f8fbkt8dkoiqvufphpuferf7lhck2rh752@4ax.com>
I'd like to write a Perl application that will tell me how many
messages are sitting in an Exchange mailbox. Implementations of both
POP3 and IMAP can query a mailbox given the username and password.
The problem is that I have several mailboxes all using the same user
account. Outlook can do this because it understands "profiles" -
i.e., name, password *and* mailbox. Can someone point me to a Perl
solution or Microsoft API?
_______________________________________________________
Stephan Gross Loral Skynet 908-470-2388
sg@loralskynet.com
------------------------------
Date: Thu, 5 Jul 2001 15:13:19 -0400
From: "Evan Panagiotopoulos" <epanagio@frontiernet.net>
Subject: Placing a variable's contents into an array
Message-Id: <9i2e4n$16qc$1@node21.cwnet.roc.gblx.net>
I have a variable which contains the output of a grep command. How can I
place portions of that string into an array? Can I get perl to place the
first 15 characters into the first element of an array.
Thanks,
Evan Panagiotopoulos
------------------------------
Date: 06 Jul 2001 08:50:15 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Q: Global variables
Message-Id: <m33d8amajs.fsf@dhcp9-173.support.tivoli.com>
On 5 Jul 2001, cool133@hotmail.com wrote:
[snip]
> package common::conf;
> use strict;
> use DBI;
>
> # Export Global Variables
> BEGIN {
> use Exporter ();
> @conf::ISA = qw(Exporter);
> @conf::EXPORT = qw();
> @conf::EXPORT_OK = qw(%config);
> }
[snip]
You declare the package as "common::conf", but then refer to
@conf::EXPORT_OK. I would expect that should be
@common::conf::EXPORT_OK.
--
Ren Maddox
ren@tivoli.com
------------------------------
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 1256
***************************************