[17851] in Perl-Users-Digest
Perl-Users Digest, Issue: 11 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jan 7 14:10:39 2001
Date: Sun, 7 Jan 2001 11:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <978894309-v10-i11@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 7 Jan 2001 Volume: 10 Number: 11
Today's topics:
Re: -M (Mark Jason Dominus)
Re: CGI error trying to parse <djo22@cornell.edu>
Re: checking/deleting mail duplicates (Tad McClellan)
Connect to WIN2K via perl <rudi_runkel@gmx.de>
Re: Connect to WIN2K via perl <rudi_runkel@gmx.de>
Re: Connect to WIN2K via perl <carvdawg@patriot.net>
Re: Could I remotely zip a file before I get it by FTP (Monte Phillips)
File I/O giving weird results fenderstratocaster@my-deja.com
Re: files in directory (Tad McClellan)
Re: Looking for program html form to cgi nobull@mail.com
Microsoft access <jtjohnston@courrier.usherb.ca>
Re: Microsoft access <a.v.a@home.nl>
Re: multiple setCookies nobull@mail.com
new irc room for perl <a.v.a@home.nl>
Re: Newbie but serious - Problems reading file from mul (Garry Williams)
Re: Perl with MS Access ()
Random Array <oktay@torontonian.com>
Syntac of passing a hash to a subroutine? (Stan Brown)
Re: Syntac of passing a hash to a subroutine? <jhelman@wsb.com>
Re: Syntac of passing a hash to a subroutine? (Stan Brown)
Re: Syntac of passing a hash to a subroutine? (Garry Williams)
Re: Syntac of passing a hash to a subroutine? (Garry Williams)
Re: Syntac of passing a hash to a subroutine? <jhelman@wsb.com>
Re: Syntac of passing a hash to a subroutine? (Stan Brown)
Re: Syntac of passing a hash to a subroutine? <joe+usenet@sunstarsys.com>
Using <> with array element that contains a filehandle <jmwjr@bellsouh.net>
Re: Using <> with array element that contains a filehan (Garry Williams)
Re: Using <> with array element that contains a filehan <jmwjr@bellsouh.net>
Re: Using <> with array element that contains a filehan <nospam.newton@gmx.li>
Re: Version of AS/400 perl. <MAR@kraitor.hh.uunet.de>
Re: What do you call the => operator? (Mark Jason Dominus)
Re: What do you call the => operator? (Ben Okopnik)
Re: What do you call the => operator? <uri@sysarch.com>
Re: xs trouble on Win32 (building Win32::API) <bjoern@hoehrmann.de>
Re: YahooQuote debugging help needed, <jhelman@wsb.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 07 Jan 2001 18:33:05 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: -M
Message-Id: <3a58b642.2dbc$14b@news.op.net>
Keywords: auctioneer, duplicate, timeshare, yeoman
In article <3A54FE5C.164929D8@docuharbor.com>,
Todd Anderson <test31@docuharbor.com> wrote:
>Anyone know what this does?
Yes.
>Thanks in advance.
You're welcome.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f|ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Sun, 7 Jan 2001 13:08:42 -0500
From: "Dan O'Connor" <djo22@cornell.edu>
Subject: Re: CGI error trying to parse
Message-Id: <93abbg$3jt$1@news01.cit.cornell.edu>
Hello,
Yes, I have the HTML::Parser statement before I create an instance of
the package. My first couple lines are the following...
# Packages to retrieve the URL using HTTP
use LWP::Simple;
use CGI;
# Used to parse HTML from the web server
use HTML::Parser();
use strict;
I'm pretty sure my script should work because it works on different servers.
When I asked my server what they thought, they just told me:
We use ActiveState Perl. you can go to www.ActiveState.com
and that was that. Is ActiveState much different?
Thanks a lot,
Dan
Bjoern Hoehrmann <bjoern@hoehrmann.de> wrote in message
news:3a665bec.9466421@news.bjoern.hoehrmann.de...
> * Dan O'Connor wrote in comp.lang.perl.misc:
> > I'm trying to parse other web pages with my page, but I'm getting the
> >following error:
> >
> >CGI Error
> >The specified CGI application misbehaved by not returning a complete set
of
> >HTTP headers. The headers it did return are:
> >Can't locate object method "handler" via package "HTML::Parser" at
> >D:\WWW\...\getweather.pl line 155.
>
> Are you sure you've got a
>
> use HTML::Parsser;
>
> statement before you create an instance of the package? Are you using
> CGI.pm and do you print any headers, i.e.
>
> use CGI ':standard';
> print header;
> print "<p>Hello CGI-World</p>";
>
> You script does not run from the command line, does it? I hope you
> aren't debugging your scripts in your browser...
> --
> Bjrn Hhrmann ^ mailto:bjoern@hoehrmann.de ^ http://www.bjoernsworld.de
> am Badedeich 7 Telefon: +49(0)4667/981028 http://bjoern.hoehrmann.de
> 25899 Dagebll # PGP Pub. KeyID: 0xA4357E78 # http://learn.to/quote [!]e
> "I am told that God is in these newsgroups. Does he post here often ?"
------------------------------
Date: Sun, 7 Jan 2001 07:26:38 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: checking/deleting mail duplicates
Message-Id: <slrn95go3u.6ct.tadmc@magna.metronet.com>
matthias tarasiewicz <t@inode.at> wrote:
>> Get the MailTools package from CPAN,
^^^^^^^^^
>very good! where can f find those modules?
Errr, how about on CPAN?
'perldoc' is a program that ships witht the perl distribution
that can look stuff up in the standard documentation that also
ships with perl. The -q option is used to search Perl's
Frequently Asked Questions:
perldoc -q CPAN
"What modules and extensions are available for Perl? What
is CPAN? What does CPAN/src/... mean?"
"How do I install a module from CPAN?"
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 7 Jan 2001 18:11:57 +0100
From: "Rudi Runkel" <rudi_runkel@gmx.de>
Subject: Connect to WIN2K via perl
Message-Id: <93a802$j5m$03$1@news.t-online.com>
Hi all,
is there a possibility to connect myself to a windows NT or 2K box from my
linux server to check, if a process is still running or if there is still
enough diskspace?
Thanks for your help
rudi
------------------------------
Date: Sun, 7 Jan 2001 18:34:22 +0100
From: "Rudi Runkel" <rudi_runkel@gmx.de>
Subject: Re: Connect to WIN2K via perl
Message-Id: <93a9a4$kf3$03$1@news.t-online.com>
> is there a possibility to connect myself to a windows NT or 2K box from my
> linux server to check, if a process is still running or if there is still
> enough diskspace?
of course by using perl
------------------------------
Date: Sun, 07 Jan 2001 14:01:40 -0500
From: H C <carvdawg@patriot.net>
Subject: Re: Connect to WIN2K via perl
Message-Id: <3A58BD14.B149CBD5@patriot.net>
> > is there a possibility to connect myself to a windows NT or 2K box from my
> > linux server to check, if a process is still running or if there is still
> > enough diskspace?
>
> of course by using perl
Using Net::Telnet, you can connect from Linux to Terminal Server on 2k, or to a
telnet server that you've installed on NT. There are several ways to get this
information
when going from NT to NT, but not Linux to NT/2K...unless you install
ActiveState Perl
and VMWare on Linux...
------------------------------
Date: Sun, 07 Jan 2001 16:24:56 GMT
From: montep@hal-pc.org (Monte Phillips)
Subject: Re: Could I remotely zip a file before I get it by FTP
Message-Id: <3a58971f.24713556@news.hal-pc.org>
On 7 Jan 2001 10:27:55 GMT, abigail@foad.org (Abigail) wrote:
>Monte Phillips (montep@hal-pc.org) wrote on MMDCLXXXV September MCMXCIII
>in <URL:news:3a57781a.20805036@news.hal-pc.org>:
>^^ On 6 Jan 2001 18:54:07 GMT, abigail@foad.org (Abigail) wrote:
>^^
>^^ >Regent Linus (wstsoi@netvigator.com) wrote on MMDCLXXXV September
>^^ >MCMXCIII in <URL:news:937egf$kpg3@imsp212.netvigator.com>:
>^^ >^^ How could perl do this?
>^^ >
>^^ >There are various ways. You could use UUCP to give a remote command.
>^^ >Or you could NSF mount the drive the file is on, then zip it. Or
>^^ >install (write?) an FTP server that zips on the fly. Perl doesn't
>^^ >really play much of a role in all of this though.
>^^ >Abigail
>^^
>^^ I beg your pardon? why not system() and zip or tarball the thing?
>
>
>And which command do you propose to use for this zipping on a remote
>system?
>Abigail
For crying out loud! If the OP wants to compress and transfer a file
from a remote location it is assumed (by optimists) that the OP is
intelligent enough to know they would need certain permissions on that
remote system. If they are so ignorant of that, then whats the point
of wasting any bandwidth telling them anything at all?
And except for your natural perversity and perpetual PMS, you would
have pointed that out to the guy. Albeit I admit that if he were so
aware of the permissions issue, then he would also be expected to
know about such things as tar, gzip, pkzip or wahtever compression
program resides on the remote system.
Or are you telling me that you could not run a script remotely that
would call tar?
------------------------------
Date: Sun, 07 Jan 2001 16:57:00 GMT
From: fenderstratocaster@my-deja.com
Subject: File I/O giving weird results
Message-Id: <93a74q$okd$1@nnrp1.deja.com>
Hi everyone.
I'm trying to write a simple program. What should happen is when you
run the program, you should get a prompt. At the prompt you would enter
in a number. Perl should then add that number to the end of the file (I
want the numbers to be added like 1, 2, 3, 4 - with the number, a
comma, and then a space).
If you add numbers out of sequence, or numeric order, then I want the
program to take the whole file into an array, sort them out, then write
over the file with the numbers in order.
Here is my code:
1. #!/usr/bin/perl -w
3. open(FREECELL, ">>C:/My Documents/freecell.txt") || die "$!";
5. print "Enter the game number here: ";
6. $gamenumber = <STDIN>;
7. chomp $gamenumber;
9. print FREECELL "$gamenumber";
10.print FREECELL ", ";
11.$text = <FREECELL>;
12.close(FREECELL);
14.@array = split(', ', $text);
16.@array = sort { $a<=>$b; } @array;
18.open(FREECELL, ">C:/My Documents/freecell.txt") || die "$!";
20.print FREECELL "@array";
21.close(FREECELL);
I first wrote this program and just appeneded numbers on the end of the
file and it worked fine. But I just had to mess with it an make it more
sophisticated and now I'm running into trouble. When I run the program,
it writes what you see below to freecell.txt:
6 :
t` < b @| @| @| @| s r s r r r u
And sometimes I'll even see #!usr/bin/perl -w written in there as
well...seems very weird to me. Can anyone help me find out what is
wrong with my script?
Thank you,
FenderStratocaster.
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Sun, 7 Jan 2001 07:34:59 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: files in directory
Message-Id: <slrn95gojj.6fi.tadmc@magna.metronet.com>
snef <snef@soneramail.nl> wrote:
>Only one problem here.....
>
>How do I let directories out of the foreach loop? I only want to select
>files.
perldoc -f -d
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 07 Jan 2001 15:46:18 +0000
From: nobull@mail.com
Subject: Re: Looking for program html form to cgi
Message-Id: <u93devpdpx.fsf@wcl-l.bham.ac.uk>
rich@mrinter.net (Hosehead) writes:
> Newsgroups: comp.lang.perl.misc
> Looking for a windows program...
You have stumbled into the wrong newgroup. This is
comp.lang.perl.misc, here we discuss issues relating to the computer
programming language Perl that don't fit elsewhere in the
comp.lang.perl hierachy.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Sun, 07 Jan 2001 11:46:11 -0500
From: jtjohnston <jtjohnston@courrier.usherb.ca>
Subject: Microsoft access
Message-Id: <3A589D52.AFB6F9B3@courrier.usherb.ca>
I am an educational programmer. I use a text file from which I generate
multiple choice questions:
1||how ___ you?||am|are||is||0||1||0
2||how ___ he?||am|are||is||0||0||1
3||how ___ we?||am|are||is||0||1||0
I have a friend who uses php instead of Perl and is able to read his
questions from a Microsoft (97?) access file. Can we do that in Perl?
How? is it pretty much the same as this below? Do I need more *.pm or
something?
This is what I use. What would I do differently? Does anyone have
something I can play with or hack around?
open(QUESTIONSFILE, "$datafile") || die "I can't open $datafile\n";
@Questions = <QUESTIONSFILE>;
close QUESTIONSFILE;
foreach $ThisQuestion (@Questions)
{
@TempData = split (/\|\|/, $ThisQuestion);
print "<TR>\n";
print "<TD><B>$TempData[0]</B></TD><TD
COLSPAN=2><B>$TempData[1]</B></TD>";
print "</TR>\n";
#--snip--
}
Thanks,
John
P.S.
A email reply would come in real handy.
------------------------------
Date: Sun, 07 Jan 2001 18:35:20 GMT
From: AvA <a.v.a@home.nl>
Subject: Re: Microsoft access
Message-Id: <3A58B86D.B9359E54@home.nl>
jtjohnston wrote:
> I am an educational programmer. I use a text file from which I generate
> multiple choice questions:
>
> 1||how ___ you?||am|are||is||0||1||0
> 2||how ___ he?||am|are||is||0||0||1
> 3||how ___ we?||am|are||is||0||1||0
>
> I have a friend who uses php instead of Perl and is able to read his
> questions from a Microsoft (97?) access file. Can we do that in Perl?
> How? is it pretty much the same as this below? Do I need more *.pm or
> something?
>
> This is what I use. What would I do differently? Does anyone have
> something I can play with or hack around?
>
> open(QUESTIONSFILE, "$datafile") || die "I can't open $datafile\n";
> @Questions = <QUESTIONSFILE>;
> close QUESTIONSFILE;
>
> foreach $ThisQuestion (@Questions)
> {
> @TempData = split (/\|\|/, $ThisQuestion);
> print "<TR>\n";
use : print "<TR><br>"; #instead of \n -> i presume that ur using it in a
html context
>
> print "<TD><B>$TempData[0]</B></TD><TD
> COLSPAN=2><B>$TempData[1]</B></TD>";
> print "</TR>\n";
> #--snip--
> }
>
> Thanks,
> John
> P.S.
> A email reply would come in real handy.
------------------------------
Date: 07 Jan 2001 15:35:30 +0000
From: nobull@mail.com
Subject: Re: multiple setCookies
Message-Id: <u966jrpe7x.fsf@wcl-l.bham.ac.uk>
steve a <sarbayo@telis.org> writes:
> On Sat, 6 Jan 2001 23:23:29 +0100, "Msl Roland" <founder@pege.org>
> wrote:
> :"steve a" <sarbayo@telis.org> wrote in message
> :news:3a57977c.9653618@news.inreach.com...
> :> Q:
> :> using Perl,
There is yuor mistake, you are asking "using Perl" when you need to
think "funadmentally". Time travel is impossible - in any language.
> 1) to determine if cookies are enables on the browser, by sending
> a "dummy" cookie and then reading it,
> 2) If cookies are enabled, set a real cookie.
> As I stated:
> #pseudo code:
> #set a dummy cookie
> print header(-cookie=>[$cookie1]);
>
> #next, test if cookies are "on" by fetching the dummy
> %cookies = fetch CGI::Cookie;
> if(! %cookies) {
> #do plan "B"
> #indicate cookies are "off"
> } else {
> #do plan "A"
> #set a valid cookie
> }
You are forgetting the transactional nature of HTTP. A single HTTP
transaction is err... well... how shall I put this... a single
transaction. There is no way for the processing of a single HTTP
tranastion to observe effects that are dependant on the outcome of the
transaction.
This has nothing whatever to do wiht Perl.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Sun, 07 Jan 2001 17:57:48 GMT
From: AvA <a.v.a@home.nl>
Subject: new irc room for perl
Message-Id: <3A58AFA1.E77AF831@home.nl>
we created a new irc room for perl:
irc.chatjunkies.org port 6667 #perl
for everyone to discuss perl or anything else
it is not (yet) a helpchannel
------------------------------
Date: Sun, 07 Jan 2001 14:37:32 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: Newbie but serious - Problems reading file from multipart forms (no binmode!) (repost)
Message-Id: <Ma%56.3560$UQ5.9331@eagle.america.net>
On 06 Jan 2001 18:00:01 -0500, Joe Schaefer
<joe+usenet@sunstarsys.com> wrote:
>garry@zvolve.com (Garry Williams) writes:
>> On 06 Jan 2001 14:45:38 -0500, Joe Schaefer
>> <joe+usenet@sunstarsys.com> wrote:
>>
>> I don't know what you expected to happen. $fileName is tainted. You
>> didn't untaint it.
>
>*That* is the point - had OP enabled taint checks, his code
>never would have run.
I didn't see that *that* was your point. I get it, now. MJD
admonished me, too. :-(
--
Garry Williams
------------------------------
Date: Sun, 07 Jan 2001 07:27:04 GMT
From: jwillmore@cyberia.com ()
Subject: Re: Perl with MS Access
Message-Id: <cTU56.8023$O82.360939@nntp3.onemain.com>
If you find a way to do this, let me know. I gave up from frustration. Same deal. The only thing I haven't tried is using the dbiproxy to connect, but that appears to need two machines. I have two, just no ambition to mess with it.
Most "modern" databases are server based (ie Oracle, MySQL, Postgres, etc.). The old "flat file" databases and psuedo-databases (ie Access) are self-contained. So, most of the development for the DBI module is geared towards server-based db's. Although there are drivers/modules to connect to "flat file" databases.
You can connect from within a Win32 machine by setting up an ODBC connection - but it sounds like you've been there, done that and not really what you want to do. :-(
Good Luck and if you find out anything, let me know.
Jim
In article <38C462C3.AA65602E@npv.com>,
Ruben Fagundo <ruben@npv.com> writes:
> I would like to write an application on a Linux box in Perl that would
> open a Microsoft Access Database (.mdb) and reads certain information
> from it, much like one opens and reads any file.
>
> The Access Database is sitting locally, and I have all the perl tools
> and modules at my disposal. I have been looking for a way to do this,
> and everyone keeps pointing to DBD::ODBC. However, it seems that this
> approach assumes that the database is sitting on a Microsoft box. I
> have the database sitting locally, so I just need to read it.
>
> Does this suggest that the in order to read the MS Access DB, I need to
> have it on a Microsoft box, and then run ODBC over to it.
>
> Also when compiling DBD::ODBC, it looks for an ODBC Manager, which I
> don't have. I could install the ODBC to ODBC Bridge, but that doesn't
> sound like what I need.
>
> Any suggestions would be appreciated.
>
>
--
_ _ __ ___ _ _
| (_)_ __ ___ \ \ / (_) | |_ __ ___ ___ _ __ ___
_ | | | '_ ` _ \ \ \ /\ / /| | | | '_ ` _ \ / _ \| '__/ _ \
| |_| | | | | | | | \ V V / | | | | | | | | | (_) | | | __/
\___/|_|_| |_| |_| \_/\_/ |_|_|_|_| |_| |_|\___/|_| \___|
___ ____ _ ____ _ _
/ _ \ _ __ ___ _ __ / ___| / \ / ___|(_) __ _ _ __ ___ __| |
| | | | '_ \ / _ \ '_ \| | / _ \ \___ \| |/ _` | '_ \ / _ \/ _` |
| |_| | |_) | __/ | | | |___ / ___ \ ___) | | (_| | | | | __/ (_| |
\___/| .__/ \___|_| |_|\____/_/ \_\ |____/|_|\__, |_| |_|\___|\__,_|
|_| |___/
------------------------------
Date: Sun, 07 Jan 2001 18:24:18 GMT
From: Oktay <oktay@torontonian.com>
Subject: Random Array
Message-Id: <3A58B46E.2BC369A0@torontonian.com>
Hello,
I modified below random images script so that it plays each time a
random real audio file.
My perl is not good at all and now what I want to do is create a script
that looks into a folder checks all the *.ra, *.rm files and writes them
into a text file(which I will rename it as *.ram) that will list all the
*.ra, *.rm files to show up in this random order
http://localhost/muzik/1.ra
http://localhost/muzik/6.rm
http://localhost/muzik/4.rm
http://localhost/muzik/3.ra
http://localhost/muzik/5.ra
http://localhost/muzik/2.rm
etc. So when I put this cgi script into the cron each day I have a
different playlist.
I know it must be a very easy script to write but unfortunately I know
no perl at all
I thank you all in advance
Regards
John Oz
######################### CODE STARTS HERE #########################
#!perl -w
$| = 1;BEGIN {
open (STDERR, ">/error.txt");
}
$IMG_DIR = "F:/home/htdocs/muzik";
$VIRTUAL_DIR = "http://localhost/muzik";
######################
# Read the selected DIR and
# put all image files into an array
######################
print "Content-type: audio/x-pn-realaudio\n\n";
opendir(DOT,"$IMG_DIR")| | &error ("Cannot Open $IMG_DIR");
foreach (sort readdir(DOT))
{
$file = $_;
if (($file =~ /.rm/) | | ($file =~ /.RA/) | | ($file =~ /.RAM/) | |
($file =~ /.ra/) )
{ push (@dir_list, "$file");
}
}
closedir(DOT);
################################
# Pick a number, any number 8*)
################################
srand(time ^ $$);
$IMG_NUM = rand(@dir_list);
###################################
# load the image.
###################################
print "$VIRTUAL_DIR/$dir_list[$IMG_NUM]\n";
------------------------------
Date: 7 Jan 2001 11:17:15 -0500
From: stanb@panix.com (Stan Brown)
Subject: Syntac of passing a hash to a subroutine?
Message-Id: <93a4qb$6nq$1@panix2.panix.com>
I have wrinte a subroutine which I use to obtain a key from a database
table contiang key value pairs.
Now I need for it to be able to handle optional fileds.
I have defined this subroutine linke this:
foo($$$$)
And now I need to do something like:
foor($$$$%) {
my $val1 = $_[0];
my $val2 = $_[1];
my $val3 = $_[2];
my $val4 = $_[3];
my %hash = $_[4];
I have read man perlsub, but I'm still drawing a blank here.
How can I do this?
------------------------------
Date: Sun, 07 Jan 2001 16:40:23 GMT
From: Jeff Helman <jhelman@wsb.com>
Subject: Re: Syntac of passing a hash to a subroutine?
Message-Id: <av6h5to92s2uusgosaqukbngqieepc3eks@4ax.com>
On 7 Jan 2001 11:17:15 -0500, stanb@panix.com (Stan Brown) wrote:
>foor($$$$%) {
>
>my $val1 = $_[0];
>my $val2 = $_[1];
>my $val3 = $_[2];
>my $val4 = $_[3];
>my %hash = $_[4];
Instead, try this...
my $val1 = shift;
my $val2 = shift;
my $val3 = shift;
my $val4 = shift;
my %hash = @_;
JH
------------------------------
Date: 7 Jan 2001 12:38:16 -0500
From: stanb@panix.com (Stan Brown)
Subject: Re: Syntac of passing a hash to a subroutine?
Message-Id: <93a9i8$c7e$1@panix2.panix.com>
In <av6h5to92s2uusgosaqukbngqieepc3eks@4ax.com> Jeff Helman <jhelman@wsb.com> writes:
>On 7 Jan 2001 11:17:15 -0500, stanb@panix.com (Stan Brown) wrote:
>>foor($$$$%) {
>>
>>my $val1 = $_[0];
>>my $val2 = $_[1];
>>my $val3 = $_[2];
>>my $val4 = $_[3];
>>my %hash = $_[4];
>Instead, try this...
>my $val1 = shift;
>my $val2 = shift;
>my $val3 = shift;
>my $val4 = shift;
>my %hash = @_;
Thanks.
I'm afraid that i have totaly confused myself at this point in time, having
tried _way_ to many things in the last couple of hours to get this to wrok.
Here's what I have:
I declare the subroutine as:
sub get_key($$$$%) {
My assignments within it now look like:
my $key_col = shift;
my $val_col = shift;
my $table = shift;
my $value = shift;
my %test = @_;
And finally here is a typical call:
get_key(
'type_id',
'type',
'TYPE',
$alarm_data{TYPE},
+{ 'key' => 'value'} ),
And here is the current error message:
Reference found where even-sized list expected at ./new.pl line 111.
What am I doing wrong?
------------------------------
Date: Sun, 07 Jan 2001 17:42:13 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: Syntac of passing a hash to a subroutine?
Message-Id: <VT166.3583$UQ5.10805@eagle.america.net>
On 7 Jan 2001 11:17:15 -0500, Stan Brown <stanb@panix.com> wrote:
>I have wrinte a subroutine which I use to obtain a key from a database
>table contiang key value pairs.
>
>Now I need for it to be able to handle optional fileds.
>
>I have defined this subroutine linke this:
>
>foo($$$$)
>
>And now I need to do something like:
>
>foor($$$$%) {
>
>my $val1 = $_[0];
>my $val2 = $_[1];
>my $val3 = $_[2];
>my $val4 = $_[3];
>my %hash = $_[4];
>
>I have read man perlsub, but I'm still drawing a blank here.
The first page of perlsub gives the answer:
The Perl model for function call and return values is
simple: all functions are passed as parameters one single
flat list of scalars, ...
Any arrays or
hashes in these call ... lists will collapse, losing
their identities--but you may always use pass-by-reference
instead to avoid this.
So, you can do one of the following:
#!/usr/local/bin/perl -l
use strict;
use warnings;
sub foo_1 ($$$$%) {
my ($val1, $val2, $val3, $val4, %options) = @_;
#...
print $options{file_name};
}
sub foo_2 ($$$$\%) {
my ($val1, $val2, $val3, $val4, $opt_ref) = @_;
#...
print $opt_ref->{file_name};
}
sub foo_3 {
my ($val1, $val2, $val3, $val4, $opt_ref) = @_;
#...
print $opt_ref->{file_name};
}
my %option_hash = ( file_name => 'test');
foo_1(1, 2, 3, 4, (file_name => 'test'));
foo_2(1, 2, 3, 4, %option_hash);
foo_3(1, 2, 3, 4, { file_name => 'test' });
foo_3(1, 2, 3, 4, \%option_hash);
__END__
I think the prototyped version is too restrictive and tend to use the
third example instead (*documenting* the interface, of course).
--
Garry Williams
------------------------------
Date: Sun, 07 Jan 2001 17:55:16 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: Syntac of passing a hash to a subroutine?
Message-Id: <84266.3584$UQ5.10805@eagle.america.net>
On 7 Jan 2001 12:38:16 -0500, Stan Brown <stanb@panix.com> wrote:
>In <av6h5to92s2uusgosaqukbngqieepc3eks@4ax.com> Jeff Helman
><jhelman@wsb.com> writes:
>>On 7 Jan 2001 11:17:15 -0500, stanb@panix.com (Stan Brown) wrote:
[snip]
>I'm afraid that i have totaly confused myself at this point in time,
>having tried _way_ to many things in the last couple of hours to get
>this to wrok.
>
>Here's what I have:
>
>I declare the subroutine as:
>
>sub get_key($$$$%) {
>
>My assignments within it now look like:
>
>my $key_col = shift;
>my $val_col = shift;
>my $table = shift;
>my $value = shift;
>my %test = @_;
>
>And finally here is a typical call:
>
> get_key(
> 'type_id',
> 'type',
> 'TYPE',
> $alarm_data{TYPE},
> +{ 'key' => 'value'} ),
>
>And here is the current error message:
>
>Reference found where even-sized list expected at ./new.pl line 111.
>
>What am I doing wrong?
Your prototype says you require a hash as the fifth parameter and you
passed in a hash _reference_ instead (actually a reference to an
anonymous hash). Also, the `+' is unnecessary. You would correct
this by passing the hash -- not the reference to the hash:
get_key(
'type_id',
'type',
'TYPE',
$alarm_data{TYPE},
('key' => 'value')
),
Or simply:
get_key(
'type_id',
'type',
'TYPE',
$alarm_data{TYPE},
'key' => 'value'
),
The perlsub manual page talks about the "flattening" of the parameter
list. So the hash is simply a (even numbered) list of scalars.
See my other follow-up for the way to use a reference.
--
Garry Williams
------------------------------
Date: Sun, 07 Jan 2001 17:56:25 GMT
From: Jeff Helman <jhelman@wsb.com>
Subject: Re: Syntac of passing a hash to a subroutine?
Message-Id: <l4bh5t8jve0mt12ijuvj71eqep3o7u9glj@4ax.com>
On 7 Jan 2001 12:38:16 -0500, stanb@panix.com (Stan Brown) wrote:
>And finally here is a typical call:
>
> get_key(
> 'type_id',
> 'type',
> 'TYPE',
> $alarm_data{TYPE},
> +{ 'key' => 'value'} ),
>
>
>And here is the current error message:
>
>Reference found where even-sized list expected at ./new.pl line 111.
>
>What am I doing wrong?
You are passing a hash reference rather than a hash. Given the way
you set up your script, just add the key-value pairs to the end of
your call and they will get put into your hash automatically.
So use
get_key('type_id', 'type', 'TYPE', $alarm_data{TYPE}, 'key' =>
'value');
And then you can add additional keys and values later just by
appending them to the end of the list.
Alternatively, you could pass the hash by reference (as you are doing
above, though the plus sign serves no useful purpose). The only
change you would need to make then is that any calls to the values of
your hash inside get_key must be dereferenced.
Read the perlreftut and perlref pages in the docs for a better
understanding of working with and passing references around.
JH
------------------------------
Date: 7 Jan 2001 13:29:36 -0500
From: stanb@panix.com (Stan Brown)
Subject: Re: Syntac of passing a hash to a subroutine?
Message-Id: <93acig$g25$1@panix2.panix.com>
In <l4bh5t8jve0mt12ijuvj71eqep3o7u9glj@4ax.com> Jeff Helman <jhelman@wsb.com> writes:
>On 7 Jan 2001 12:38:16 -0500, stanb@panix.com (Stan Brown) wrote:
>>And finally here is a typical call:
>>
>> get_key(
>> 'type_id',
>> 'type',
>> 'TYPE',
>> $alarm_data{TYPE},
>> +{ 'key' => 'value'} ),
>>
>>
>>And here is the current error message:
>>
>>Reference found where even-sized list expected at ./new.pl line 111.
>>
>>What am I doing wrong?
>You are passing a hash reference rather than a hash. Given the way
>you set up your script, just add the key-value pairs to the end of
>your call and they will get put into your hash automatically.
>So use
>get_key('type_id', 'type', 'TYPE', $alarm_data{TYPE}, 'key' =>
>'value');
Thanks very much for all the insightfule, helpful, and quick, replieson
this.
Hopefully, I will be able to help some others in the future.
------------------------------
Date: 07 Jan 2001 13:42:31 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Syntac of passing a hash to a subroutine?
Message-Id: <m3lmsn19wo.fsf@mumonkan.sunstarsys.com>
stanb@panix.com (Stan Brown) writes:
> Here's what I have:
>
> I declare the subroutine as:
>
> sub get_key($$$$%) {
>
> My assignments within it now look like:
>
> my $key_col = shift;
> my $val_col = shift;
> my $table = shift;
> my $value = shift;
> my %test = @_;
my ($key_col, $val_col, $table, $value, %test) = @_;
> And finally here is a typical call:
>
> get_key(
> 'type_id',
> 'type',
> 'TYPE',
> $alarm_data{TYPE},
> +{ 'key' => 'value'} ),
^^ ^
Brackets create an anonymous hash here, and return a ref
to it. Drop the + sign and try it again using plain-old
parentheses (or leave them out altogether).
> And here is the current error message:
>
> Reference found where even-sized list expected at ./new.pl line 111.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Often times just following the recommended fix will
do the trick.
HTH
--
Joe Schaefer
------------------------------
Date: Sun, 7 Jan 2001 11:34:40 -0500
From: "Mike Wilson" <jmwjr@bellsouh.net>
Subject: Using <> with array element that contains a filehandle
Message-Id: <I6166.68$gN3.8162@news1.atl>
I am stroring filehandles in an array,
$read[$i] = new IO::Handle();
$write[$i] = new IO::Handle();
open2($read[$i], $write[$i], 'perl echo.pl -');
$i++;
I can reference the write for printing as follow
print { $write[$i] } "Stuff";
but when trying to read the read[$i] filehandle in this format it doesnt
compile.
while (<$read[$i]>) { print "doesnt compile"; }
or this way fails to read
while (<{ $read[$i] }>) { print "fails"; }
I have stored the filehandle in a temp variable as follows and it works.
my $read=$read[$i];
while (<$read>) { print "Itworks"; }
Any ideas, I would like to get rid of the temp variable.
Thanks Mike W.
------------------------------
Date: Sun, 07 Jan 2001 17:14:16 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: Using <> with array element that contains a filehandle
Message-Id: <It166.3576$UQ5.10550@eagle.america.net>
On Sun, 7 Jan 2001 11:34:40 -0500, Mike Wilson <jmwjr@bellsouh.net> wrote:
>I am stroring filehandles in an array,
[snip]
>but when trying to read the read[$i] filehandle in this format it doesnt
>compile.
>while (<$read[$i]>) { print "doesnt compile"; }
>
>or this way fails to read
>while (<{ $read[$i] }>) { print "fails"; }
[snip]
>Any ideas, I would like to get rid of the temp variable.
Sorry. From the perlop manual page:
If angle brackets contain is a simple scalar variable (e.g.,
<$foo>), then that variable contains the name of the
filehandle to input from, or its typeglob, or a reference to
the same. For example:
$fh = \*STDIN;
$line = <$fh>;
If what's within the angle brackets is neither a filehandle
nor a simple scalar variable containing a filehandle name,
typeglob, or typeglob reference, it is interpreted as a
filename pattern to be globbed, and either a list of
filenames or the next filename in the list is returned,
depending on context. This distinction is determined on
syntactic grounds alone. That means `<$x>' is always a
readline() from an indirect handle, but `<$hash{key}>' is
always a glob(). That's because $x is a simple scalar
variable, but `$hash{key}' is not--it's a hash element.
--
Garry Williams
------------------------------
Date: Sun, 7 Jan 2001 12:14:31 -0500
From: "Mike Wilson" <jmwjr@bellsouh.net>
Subject: Re: Using <> with array element that contains a filehandle
Message-Id: <3I166.76$gN3.9068@news1.atl>
Thanks Gray, Ive was just reading through the same doc.
I'v been trying to come up with something using a readline, but it is ending
up
alot uglier than just using a temp variable.
Thanks again
------------------------------
Date: Sun, 07 Jan 2001 18:52:25 +0100
From: "Philip 'Yes, that's my address' Newton" <nospam.newton@gmx.li>
Subject: Re: Using <> with array element that contains a filehandle
Message-Id: <u4ah5t457384s7pkitkfj46qh2g9ohfcli@4ax.com>
On Sun, 7 Jan 2001 11:34:40 -0500, "Mike Wilson" <jmwjr@bellsouh.net> wrote:
> but when trying to read the read[$i] filehandle in this format it doesnt
> compile.
> while (<$read[$i]>) { print "doesnt compile"; }
Funny, that compiles for me (5.005_03). It probably doesn't do what you want,
though.
> or this way fails to read
> while (<{ $read[$i] }>) { print "fails"; }
So should the version above.
> I have stored the filehandle in a temp variable as follows and it works.
> my $read=$read[$i];
> while (<$read>) { print "Itworks"; }
>
> Any ideas, I would like to get rid of the temp variable.
RTFM. Specifically, `perldoc perlop`, s.v. 'I/O Operators':
: If the string inside the angle brackets is a reference to a
: scalar variable (e.g., <$foo>), then that variable contains the
: name of the filehandle to input from, or its typeglob, or a
: reference to the same. For example:
:
: $fh = \*STDIN;
: $line = <$fh>;
This is what allowed your "while (<$read>)" to work. But wait! There's more:
: If what's within the angle brackets is neither a filehandle nor
: a simple scalar variable containing a filehandle name, typeglob,
: or typeglob reference, it is interpreted as a filename pattern
: to be globbed, and either a list of filenames or the next
: filename in the list is returned, depending on context. This
: distinction is determined on syntactic grounds alone. That means
: `<$x>' is always a readline from an indirect handle, but
: `<$hash{key}>' is always a glob. That's because $x is a simple
: scalar variable, but `$hash{key}' is not--it's a hash element.
So <$read[$i]> is not readline but rather glob. (B::Deparse would have told you
so, as well. B::Deparse is (often) your friend.) Unfortunately, this place of
the manual doesn't tell you how to use something other than a simple scalar
variable as a file handle to read a line from. However, a few paragraphs further
up, we can see:
: <FILEHANDLE> may also be spelt readline(FILEHANDLE). See the
: "readline" entry in the perlfunc manpage.
I'll leave it up to you to "See the 'readline' entry in the perlfunc manpage"
and to proceed from here. Enjoy!
(Note that in quick testing, the argument of readline() couldn't contain the
name of a filehandle or a reference to a typeglob, only a plain typeglob. Not
sure whether IO::Handle objects would work here. So $read[$i] = *DATA works, but
\*DATA and 'DATA' didn't. Again, this is 5.005_03.)
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: Sun, 7 Jan 2001 18:48:50 +0100
From: "Elisaweta" <MAR@kraitor.hh.uunet.de>
Subject: Re: Version of AS/400 perl.
Message-Id: <3a58ac22$0$8783$73bec562@personalnews.de.uu.net>
Perl Version 5.005
http://www.as400.ibm.com/tstudio/workshop/tiptools/perl.htm
ftp://ftp.plig.org/pub/CPAN/ports/as400/
RGDS,
Elisaweta
Andre Lacroix <lacroix_andre@emc.com> schrieb in im Newsbeitrag:
935gft$kbj5@emcnews1.lss.emc.com...
> Can anyone tell me what AS/400 version the perl savf was created under
from
> CPAN sites?
>
> Thanks.
>
>
------------------------------
Date: Sun, 07 Jan 2001 15:23:16 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: What do you call the => operator?
Message-Id: <3a5889e3.296c$2b6@news.op.net>
In article <x7u27b7qin.fsf@home.sysarch.com>,
Uri Guttman <uri@sysarch.com> wrote:
>well, most perl hackers call it fat comma.
I never heard that in my life, and it isn't in the manual.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f|ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: 7 Jan 2001 17:30:57 GMT
From: ben-fuzzybear@geocities.com (Ben Okopnik)
Subject: Re: What do you call the => operator?
Message-Id: <slrn95ha1e.d3m.ben-fuzzybear@Odin.Thor>
The ancient archives of Sun, 07 Jan 2001 15:23:16 GMT showed
Mark Jason Dominus of comp.lang.perl.misc speaking thus:
>In article <x7u27b7qin.fsf@home.sysarch.com>,
>Uri Guttman <uri@sysarch.com> wrote:
>>well, most perl hackers call it fat comma.
>
>I never heard that in my life, and it isn't in the manual.
38 relevant refs on Google from an "omitted results" search for '"fat
comma" Perl', all from Perl-Users Digest. Seems like relatively common
usage there, at least.
Ben Okopnik
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
The penalty for laughing in a courtroom is six months in jail; if it were
not for this penalty, the jury would never hear the evidence.
-- H. L. Mencken
------------------------------
Date: Sun, 07 Jan 2001 18:26:18 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: What do you call the => operator?
Message-Id: <x7g0iv6wxg.fsf@home.sysarch.com>
>>>>> "MJD" == Mark Jason Dominus <mjd@plover.com> writes:
MJD> In article <x7u27b7qin.fsf@home.sysarch.com>,
MJD> Uri Guttman <uri@sysarch.com> wrote:
>> well, most perl hackers call it fat comma.
MJD> I never heard that in my life, and it isn't in the manual.
well, i didn't invent it and i have heard many others use it. it is not
official but is has become a nickname of sorts and it is spreading.
deja has 55 hits on fat comma in the perl groups since may 99. some
mention it in the subject.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Sun, 07 Jan 2001 18:50:39 +0100
From: Bjoern Hoehrmann <bjoern@hoehrmann.de>
Subject: Re: xs trouble on Win32 (building Win32::API)
Message-Id: <3a5eaa9b.31678721@news.bjoern.hoehrmann.de>
* Soren Andersen wrote in comp.lang.perl.misc:
>I am trying to compile the module Win32::API (http://dada.perl.it/) on WinNT4
>sp6 using MinGW - gcc-2.95.2.1 and having a rough go of it with the xs code.
>The compilation fails because this code has an undeclared identifier:
>Anybody (perhaps familiar with xs and Win32/MSVC++) got any insights?
Well, I tried to build it with VC++ 6.0 and got
API.xs(155) : error C2065: 'na' : undeclared identifier
I asked the author what to do about it and got no response yet.
--
Bjrn Hhrmann ^ mailto:bjoern@hoehrmann.de ^ http://www.bjoernsworld.de
am Badedeich 7 Telefon: +49(0)4667/981028 http://bjoern.hoehrmann.de
25899 Dagebll # PGP Pub. KeyID: 0xA4357E78 # http://learn.to/quote [!]e
"I am told that God is in these newsgroups. Does he post here often ?"
------------------------------
Date: Sun, 07 Jan 2001 15:32:46 GMT
From: Jeff Helman <jhelman@wsb.com>
Subject: Re: YahooQuote debugging help needed,
Message-Id: <br2h5tcg9aaf5fcj5kbrr3ghuun55pc97u@4ax.com>
On Sun, 07 Jan 2001 04:50:43 GMT, hvcraft <hvcraft@my-deja.com> wrote:
>Why isnt Finance::YahooQuote working for me?
I would check to make sure you are running the latest version of
Finance::YahooQuote and also make sure that your DSL line isn't to
blame. Your code works just fine for me (Perl 5.6.0, NT4 SP6).
Running it returns the expected output:
SUNW
SUN MICROSYS
28
1/5/2001
4:01PM
-3
-9.68%
41694500
37867954
28.0625
28.125
31
31.734375
27.8125 - 31.8125
25 - 64.625
0.62
50.00
Dec 5
N/A
N/A
90.159B
NasdaqNM
done
Sorry,
JH
------------------------------
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 V10 Issue 11
*************************************