[15987] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3399 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jun 17 03:10:23 2000

Date: Sat, 17 Jun 2000 00:10:14 -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: <961225814-v9-i3399@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 17 Jun 2000     Volume: 9 Number: 3399

Today's topics:
    Re: now this is strange... <kmsproule@worldnet.att.net>
        Passing a database handles to subs.... <david@dbillingham.demon.co.uk>
        Posting a picture <shawnball@uswest.net>
    Re: Posting a picture <lauren_smith13@hotmail.com>
    Re: Posting a picture <djbishop@bigfoot.com>
    Re: Posting a picture (Malcolm Dew-Jones)
    Re: read single chars <abe@ztreet.demon.nl>
    Re: Subclassing Exporter::import (Randal L. Schwartz)
    Re: Ugh (jason)
    Re: Very Strange Behaviour <rootbeer@redcat.com>
    Re: What is wrong? (Tad McClellan)
    Re: Writing line of death to log (Steve Leibel)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sat, 17 Jun 2000 06:08:05 GMT
From: "Kevin M. Sproule" <kmsproule@worldnet.att.net>
Subject: Re: now this is strange...
Message-Id: <9BE25.6241$C44.349278@bgtnsc05-news.ops.worldnet.att.net>


"Raphael Pirker" <raphaelp@nr1webresource.com> wrote in message
news:8hu0if$iqv$1@news.online.de...
> I have quite a few variables that need to be defined:
>
> $autoresp_state       = $FORM{autoresp_state};
> SNIP ...
> $results_link_url     = $FORM{results_link_url};
>
> Now, what I want is to shorten this. I came up with an Idea, but this $h!t
> just doesn't want to work... :-)
>
> foreach $key (keys(%FORM)) {
> $key = $FORM{$key};
> }
>
> I'm more than stranded here. It took me ages to find a possible solution
and
> now it doesn't work! :-(
>
> Could anyone point me into the right direction? (please feel free to
> underestimate my IQ... :-)
>
> Regards,
>
> Raphael


Raphael,

Oh you were so close!

foreach $key (keys(%FORM)) {
    $$key = $FORM{$key};
}

Note the extra $ which means use indirection.  This will assign the values
to variables generated by $$key.  Cool stuff!

Digitally yours,

Kevin Sproule





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

Date: Fri, 16 Jun 2000 07:14:03 +0100
From: "David" <david@dbillingham.demon.co.uk>
Subject: Passing a database handles to subs....
Message-Id: <961222466.15154.0.nnrp-08.c2deb140@news.demon.co.uk>

Hi

I am writing as set of cgi scripts that use the Perl DBI to connect to a
database. I want to connect to to the database and then call a sub, passing
the sub the database handle or a handle returned by a prepare statement.
I've tried to pass it by reference but can't find the right syntax - any
suggestions?

Does anybody outhere know how to do this - or whether there is better
approach?

For instance:

use strict;
my $dbh = DBI->connect('dbi:ODBC:driver=Microsoft Access Driver
(*.mdb);dbq=h:\db\Products.mdb') or die $DBI::errstr;

if ($FormData{search_button} eq 'Show Groups')
{
my $sql = "SELECT * FROM groups ORDER BY group_description";
my $tbh = $dbh->prepare($sql) || &HandleError($DBI::errstr);

#Pass handle returned by $dbh->prepare - except it doesn't work....
&ShowGroups($tbh);

};

Thanks in advance.

David Billingham









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

Date: Fri, 16 Jun 2000 20:31:38 -0700
From: "Ferk Da Jerk" <shawnball@uswest.net>
Subject: Posting a picture
Message-Id: <5gA25.722$RY6.43752@news.uswest.net>

I want to make a Perl/CGI script that lets users type in the location of a
picture on their computer and have it uploaded to my server and saved.
Could any one help me out with this.




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

Date: Fri, 16 Jun 2000 18:17:41 -0700
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: Posting a picture
Message-Id: <8iejig$95v$1@brokaw.wa.com>


Ferk Da Jerk <shawnball@uswest.net> wrote in message
news:5gA25.722$RY6.43752@news.uswest.net...
> I want to make a Perl/CGI script that lets users type in the location of a
> picture on their computer and have it uploaded to my server and saved.
> Could any one help me out with this.

Take a look at the documentation for the CGI.pm module.  It is already
installed if you've got Perl correctly installed, so just do a 'perldoc CGI'
and read on.

Lauren





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

Date: Sat, 17 Jun 2000 02:25:15 +0100
From: "Dominic Bishop" <djbishop@bigfoot.com>
Subject: Re: Posting a picture
Message-Id: <8iek4u$4khcm$1@fu-berlin.de>


"Ferk Da Jerk" <shawnball@uswest.net> wrote in message
news:5gA25.722$RY6.43752@news.uswest.net...
> I want to make a Perl/CGI script that lets users type in the location of a
> picture on their computer and have it uploaded to my server and saved.
> Could any one help me out with this.
>
>

There is an example of this at cgi101.com class 17,
http://www.cgi101.com/class/ch17/

Dominic Bishop




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

Date: 16 Jun 2000 21:24:12 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Posting a picture
Message-Id: <394afd6c@news.victoria.tc.ca>

Ferk Da Jerk (shawnball@uswest.net) wrote:
: I want to make a Perl/CGI script that lets users type in the location of a
: picture on their computer and have it uploaded to my server and saved.
: Could any one help me out with this.


send an HTML page to the browser, something like this (but this is NOT
quite correct, read your HTML documentation for exact details.) 


<FORM ENCTYPE="multipart/form-data" action=yourscript>
<input type=file name="thefile">
</FORM>


Your script (called "yourscript") has lines something like this


#!perl (untested, dosn't work)

# this script saves the file in the _current_directory_ of the running cgi
# script, which is not where you want it to be, and MOST CGI SCRIPTS do
# not have permission to do this, so the script will die a horrible death.

# this is just an example.

use CGI qw/ :standard /;

$uploaded_files_original_name = param('thefile');

open LOCAL_FILE , ">uploaded_file.saved"  or die "horrible death, $!";
binmode LOCAL_FILE;

# ( note that the original name of the file is used as the name of the
#   variable to hold a local file handle )

while ( <$uploaded_files_original_name> )
{
	print LOCAL_FILE $_;
}
close LOCAL_FILE;



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

Date: Sat, 17 Jun 2000 03:41:30 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: read single chars
Message-Id: <7gklks0dbbsravj77uphjvf25ocu69ao19@4ax.com>

On Fri, 16 Jun 2000 13:26:25 -0500, "Tim" <tcuffel@exactis.com> wrote:

> Tad McClellan wrote in message ...
> >On Fri, 16 Jun 2000 20:27:46 +0200, Oliver Soeder <soeder@ai-lab.fh-furtwangen.de> wrote:
> >
> >>but I am a novice.
> >
> >
> >That is no excuse.
> >
> >Usenet practice *requires* that you check the FAQ before posting.
> >
> >There is no exception for novices.
> 
> 
> [snip]
> 
> A little quick with the trigger finger there, cowboy...
> 
> His full question boiled down to "Can I read one character from a file
> using <> syntax?"
> 
Did you actually read the question? 
Did you actually read the answer in perlfaq5?

[quoted from OP]
> $chars=<STDIN>
> This reads in a string, how can i read it as single chars?

Now I can make a lot of that, but I never would have come up with your
interpretation. Can we dismiss <STDIN> as a clue, it's not just _any_
filehandle.
Lauren's answer looks like a good job to me.

You seem a bit trigger-happy yourself :-)

-- 
Good luck,
Abe


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

Date: 16 Jun 2000 18:47:42 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Subclassing Exporter::import
Message-Id: <m1vgz9m62p.fsf@halfdome.holdit.com>

>>>>> "Andrew" == Andrew Perrin <- Demography <aperrin@famine.DEMOG.Berkeley.EDU>> writes:

Andrew> I want to be able to pass an option to an Exporting package; the
Andrew> option is 'no_logger' and tells the package to avoid opening a
Andrew> separate logging script that is part of the application.  The package
Andrew> is called DemogTrak, and I would like to use it such:

Andrew> use DemogTrak qw/no_logger Getname/;

perldoc Exporter =>

       Managing Unknown Symbols

       In some situations you may want to prevent certain symbols
       from being exported. Typically this applies to extensions
       which have functions or constants that may not exist on
       some systems.

       The names of any symbols that cannot be exported should be
       listed in the @EXPORT_FAIL array.

       If a module attempts to import any of these symbols the
       Exporter will give the module an opportunity to handle the
       situation before generating an error. The Exporter will
       call an export_fail method with a list of the failed
       symbols:

         @failed_symbols = $module_name->export_fail(@failed_symbols);

       If the export_fail method returns an empty list then no
       error is recorded and all the requested symbols are
       exported. If the returned list is not empty then an error
       is generated for each symbol and the export fails. The
       Exporter provides a default export_fail method which
       simply returns the list unchanged.

       Uses for the export_fail method include giving better
       error messages for some symbols and performing lazy
       architectural checks (put more symbols into @EXPORT_FAIL
       by default and then take them out if someone actually
       tries to use them and an expensive check shows that they
       are usable on that platform).

So, just define:

    sub export_fail {
      my @ret;
      for (@_) {
        if ($_ eq "no_logger") {
          # set no_logger flag somehow
        } else {
          push @ret, $_;
        }
      }
      @ret;
    }

and use the standard Exporter.  No need to subclass.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Sat, 17 Jun 2000 05:03:25 GMT
From: elephant@squirrelgroup.com (jason)
Subject: Re: Ugh
Message-Id: <MPG.13b5a3cf6045708f98973f@news>

Helgi Briem writes ..
>On Wed, 14 Jun 2000 10:26:31 GMT, "Dan" <drshickell@bsu.edu>
>wrote:
>
>>Anyone know any good ways to transport a perl script to a Unix Machine?
>>
>>My main Dev machine is Windows.  So I write my PERL stuff in notepad etc.  I
>>need a way to strip newline characters after transfer or a way to easily
>>edit PERL on a windows box.  Any ideas?
>>
>Try this useful little script which I call
>macorpc2unix:
>
>#!/usr/bin/perl -w -i
>while (<>) {s/\r\n*/\n/g;}
>continue   {print;}

you should add that the above has to be done once over on UNIX otherwise 
there will not be any "\r\n"s in the file as the filehandle was not 
binmoded

don't even know if you can with the <> construct .. if I'm reading the 
(5.005_03) docs correctly the ARGV filehandle doesn't exist until the 
first time the <> is used .. and once it is used it's too late to be 
binmoding it

-- 
 jason - elephant@squirrelgroup.com -


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

Date: Fri, 16 Jun 2000 22:19:54 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Very Strange Behaviour
Message-Id: <Pine.GSO.4.10.10006162218300.21108-100000@user2.teleport.com>

On Sat, 17 Jun 2000, Jacobyte wrote:

> I am running a few web sites out there each with their own cgi-bins on unix
> servers - all scripts work fine and well.
> I am also running 3 personal web servers one on Win98 , one Linux Mandrake
> and one on Corel Linux for the sole purpose of customizing my existing
> scripts on the remote servers. On win98 only %40 work, everything is set up
> ok though while on the linux servers with Apache installed I cannot get any
> to work through the browser - just get the 500 error - most of the scripts
> will execute through bash ok though.
> 
> I know this is a long shot but I desperatley need an offline cgi development
> environment. and am absolutley stuck as to why things are not working esp in
> Linux even though they run on the remote servers. I have check all the usual
> basepaths, permissions etc and everything is ok
> 
> If you have any ideas on this then feel free to throw them at me I will be
> eternaly grateful !

You haven't mentioned anything about Perl. It sounds as if you have a CGI
problem. Perhaps you should search for the docs, FAQs, and newsgroups
about CGI programming.

Of course, if you _are_ using Perl's CGI module, you'll find that you
already have an "offline CGI development environment". Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 16 Jun 2000 21:20:49 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: What is wrong?
Message-Id: <slrn8klkjh.9l5.tadmc@magna.metronet.com>

On Sat, 17 Jun 2000 02:18:47 +0200, Charles W.W. <weiwa592@student.liu.se> wrote:

> Subject: What is wrong?


What is wrong is that you did not put the subject of
your article in the Subject header of your article.


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


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

Date: Fri, 16 Jun 2000 22:49:44 -0700
From: stevel@coastside.net (Steve Leibel)
Subject: Re: Writing line of death to log
Message-Id: <stevel-1606002249440001@192.168.100.2>

In article <8idtag$lg3$1@bcarh8ab.ca.nortel.com>, "Dave McIntyre"
<dem@achilles.net> wrote:

> O Ye of Perl,
> 
> The user wants a log file entry everytime the script dies
> for any reason.
> 
> I'm doing this:
> 
> open(FILE, "file.txt") or print LOG scalar(localtime) . " Line:  Can't open
> $file: $!\n" and die;
> 
> but would like to include the line number it died on. Possible?
> 
> Thanks,
> Dave

Look up caller().


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

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


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