[21693] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3897 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 2 00:05:41 2002

Date: Tue, 1 Oct 2002 21: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)

Perl-Users Digest           Tue, 1 Oct 2002     Volume: 10 Number: 3897

Today's topics:
    Re: Beginning Perl <none@none.com>
    Re: Can I control "send_te" HTML compression header? (Joe)
        chdir then changing back (jnam)
    Re: chdir then changing back (Walter Roberson)
    Re: chdir then changing back (jnam)
    Re: chdir then changing back <Cptn.Fredo@S.S.No.Spam>
    Re: chdir then changing back (Walter Roberson)
    Re: chdir then changing back (Tad McClellan)
        Connecting to Excel <jlow1@attbi.com>
    Re: Connecting to Excel <cpryce@pryce.nospam.net>
        Connecting to existing Excel Spreadsheet <jlow1@attbi.com>
    Re: Counting Instances of @ in a Scalar (David Garde)
    Re: Counting Instances of @ in a Scalar (Tad McClellan)
    Re: Counting Instances of @ in a Scalar (Tad McClellan)
    Re: Downloading from a www server: Problem develop@gistenson.com
    Re: dynamic pattern matching <bernard.el-hagin@DODGE_THISlido-tech.net>
    Re: dynamic pattern matching <bernard.el-hagin@DODGE_THISlido-tech.net>
    Re: input from a pipe is buffered. <goldbb2@earthlink.net>
    Re: reading Cobol PIC 9(6)V99 formats... <speby@hotmail.com>
        Script stops working when DBI added. Why? <me@me.com>
    Re: Script stops working when DBI added. Why? <me@me.com>
    Re: Self-testing code in Perl? <goldbb2@earthlink.net>
        Sticky forms without CGI.pm? <none@none.com>
    Re: Sticky forms without CGI.pm? <nospam@nospam.com>
    Re: To mod_perl or not to mod_perl? <goldbb2@earthlink.net>
        weird behavior with URI::URL (thomas aquinas)
    Re: weird behavior with URI::URL <nospam@nospam.com>
        Which one is more efficient regarding constant scalars? <VES@VES.NET>
    Re: Which one is more efficient regarding constant scal <nospam@nospam.com>
    Re: Which one is more efficient regarding constant scal <uri@stemsystems.com>
    Re: Why are the columns of a MySQL SELECT scrambled? <cpryce@pryce.nospam.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 02 Oct 2002 02:23:29 +0100
From: Garry <none@none.com>
Subject: Re: Beginning Perl
Message-Id: <andhom$bgh$1@newsg3.svr.pol.co.uk>

ActiveState sell an IDE called "Active Perl". I once downloaded a demo
and it looked like a kind of Visual Studio for Perl, if you like that
sort of IDE :-(

If you use Emacs or Vim they're cross-platform so you can create a
consistent environment. Add Cygwin and you have a close approximation to
UNIX on Windoze.

Much OSS software is now cross-platform, which takes away some of the
pain for *nix-ers who have to work with Windoze. MySQL, Apache, Open
Office, Emacs, Vim, Cygwin, GIMP, Perl, PHP all have Win32 ports.

Garry Heaton


Gyzmo wrote:
> Hi,
> 
> I'm looking for advice on getting perl installed on my pc running XP &
> Debian Linux.I'd like to try and teach myself the language in order to write
> programs for the unix,linux and microsoft environments.
> 
> Is there a good Development Environment that you can recommend ?
> 
> Thank You,
> Graham.
> 
> 



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

Date: 1 Oct 2002 18:14:23 -0700
From: joemercury@gmx.net (Joe)
Subject: Re: Can I control "send_te" HTML compression header?
Message-Id: <d6c57a14.0210011714.e77d874@posting.google.com>

> So where can I control the compression header TE: to set it ON or OFF?
> 
> Thanks.
> J.

Sorry, I meant HTTP protocol, not HTML

J.


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

Date: Wed, 02 Oct 2002 01:09:41 GMT
From: jnam@sunnybrook.com (jnam)
Subject: chdir then changing back
Message-Id: <3d9a47f4.91451580@news-south.giganews.com>

How do i change back to the cgi-bin dierctory after 
chdir ("vip_sap/employee_log")

any help thanks.

jnamiyo


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

Date: 2 Oct 2002 01:34:45 GMT
From: roberson@ibd.nrc.ca (Walter Roberson)
Subject: Re: chdir then changing back
Message-Id: <andifl$ils$1@canopus.cc.umanitoba.ca>

In article <3d9a47f4.91451580@news-south.giganews.com>,
jnam <jnam@sunnybrook.com> wrote:
:How do i change back to the cgi-bin dierctory after 
:chdir ("vip_sap/employee_log")

If you start in cgi-bin and chdir "vip_sap/employee_log" then
  chdir "../.."   will get you back again.

If you start in cgi-bin and chdir to some absolute path, then to get
back, you would have to figure out where you started or else chdir to
an absolute path that you "ought to have" started from.

To figure out where you are now, see the modules at

http://search.cpan.org/author/LIBERTY/Cwd-2.06/Cwd.pm   or
http://search.cpan.org/author/JHI/perl-5.8.0/lib/Cwd.pm

--
   "There are three kinds of lies: lies, damn lies, and statistics."
   -- not Twain, perhaps Disraeli, first quoted by Leonard Courtney


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

Date: Wed, 02 Oct 2002 01:49:52 GMT
From: jnam@sunnybrook.com (jnam)
Subject: Re: chdir then changing back
Message-Id: <3d9a5072.93624825@news-south.giganews.com>

Thanks much

one follow up question: 

chdir "../.."    is there no ( ) ? or ;

Thanks again

roberson@ibd.nrc.ca (Walter Roberson) wrote:

>In article <3d9a47f4.91451580@news-south.giganews.com>,
>jnam <jnam@sunnybrook.com> wrote:
>:How do i change back to the cgi-bin dierctory after 
>:chdir ("vip_sap/employee_log")
>
>If you start in cgi-bin and chdir "vip_sap/employee_log" then
>  chdir "../.."   will get you back again.
>
>If you start in cgi-bin and chdir to some absolute path, then to get
>back, you would have to figure out where you started or else chdir to
>an absolute path that you "ought to have" started from.
>
>To figure out where you are now, see the modules at
>
>http://search.cpan.org/author/LIBERTY/Cwd-2.06/Cwd.pm   or
>http://search.cpan.org/author/JHI/perl-5.8.0/lib/Cwd.pm
>
>--
>   "There are three kinds of lies: lies, damn lies, and statistics."
>   -- not Twain, perhaps Disraeli, first quoted by Leonard Courtney



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

Date: Wed, 02 Oct 2002 02:33:44 GMT
From: ".Fredo" <Cptn.Fredo@S.S.No.Spam>
Subject: Re: chdir then changing back
Message-Id: <cWsm9.1047$2n3.121019577@newssvr14.news.prodigy.com>


"Walter Roberson" <roberson@ibd.nrc.ca> wrote in message
news:andifl$ils$1@canopus.cc.umanitoba.ca...
> In article <3d9a47f4.91451580@news-south.giganews.com>,
> jnam <jnam@sunnybrook.com> wrote:
> :How do i change back to the cgi-bin dierctory after
> :chdir ("vip_sap/employee_log")
>
> If you start in cgi-bin and chdir "vip_sap/employee_log" then
>   chdir "../.."   will get you back again.
>
> If you start in cgi-bin and chdir to some absolute path, then to get
> back, you would have to figure out where you started or else chdir to
> an absolute path that you "ought to have" started from.
>
> To figure out where you are now, see the modules at

Or one can simply do this:
   my $current_path = `pwd 2>&1`;

> http://search.cpan.org/author/LIBERTY/Cwd-2.06/Cwd.pm   or
> http://search.cpan.org/author/JHI/perl-5.8.0/lib/Cwd.pm

Nothin' wrong with a module too; in fact it may offer betteer
compatibility among differnt platforms.




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

Date: 2 Oct 2002 02:44:06 GMT
From: roberson@ibd.nrc.ca (Walter Roberson)
Subject: Re: chdir then changing back
Message-Id: <andmhm$kgj$1@canopus.cc.umanitoba.ca>

In article <3d9a5072.93624825@news-south.giganews.com>,
jnam <jnam@sunnybrook.com> wrote:
:one follow up question: 

:chdir "../.."    is there no ( ) ?

As is the case for all perl functions, you do not need () around
the arguments unless the function allows a list of arguments,
you are already in a list and you need to mark the
end of the argument to this particular functions.

For example, in

  print $a, log abs cos .13, reverse($d, $e), push @bar, 1, 2, 3

there are 4 arguments to the 'print' function:

   $a
   log abs cos .13
   reverse($d, $e)
   push @bar, 1, 2, 3

Without the (), the argument list for reverse would have extended to
include the  push @bar, 1, 2, 3

Notice the scope of the push extends as far as possible to the right.
If you'd only wanted to push the 1 onto @bar, and meant the 2 and 3 to
be further arguments to print, then you would have needed (@bar, 1)

Another note: adding unnecessary () can change the meaning of your code
in subtle ways... not just the possibility of accidently introducing
a list context you didn't mean, but because you might end up invoking
something without the right prototype. See the perlsub documentation for 
information about prototypes.


:or ;

chdir "../.."  is an expression. If you don't need the result of that
expression, then add a semi-colon at the end to change it into a command.
You should, though, be checking to see that the chdir worked:

  chdir "../.." or die "Could not cd back to where I started!";

--
Pity the poor electron, floating around minding its own business for
billions of years; and then suddenly Bam!! -- annihilated just so
you could read this posting.


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

Date: Wed, 02 Oct 2002 03:19:37 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: chdir then changing back
Message-Id: <slrnapkmld.3ae.tadmc@magna.augustmail.com>

jnam <jnam@sunnybrook.com> wrote:

> chdir "../.."    is there no ( ) ? or ;


Parenthesis around function argument lists are (nearly 
always) optional.

If you like parenthesis around function args use parenthesis.

If you don't, don't.


Semicolon is a statement separator, so it depends on whether
you have another thing to separate or not.

Most of the time you'll need the semicolon[1]. If the chdir()
is the last statement in a block or in your program, then
you can omit the semicolon too.



[1] But you wouldn't put it immediately after the chdir()
    call, because you need to check its return value :-)

   chdir "../.." or die "could not back up two levels";

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


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

Date: Wed, 02 Oct 2002 01:34:56 GMT
From: Kenny Low <jlow1@attbi.com>
Subject: Connecting to Excel
Message-Id: <3D99EAC9.4020801@attbi.com>

  Hello,
I'm trying to connect to an existing Excel spreadsheet. In the 
spreadhseet there are 3 columns of interest to me. I'd like to have 4 
variables (3 for columns A,B,C and one for the current row) that I would 
use in a loop to extract data. Everything I've seen so far creates a new 
spreadsheet so here are my questions.

1) Can I connect to an exiting Excel Spreadsheet? If so how? Which 
modules would I need?

2) Can I use SQL statements in PERL to query the spreasheet or is it 
easier to use some other method?

Thanks
jl



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

Date: Wed, 02 Oct 2002 03:28:49 GMT
From: cp <cpryce@pryce.nospam.net>
Subject: Re: Connecting to Excel
Message-Id: <011020022233576203%cpryce@pryce.nospam.net>

In article <3D99EAC9.4020801@attbi.com>, Kenny Low <jlow1@attbi.com>
wrote:

> I'm trying to connect to an existing Excel spreadsheet. In the 
> spreadhseet there are 3 columns of interest to me. I'd like to have 4 
> variables (3 for columns A,B,C and one for the current row) that I would 
> use in a loop to extract data. Everything I've seen so far creates a new 
> spreadsheet so here are my questions.
> 
> 1) Can I connect to an exiting Excel Spreadsheet? If so how? Which 
> modules would I need?
> 
> 2) Can I use SQL statements in PERL to query the spreasheet or is it 
> easier to use some other method?

Often when the question is "how do I do X" or "what module do I use to
do X" the answer can be found on the CPAN archive (at www.cpan.org or
search.cpan.org). 

If you want to use SQL on the Spreadsheet you might have a look at
DBD::Excel. 

Spreadsheet::WriteExcel also has an extension called
Spreadsheet::WriteExcel::FromDB, but you can't query existing values
from WriteExcel. 

Search the perl.dbi.users mailing list at
http://groups.google.com/groups?group=perl.dbi.users for other
solutions.

-- 
cp

remove 'nospam' to reply


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

Date: Wed, 02 Oct 2002 01:33:16 GMT
From: Kenny Low <jlow1@attbi.com>
Subject: Connecting to existing Excel Spreadsheet
Message-Id: <3D99EA65.8050605@attbi.com>




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

Date: 1 Oct 2002 18:28:28 -0700
From: david_garde@yahoo.com (David Garde)
Subject: Re: Counting Instances of @ in a Scalar
Message-Id: <ca6180e1.0210011728.21b919a3@posting.google.com>

Tina Mueller <usenet@tinita.de> wrote in message news:<ancf30$cn630$1@fu-berlin.de>...
> David Garde <david_garde@yahoo.com> wrote:
> > I am very fresh at writing perl and am trying to get a count on the
> > number of @ in a scalar variable.
> 
> my $count = $scalar =~ tr/@//;
> 
> > The code I wrote is:
>  
> > $count = 0;
> > $email = <STDIN>;
> >     while ($email =~ /@/g) {
> >        $count += 1; 
> >        print "$count\n";
> >        exit;
> 
> you are exiting the program here, already after the
> first loop.
> 
> hth, tina

Sorry to bother you again but your info was quite helpful. Thank you.
This is what I came up with:

print "Please enter your e-mail address\n";

$email = <STDIN>;     
      if ($email !~ /@/) {
          print "ERROR\n";
      exit;
      }
while ($count = ($email =~ tr/@//)) {
      if ($count > 1) {
          print "ERROR\n";
      exit;
      }    
      else {
      print "okay\n";
      exit;
      }
}

This will test for the existence of no @ marks or more than one giving
an error in each case.


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

Date: Wed, 02 Oct 2002 03:19:38 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Counting Instances of @ in a Scalar
Message-Id: <slrnapko92.3ae.tadmc@magna.augustmail.com>

David Garde <david_garde@yahoo.com> wrote:
> Tina Mueller <usenet@tinita.de> wrote in message news:<ancf30$cn630$1@fu-berlin.de>...
>> David Garde <david_garde@yahoo.com> wrote:
>> > I am very fresh at writing perl and am trying to get a count on the
>> > number of @ in a scalar variable.


> Thank you for the reply. However the returned value is now one more
> than the true value when I use this:


Yes, because you are adding one to the correct value.

Don't do that if you don't want that.  :-)


> $count = 0;
> $email = <STDIN>;
> my $count = $email =~ tr/@//;
>             $count += 1; 
              

Adds one to the value in $count.

Your original code needed to loop and count, tr/// gives
you the count directly, no further counting or looping needed.


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


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

Date: Wed, 02 Oct 2002 03:19:39 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Counting Instances of @ in a Scalar
Message-Id: <slrnapkord.3ae.tadmc@magna.augustmail.com>

David Garde <david_garde@yahoo.com> wrote:
> Tina Mueller <usenet@tinita.de> wrote in message news:<ancf30$cn630$1@fu-berlin.de>...
>> David Garde <david_garde@yahoo.com> wrote:
>> > I am very fresh at writing perl and am trying to get a count on the
>> > number of @ in a scalar variable.
>> 
>> my $count = $scalar =~ tr/@//;

[snip]

> while ($count = ($email =~ tr/@//)) {


Why is this in a loop?

How many times do you expect the loop to execute?


>       if ($count > 1) {
>           print "ERROR\n";
>       exit;
>       }    
>       else {
>       print "okay\n";
>       exit;
>       }
> }
> 
> This will test for the existence of no @ marks or more than one giving
> an error in each case.


So will this:

   if ( $email =~ tr/@// != 1 )
      { print "ERROR\n" }
   else
      { print "okay\n" }


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


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

Date: Wed, 2 Oct 2002 02:52:39 +0000 (UTC)
From: develop@gistenson.com
Subject: Re: Downloading from a www server: Problem
Message-Id: <andn1n$58b$1@flood.xnet.com>

Tab and Alan,

I'll try again.

I'm developing a web site, not client-side software. The web site needs to 
transfer files from it to the client.

Alan, you're solution, using an anchor, is fine for downloading one file, 
but I'm interested in a shopping cart application: A user, via his 
browser, selects the items he wants to buy by clicking on a picture of 
each item he intends to buy. This causes the item to be added to his 
shopping cart. When the user has picked all of the items he wants to buy, 
he clicks on a link, call it:

<a href="checkout.cgi">checkout</a>

The script checkout.cgi is the script of interest here and needs to do the 
following:
1. Initiate the credit card processing (No help needed here.)
2. Download to the user all of the purchased items. (The items are all 
binary files.)

The LWP documentation appears to say that LWP's purpose is at the machine 
at the "receiveing" end of a file transfer. (ie. get, getprint and 
getstore.) Am I wrong? I need something like putstore.

I'm looking for guidance with the second of the above two "checkout" 
steps.

Thanks,
Dan



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

Date: Tue, 1 Oct 2002 11:40:43 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: dynamic pattern matching
Message-Id: <slrnapj2b8.1bi.bernard.el-hagin@gdndev25.lido-tech>

In article <anc0q5$7dn$1@oslo-nntp.eunet.no>, Brutus wrote:
> Usually pattern matching is hard coded, e.g.:
> if (/ "expression" /)
> 
> But what if  "expression" is a scalar variable ?
> I'm looking for the syntax for finding the occurance of an expression
> ( contained in a scalar ) in another scalar.
> 
> I've been looking in the books, without any luck so far.


You need to get rid of those books, then. You could look in the free
documentation you got with Perl. I suggest starting with perlre.pod
which you can access by issuing the command


  perldoc perlre


Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'


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

Date: Tue, 1 Oct 2002 11:43:28 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: dynamic pattern matching
Message-Id: <slrnapj2gd.1bi.bernard.el-hagin@gdndev25.lido-tech>

In article <anc0q5$7dn$1@oslo-nntp.eunet.no>, Brutus wrote:
> Usually pattern matching is hard coded, e.g.:
> if (/ "expression" /)
> 
> But what if  "expression" is a scalar variable ?
> I'm looking for the syntax for finding the occurance of an expression
> ( contained in a scalar ) in another scalar.
> 
> I've been looking in the books, without any luck so far.


You need to get rid of those books, then. You could look in the free
documentation you got with Perl. I suggest starting with perlre.pod
which you can access by issuing the command


  perldoc perlre


You can also check the FAQ. I think this question is covered there to
some extent.


Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'


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

Date: Tue, 01 Oct 2002 22:37:53 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: input from a pipe is buffered.
Message-Id: <3D9A5C01.634E8BFE@earthlink.net>

aaron smith wrote:
> 
> > I recoded to use getc(PIPE) in place of <PIPE>.
> > On windows2000, I still don't see any input until ~50 messages are
> > sent from the monuserfield program.
> 
> John, can you include a little bit of the code you're using? You
> should be getting output with each character received. I had a similar
> problem awhile back I seem to recall sysread and syswrite worked out
> for me, but I don't see why getc and syswrite shouldn't be ok.

The problem sounds like the *other end* of PIPE is being buffered.

Sure, he gets output for each character received, but the characters are
not being sent in the first place, due to IO buffering on the writing
end of the pipe.

-- 
How many Monks would a Chipmonk chip,
if a Chipmonk could chip Monks?


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

Date: Tue, 1 Oct 2002 21:53:37 -0500
From: "Sean Eby" <speby@hotmail.com>
Subject: Re: reading Cobol PIC 9(6)V99 formats...
Message-Id: <andn2a$e4m$1@husk.cso.niu.edu>

"Jim Agnew" <jpagnew@vcu.edu> wrote in message
news:3D9A003C.990A91A0@vcu.edu...
> People, subject says it all,
>
> on a VMS system, try to read a Cobol PIC 9(6)V99 formats...
>
> I'm a newbie trying to redo an accounting system from Cobol to
something
> a little bit less unwieldy...  ;-)
>
> so the question is how can Perl read that stuff? I think I'm wading
thru
> most else ok,
> just time and beating my head on the books...
>
> jim

Why don't you post something more specific? Show some examples of the
COBOL and the format of the actual data (if possible) and explain what
you are trying to read and/or extract.

Sean




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

Date: Wed, 02 Oct 2002 02:13:27 GMT
From: "ColdCathoid" <me@me.com>
Subject: Script stops working when DBI added. Why?
Message-Id: <bDsm9.435692$v53.19714827@news3.calgary.shaw.ca>

Slowly I am getting my brain wrapped around perl. I wrote a CGI script to
upload files, rename with a unique name and store them on the server. This
all worked fine and dandy until I decided I wanted to add some database
functionality with it. I want to connect to a database and store the
filename and some other related info. But when I add "use DBI" the program
breaks and I get:

"Internal Server Error
The server encountered an internal error or misconfiguration and was unable
to complete your request.
Please contact the server administrator, admin and inform them of the time
the error occurred, and anything you might have done that may have caused
the error.
More information about this error may be available in the server error log.
Additionally, a 404 Not Found error was encountered while trying to use an
ErrorDocument to handle the request. "

I am not sure why just adding "use DBI" can make it break. What am I not
doing right?

The company that I am hosted with has perl 5.005 w/DBI support and MySQL
database. Here is the code I have so far... I know it's kind of ghetto. =)

#!/usr/bin/perl -w

use DBI;
use CGI qw/:standard/;

$upload_dir = "/home/sites/www.datamolders.com/web/FileUpload/files";

$query = new CGI;

#Upload first file
$filename1 = $query->param("file1");
$filename1 =~ s/.*[\/\\](.*)/$1/;
$upload_filehandle1 = $query->upload("file1");

#Upload second file
$filename2 = $query->param("file2");
$filename2 =~ s/.*[\/\\](.*)/$1/;
$upload_filehandle2 = $query->upload("file2");

#Upload third file
$filename3 = $query->param("file3");
$filename3 =~ s/.*[\/\\](.*)/$1/;
$upload_filehandle3 = $query->upload("file3");

#Upload fourth file
$filename4 = $query->param("file4");
$filename4 =~ s/.*[\/\\](.*)/$1/;
$upload_filehandle4 = $query->upload("file4");


if ($filename1 ne "") {

   #Get a unique file name
   $file1unique = createUniqueFileName();
   $filename1 = $file1unique;
   open UPLOADFILE, ">$upload_dir/$filename1";
   while ( <$upload_filehandle1> )
   {
      print UPLOADFILE;
   }
   close UPLOADFILE;
   $file1html = "<img src=\"files\/$filename1\"
border=\"0\"><br>$file1unique";

 }

if ($filename2 ne "") {

   #Get a unique file name
   $file2unique = createUniqueFileName();
   $filename2 = $file2unique;
   open UPLOADFILE, ">$upload_dir/$filename2";
   while ( <$upload_filehandle2> )
   {
   print UPLOADFILE;
   }
   close UPLOADFILE;
   $file2html = "<br><img src=\"files\/$filename2\"
border=\"0\"><br>$file2unique";

}

if ($filename3 ne "") {

   #Get a unique file name
   $file3unique = createUniqueFileName();
   $filename3 = $file3unique;
   open UPLOADFILE, ">$upload_dir/$filename3";
   while ( <$upload_filehandle3> )
   {
   print UPLOADFILE;
   }
   close UPLOADFILE;
   $file3html = "<br><img src=\"files\/$filename3\"
border=\"0\"><br>$file3unique";
}

if ($filename4 ne "") {

   #Get a unique file name
   $file4unique = createUniqueFileName();
   $filename4 = $file4unique;
   open UPLOADFILE, ">$upload_dir/$filename4";
   while ( <$upload_filehandle4> )
   {
   print UPLOADFILE;
   }
   close UPLOADFILE;
   $file4html = "<br><img src=\"files\/$filename4\"
border=\"0\"><br>$file4unique";
}

#Some code to do cool database inserts

sub createUniqueFileName{

#Change filename
# Get the all the values for current time
($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOfYear, $IsDST)
= localtime(time);

$Month = $Month + 1; # Months of the year are not zero-based
if($Month < 10)
{
   $Month = "0" . $Month; # add a leading zero to one-digit months
}

if($Day < 10)
{
   $Day = "0" . $Day; # add a leading zero to one-digit days
}
$Year = $Year + 1900;

$rand_int = int(rand 9999)+1;

$newfilename = $Year . $Month . $Day . "_" . $Hour . $Minute . $Second . "_"
 . $rand_int . ".jpg";

return $newfilename;
}


print $query->header ( );
print <<END_HTML;

<HTML>
<HEAD>
<TITLE>Thanks!</TITLE>
</HEAD>
<BODY>
<P>Thanks for uploading your photo!</P>

   $file1html
   $file2html
   $file3html
   $file4html

</BODY>
</HTML>

END_HTML




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

Date: Wed, 02 Oct 2002 03:42:45 GMT
From: "ColdCathoid" <me@me.com>
Subject: Re: Script stops working when DBI added. Why?
Message-Id: <VWtm9.461705$f05.20883421@news1.calgary.shaw.ca>


"ColdCathoid" <me@me.com> wrote in message
news:bDsm9.435692$v53.19714827@news3.calgary.shaw.ca...
<snip>

Nevermind everyone .. it seems the goofy editor I was using was adding some
extra wonky code that made the script bomb. Went back to trusty Textpad and
everything is working great now! Reading and writing to the DB. Woot!




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

Date: Tue, 01 Oct 2002 22:22:52 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Self-testing code in Perl?
Message-Id: <3D9A587C.73121F4E@earthlink.net>

J Hall wrote:
> 
> Dear Perl Users,
>     Is there a way to create Perl scripts/modules that include
> self-testing code similar to the Python contruct 'if __name__ ==
> "__main__":'. Thanks.

You mean like if( $0 eq __FILE__ ) ?

-- 
How many Monks would a Chipmonk chip,
if a Chipmonk could chip Monks?


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

Date: Wed, 02 Oct 2002 02:12:33 +0100
From: Garry <none@none.com>
Subject: Sticky forms without CGI.pm?
Message-Id: <andh46$nb0$1@newsg2.svr.pol.co.uk>

I loathe writing second-hand HMTL with CGI.pm but I need the sticky form
feature. Any ideas how to do it without CGI.pm? Do I need to access
$REQUEST_URI or $QUERY_STRING? Parse this with regex's?

Garry Heaton



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

Date: Tue, 1 Oct 2002 20:57:36 -0700
From: "Tan Nguyen" <nospam@nospam.com>
Subject: Re: Sticky forms without CGI.pm?
Message-Id: <3d9a6e2a$1_5@nopics.sjc>


"Garry" <none@none.com> wrote in message

> I loathe writing second-hand HMTL with CGI.pm but I need the sticky form
> feature. Any ideas how to do it without CGI.pm? Do I need to access
> $REQUEST_URI or $QUERY_STRING? Parse this with regex's?

It looks like you have to parse the query string without the use of CGI.pm.
It's fairly simple, but you have to be careful with URL encoding characters.




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

Date: Tue, 01 Oct 2002 22:33:32 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: To mod_perl or not to mod_perl?
Message-Id: <3D9A5AFC.67C17CA9@earthlink.net>

Koos Pol wrote:
> 
> Helgi Briem wrote (Monday 30 September 2002 12:46):
> 
> > On Mon, 30 Sep 2002 10:50:47 +0200, Koos Pol
> > <koos_pol@NO.nl.JUNK.compuware.MAIL.com> wrote:
> >
> >>On a purely personal note, I never came to use mod_perl
> >>because of the  namespace problems. Spent a few days to
> >>figure out why my variables weren't visible while I figured
> >>they should be.
> >
> > If you had scoped your variables properly, as you always
> > should anyway, this would not have been a problem.
> 
> I wish it was that easy. I remember clearly that while variable $bar
> was just living in it's own package Foo, I wasn't able to resolve it
> with $Foo::bar. Sometomes I could, sometimes I couldn't.

You *do* realize that apache makes multiple instances of itself, right?

> A bit later I learned that with mod_perl things can get complicated as
> each httpd instance gets it's own namespace and thus does't know the
> "current" variables and values.

Define current.  Do you mean to say that you expected package globals to
be shared amongst all of the httpd processes?

> I find this property/behaviour very much disturbing (programming wise)
> As it is already half a year back, I don't recall the exact issue. But
> cleary "If you had scoped your variables properly" is too short
> sighted.

The OP is worried that due to persistance, his variables might not get
reinitialized as they should, and that values might continue to exist
longer than they should, and have overly-wide visibility.  *Your*
problem seems to have been that you were *trying* to get variables to be
more visible than was possible, and you were confused when it didn't
work.

You had a different problem entirely, and it was not mod_perl's fault
that it didn't work as you expected.

-- 
How many Monks would a Chipmonk chip,
if a Chipmonk could chip Monks?


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

Date: 2 Oct 2002 03:18:03 GMT
From: aquinas@no.uce.thanks.com (thomas aquinas)
Subject: weird behavior with URI::URL
Message-Id: <andoh7$dau2u$1@ID-42081.news.dfncis.de>

Dear All,

I have tried the following one-liner with URI/URL.pm version 5.02/5.03 and URI 
= 1.18 (on SunOS 5.8), and it works fine:

$ perl -e 'use URI::URL; my $url = new URI("http://foo.bar/sh.htm"); print \ 
$url->host,"\n"'

But when I run the following code:

---
#!/usr/bin/perl 

use URI::URL;
my (%urls,$url,$host);

while (<>) {

  $url = URI::URL->new("$_");
  $host = $url->host();
  print $host,"\n";
  $urls{$host}++;

}
---

it produces the following output:

Can't locate object method "host" via package "URI::_generic" (perhaps you 
forgot to load  "URI::_generic"?) at 
/usr/local/lib/perl5/site_perl/5.6.1/URI/WithBase.pm line 48, <> line 1.

Even if I explicily load '_generic' and WithBase.pm... Why is this happening?  
How can I fix it?

Thanks in advance,
thomas.



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

Date: Tue, 1 Oct 2002 20:47:48 -0700
From: "Tan Nguyen" <nospam@nospam.com>
Subject: Re: weird behavior with URI::URL
Message-Id: <3d9a6bde$1_1@nopics.sjc>


"thomas aquinas" <aquinas@no.uce.thanks.com> wrote > Dear All,
>
> I have tried the following one-liner with URI/URL.pm version 5.02/5.03 and
URI
> = 1.18 (on SunOS 5.8), and it works fine:
>
> $ perl -e 'use URI::URL; my $url = new URI("http://foo.bar/sh.htm"); print
\
> $url->host,"\n"'
>
> But when I run the following code:
>
> ---
> #!/usr/bin/perl
>
> use URI::URL;
> my (%urls,$url,$host);
>
> while (<>) {
>
>   $url = URI::URL->new("$_");
>   $host = $url->host();
>   print $host,"\n";
>   $urls{$host}++;
>
> }
> ---
>
> it produces the following output:
>
> Can't locate object method "host" via package "URI::_generic" (perhaps you
> forgot to load  "URI::_generic"?) at
> /usr/local/lib/perl5/site_perl/5.6.1/URI/WithBase.pm line 48, <> line 1.
>
> Even if I explicily load '_generic' and WithBase.pm... Why is this
happening?
> How can I fix it?
>
> Thanks in advance,
> thomas.
>

You instantiate two different objects here. With the command line version,
you create an URI object while your script makes  an URI::URL one.





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

Date: Wed, 02 Oct 2002 01:29:37 GMT
From: Vespasian <VES@VES.NET>
Subject: Which one is more efficient regarding constant scalars?
Message-Id: <PUuaPaQrTaxBQ+Ndlpx6uUnhHfA=@4ax.com>

Which of the following is more time/memory efficient or are they the
same?

1) 
use constant PI => 3.14; 

or,

2) 
*PI = \3.14;


Thanks.



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

Date: Tue, 1 Oct 2002 20:52:37 -0700
From: "Tan Nguyen" <nospam@nospam.com>
Subject: Re: Which one is more efficient regarding constant scalars?
Message-Id: <3d9a6cff$1_3@nopics.sjc>


"Vespasian" <VES@VES.NET> wrote in message > Which of the following is more
time/memory efficient or are they the
> same?
>
> 1)
> use constant PI => 3.14;
>
> or,
>
> 2)
> *PI = \3.14;
>
>
> Thanks.
>
I just like to add the third
3)
sub PI() { 3.14 }

The doc mentions that any subs with void parameter list are cadidates for
inline code, hence, I believe this is the most efficient (after compiling
phase).




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

Date: Wed, 02 Oct 2002 03:56:29 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Which one is more efficient regarding constant scalars?
Message-Id: <x7adlxa3yq.fsf@mail.sysarch.com>

>>>>> "TN" == Tan Nguyen <nospam@nospam.com> writes:

  >> use constant PI => 3.14;

  TN> I just like to add the third
  TN> 3)
  TN> sub PI() { 3.14 }

  TN> The doc mentions that any subs with void parameter list are
  TN> cadidates for inline code, hence, I believe this is the most
  TN> efficient (after compiling phase).

that is just what the constant pragma does. i would recommend using it
for clarity over your solution or the obscure assigning a ref to a
typeglob method.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Wed, 02 Oct 2002 03:16:44 GMT
From: cp <cpryce@pryce.nospam.net>
Subject: Re: Why are the columns of a MySQL SELECT scrambled?
Message-Id: <011020022221522596%cpryce@pryce.nospam.net>

In article <3b25bd38.0210011406.cecb586@posting.google.com>, James
<caligari2k@yahoo.com> wrote:

> This is an interesting situation I have.  I have something like:
> 
>     $myquery = "SELECT * FROM main where centernumber = ?";
>     $sth = $dbh->prepare($myquery);
>     $sth->execute(2);
> 
> Now, I know I only have 1 row that is being returned, but due to the
> nature of the code I'm trying to write (ie very very generic) I return
> the row via the following:
> 
>     my $row = $sth->fetchrow_hashref;
> 
> Then I can parse the hash to get the column names plus the value of
> said column associated with centernumber=2.  Here's the kicker, the
> hash is all scrambled.  If I use the command line client for mysql and
> execute the same query, it is ordered like I want it.  But not here! 
> I can see this by using
> 
>     print Dumper($row);
> 
> So when I loop through the the columnnames, everything is out of
> whack.  

You could try something like: 

my $row = $sth->fetchrow_hashref(); 

for ( @{ $sth->{NAME} } ) { 
   print "$_: $row->{$_}\n" ; 
} 


or $sth->{NAME_lc} to make it more portable...

-- 
cp

remove 'nospam' to reply


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

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


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