[24063] in Perl-Users-Digest
Perl-Users Digest, Issue: 6260 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 15 14:07:37 2004
Date: Mon, 15 Mar 2004 11:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 15 Mar 2004 Volume: 10 Number: 6260
Today's topics:
Re: bit string parsing and mapping question <remorse@partners.org>
Re: bit string parsing and mapping question (Anno Siegel)
block of code doesn't get executed (stalwart)
Re: block of code doesn't get executed <nobull@mail.com>
browser tries to download perl code (Ki)
Re: browser tries to download perl code <ittyspam@yahoo.com>
Re: browser tries to download perl code <nobull@mail.com>
Re: call a cgi script from a cgi script (Joe)
Re: call a cgi script from a cgi script <xx087@freenet.carleton.ca>
cgi & javascript <fluca1978@libero.it>
Re: cgi & javascript <nospam@bigpond.com>
Re: cgi & javascript <remorse@partners.org>
Re: env perl or simply perl? ctcgag@hotmail.com
Re: Hash as a function argument.. plz help! <roel-perl@st2x.net>
Re: Hash as a function argument.. plz help! <noreply@gunnar.cc>
Matching File Content Values within Multiple Folder (KP)
Re: new to perl <s020274@cuhk.edu.hk>
Re: No more handles error with DBD::DB2 on Linux <shah@typhoon.xnet.com>
Re: Send variable from cgi to an html or php page <s.patterson@freeuk.com>
Re: variable initialization question <jwillmore@remove.adelphia.net>
Re: variable initialization question <ittyspam@yahoo.com>
Re: variable initialization question (Anno Siegel)
Re: variable initialization question <remorse@partners.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 15 Mar 2004 12:44:02 -0500
From: Richard Morse <remorse@partners.org>
Subject: Re: bit string parsing and mapping question
Message-Id: <remorse-776A5D.12440215032004@plato.harvard.edu>
In article <c2vsra$f4a$1@mamenchi.zrz.TU-Berlin.DE>,
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> David K. Wall <dwall@fastmail.fm> wrote in comp.lang.perl.misc:
> > Paul <Paul.Sue@telus.com> wrote:
> >
> > > @desc = qw(lowMem badHandle badPasswd noSpace badArg invalidInput
> > > badSyntax outOfRange);
> > >
> > my %hash = split /\n|\s+=\s+/, $com_output;
> > my @desc = qw(lowMem badHandle badPasswd noSpace
> > badArg invalidInput badSyntax outOfRange);
> > print join ', ', @desc[ grep { $hash{'code'.($_+1)} } 0..$#desc ];
>
> I think that an array isn't the best data structure for the descriptors.
> The index starts at 1, and that means hassle. I'd build a hash from the
> keys as they come. Then select the lines we need, extract the keys and
> print using a hash slice, like you did. An intermediate variable
> doesn't hurt:
>
> my %desc;
> @desc{ 'code1' .. 'code8'} = qw(
> lowMem badHandle badPasswd noSpace
> badArg invalidInput badSyntax outOfRange
> );
>
> my @sel = map /(code\d)/, grep /1$/, split /\n/, $com_output;
> print join( ', ', @desc{ @sel}), "\n";
>
Why not just do:
@desc = qw/none lowMem badHandle badPasswd .../;
This would work just as well, wouldn't it?
Ricky
------------------------------
Date: 15 Mar 2004 18:04:48 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: bit string parsing and mapping question
Message-Id: <c34r80$g89$2@mamenchi.zrz.TU-Berlin.DE>
Richard Morse <remorse@partners.org> wrote in comp.lang.perl.misc:
> In article <c2vsra$f4a$1@mamenchi.zrz.TU-Berlin.DE>,
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
>
> > David K. Wall <dwall@fastmail.fm> wrote in comp.lang.perl.misc:
> > > Paul <Paul.Sue@telus.com> wrote:
> > >
> > > > @desc = qw(lowMem badHandle badPasswd noSpace badArg invalidInput
> > > > badSyntax outOfRange);
> > > >
> > > my %hash = split /\n|\s+=\s+/, $com_output;
> > > my @desc = qw(lowMem badHandle badPasswd noSpace
> > > badArg invalidInput badSyntax outOfRange);
> > > print join ', ', @desc[ grep { $hash{'code'.($_+1)} } 0..$#desc ];
> >
> > I think that an array isn't the best data structure for the descriptors.
> > The index starts at 1, and that means hassle. I'd build a hash from the
> > keys as they come. Then select the lines we need, extract the keys and
> > print using a hash slice, like you did. An intermediate variable
> > doesn't hurt:
> >
> > my %desc;
> > @desc{ 'code1' .. 'code8'} = qw(
> > lowMem badHandle badPasswd noSpace
> > badArg invalidInput badSyntax outOfRange
> > );
> >
> > my @sel = map /(code\d)/, grep /1$/, split /\n/, $com_output;
> > print join( ', ', @desc{ @sel}), "\n";
> >
>
> Why not just do:
>
> @desc = qw/none lowMem badHandle badPasswd .../;
>
> This would work just as well, wouldn't it?
One would only have to move one "(" and change the pair of "{}" to "[]"
(untested):
my @sel = map /code(\d)/, grep /1$/, split /\n/, $com_output;
print join( ', ', @descr[ @sel]), "\n";
But the "none" would need a comment, and when a passage needs a comment,
you re-write it :)
The standard lookup structure in Perl is a hash. Just because the keys'
distinguishing part is numeric doesn't mean you must use an array.
Anno
------------------------------
Date: 15 Mar 2004 08:57:22 -0800
From: hammer@thatbox.net (stalwart)
Subject: block of code doesn't get executed
Message-Id: <f21704f9.0403150857.101c2537@posting.google.com>
Hello everyone.
I"m fairly new to perl, but I recently picked up a new sysadmin job
where perl is in heavy use. To say the least, I've been hacking away
at it for about a month now, and I'm very happy with what perl does
and what it does for me. Here is a specific problem I am having
however....
I have this program I wrote to backup voice recordings of mp3s on a
remote machine, but only if the files on the "webcenter" machine are
newer than the ones on the local machine (where the script is). All
seems well, but the last block of code towards the bottom is never
executed.
Here is the oode (I aplogize if it's too long and spams up the list):
#!/usr/bin/perl
use Net::FTP ;
use Date::Parse ;
$home = "/home/backups/recordings";
# this should go out before the mp3 backup script runs and get a
listing for it to use to compare file dates
chdir $home;
open(PASS, "/root/.mp3_backup_pass") or die "Can't open the password
file!: $!
";
print("Connecting via FTP to Webcenter...\n");
$ftp = Net::FTP->new("webcenter", Debug => 0)
or die "Cannot connect to webcenter: $@";
print("Logging in as agentmp3...\n");
$ftp->login("agentmp3", <PASS> )
or die "Cannot login!\n ", $ftp->message;
print("Getting directory listing of mp3s.....\n");
%filename = $ftp->ls
or die "Unable to list the dir!:\n", $ftp->message;
print("Ok, now I need to do some date checking....\n");
foreach($filename) {
s/^_RC//;
s/_RC^/"\n"/;
};
while ($filename) {
foreach ($filename) {
($junk1, $junk2, $file_time, $aid) =
(split(/_/, (keys %filename)));
$udate = $file_time . "\n";
};
};
#print(keys %filename);
# this is where i will check the date of the remote files against the
dates of the local files
opendir (LOCAL, $home)
or die "Unable to open $home!: $!\n";
foreach $file (readdir LOCAL) {
($junk1, $junk2, $lfile_time, $aid) = (split /_/,
$file);
undef $junk1;
undef $junk2;
$ludate = $lfile_time;
};
while ($ludate) {
if ($udate > $ludate) {
print("Retrieving newest voice
recordings....");
$ftp->get("$filename")
or die "Unable to download file(s)!:\n",
$ftp->message;
$ftp->quit;
} else {
print("There aren't any new files to
download\n");
$ftp->quit;
exit 0;
};
};
print ("Done with the mp3 backups!\n");
exit 0;
You'll note I"m using Net::FTP to retrieve a dir listing from the
remote server...it's a Winblows box and for security reasons I haven't
set up any shares on it. So I have to use FTP to list the dir. Also,
the format for the filenames is _RC_1075228773_51159_0_40.mp3 with the
1076228773 being a unix timestamp, which is what I am compairing as
which is newer or not.
Problem is, the bottom block of code, where the comparison happens,
doesn't seem to get executed at all.
I know this isn't the best looking code (or maybe even properly
formatted) but hey, this is one of my first runs at it. If any help
can be provided, then thanks. If not, it's cool, I can understand
this may be too specific to my environment to answer.
------------------------------
Date: 15 Mar 2004 17:57:42 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: block of code doesn't get executed
Message-Id: <u9wu5mm1rd.fsf@wcl-l.bham.ac.uk>
hammer@thatbox.net (stalwart) writes:
> Hello everyone.
>
> I"m fairly new to perl,
Get into the habit of always declaring all your variables as
lexically scoped in the smallest applicable scope unless you have a
positive reason to do otherwise. Do this from day 0. Do not wait
until you failure to do so causes you pain.
Indent your code.
Put "use strict" and "use warnings" at the top of your script to help
Perl to help you.
> Here is the oode (I aplogize if it's too long and spams up the list):
I can't be bothered to attempt to figure out what's wrong. The first
5-10 minuites would be spent looking for mistakes that would have
been avoided if you'd followed the advice above. If you can't be
bothered to help yourself you shouldn't expect anyone else to do so.
Random shot in the dark - you have a } in the wrong place.
Another random shot in the dark, you are confusing exit() and last().
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 15 Mar 2004 09:05:37 -0800
From: docskky@yahoo.com (Ki)
Subject: browser tries to download perl code
Message-Id: <935d4411.0403150905.7f412932@posting.google.com>
Hello.
I am currently using apache server and trying to write perl programs.
It is working for some other perl programs, but my browser tries to
download not actual output but perl source code.
This is the code I am trying to write.
File name: slicer.pl
----------------------------------------------------------------
#!/usr/local/bin/perl
print "Content-type: text/html/n/n";
#Executes input from text box in html and displays output
# if ( $ENV{'CONTENT_LENGTH'} ) {
# read(STDIN, $_, $ENV{'CONTENT_LENGTH'});
# s/(.)*=//; s/\+/ /g; s/%(.)/pack("c",hex($1))/ge;
# $out='$_ 2>&1';
print "\n\n";
print "<HTML><HEAD><TITLE>Slicer grapher</TITLE></HEAD>";
print "<BODY BGCOLOR=#99CCFF><BR>";
#takes the input from the text box in html and stores value
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs=split(/&/, &buffer);
foreach $pair ( @pairs ) {
($name,$value)=split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
#displays user input and options chosen
print "<h2>You have submitted...</h2>\n";
print "<BR>";
print "Graph file: $FORM{fileName}<br> ";
$Int = "Graph with the follow option(s): ";
$option=1; #variable to keep track of which options a user chooses,
1=option chosen, 0=option not chosen
if ($FORM{edges}>1 && $FORM{Pref} =~ m/[eE]edges/) {
$Int = "$Int Edges";
$option=0;
}
if ($FORM{nodes}>1) {
$Int = "$Int Nodes";
$optoin = 0;
}
if ($FORM{numNodes}>1) {
$Int = "$Int NumNodes";
$option=0;
}
if ($FORM{split}>1) {
$Int = "$Int Split";
$option=0;
}
#if option is chosen, will display name of option and store a string
into var arg
if($option==1)
{
if($FORM{edges}==1)
{
$Int = "$Int <i>Control Flow Edge,</i>";
$option=0;
$arg1 = "-edges CF";
}
if($FORM{edges}==2)
{
$Int = "$Int <i>Control Dependence Edge,</i>";
$option=0;
$arg1 = "-edges CD";
}
if($FORM{edges}==3)
{
$Int = "$Int <i>Data Dependence Edge,</i>";
$option=0;
$arg1 = "-edges DD";
}
if($FORM{edges}==4)
{
$Int = "$Int <i>Interference Edge,</i>";
$option=0;
$arg1 = "-edges ID";
}
if($FORM{edges}==5)
{
$Int = "$Int <i>Call Edge,</i>";
$option=0;
$arg1 = "-edges CA";
}
if($FORM{edges}==6)
{
$Int = "$Int <i>Parameter Edge,</i>";
$option=0;
$arg1 = "-edges PA";
}
if($FORM{edges}==7)
{
$Int = "$Int <i>Transitive Edge,</i>";
$option=0;
$arg1 = "-edges TR";
}
if($FORM{edges}==8)
{
$Int = "$Int <i>All Edges,</i>";
$option=0;
$arg1 = "-edges ALL";
}
if($FORM{nodes}==1)
{
$Int = "$Int <i>Nodes,</i>";
$option=0;
$arg2 = "-so";
}
if($FORM{numNodes}==1)
{
$Int = "$Int <i>NumNodes,</i>";
$option=0;
$arg3 = "-num";
}
if($FORM{nodes}==1)
{
$Int = "$Int <i>Nodes,</i>";
$option=0;
$arg2 = "-split";
}
}
print "$Int";
print "<br>";
$FORM{fileName} = "main";
#if no options selected, this page will display
if ($option==1) {
print "<BR> You have not chosen to graph with any options<p>";
print "<A HREF=/home/kiyong/hiperspace/Slicer/$FORM{fileName}.ps>CLICK
TO VIEW BASIC GRAPH<A><BR>";
}
#if at least one option chosen, this page will display
else {
print "<A HREF=/home/kiyong/hiperspace/Slicer/$FORM{fileName}.ps>CLICK
TO VIEW GRAPH WITH SELECTED OPTIONS</A><BR>";
}
#displays current date
$date='/bin/data';
print "<BR><BR>$date";
print "****************************************************************************************************************";
# prints out what the slicing script is running with the correct
arguments
#print "\%: /slicer $_<PRE>$out</PRE>";
#print "$FORM{fileName} 28:z,i $arg1 $arg2 $arg3 $arg4<br>";
print "<PRE>";
#prints the display of occ and scc and slicing script
#print `./slicer $FORM{fileName} "28:z,i $arg1 $arg2 $arg3 $arg4"`;
print "</PRE>";
print "<p></B></BODY></HTML>";
#inputs all the data into a file called file.dat
`echo "$date" >> ./files.dat`;
`echo "$Name" >> ./files.dat`;
`echo "$Number" >> ./files.dat`;
`echo "$Int" >> ./files.dat`;
`echo >> ./files.dat`;
`echo >> ./files.dat`;
------------------------------
Date: Mon, 15 Mar 2004 12:13:26 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: browser tries to download perl code
Message-Id: <20040315121213.X27834@dishwasher.cs.rpi.edu>
On Mon, 15 Mar 2004, Ki wrote:
> Date: 15 Mar 2004 09:05:37 -0800
> From: Ki <docskky@yahoo.com>
> Newsgroups: comp.lang.perl.misc
> Subject: browser tries to download perl code
>
> Hello.
> I am currently using apache server and trying to write perl programs.
> It is working for some other perl programs, but my browser tries to
> download not actual output but perl source code.
>
> This is the code I am trying to write.
>
> File name: slicer.pl
> ----------------------------------------------------------------
> #!/usr/local/bin/perl
> print "Content-type: text/html/n/n";
^^^^^
The HTTP header isn't being set correctly. \n\n, not /n/n.
You could avoid this problem (as well as the messy query string parsing)
using the CGI.pm module, of course.
Paul Lalli
------------------------------
Date: 15 Mar 2004 18:00:53 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: browser tries to download perl code
Message-Id: <u9smgam1m2.fsf@wcl-l.bham.ac.uk>
docskky@yahoo.com (Ki) writes:
> Hello.
> I am currently using apache server and trying to write perl programs.
> It is working for some other perl programs, but my browser tries to
> download not actual output but perl source code.
This is a server config issue - nothing to do with Perl.
> This is the code I am trying to write.
>
> #takes the input from the text box in html and stores value
> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
> @pairs=split(/&/, &buffer);
> foreach $pair ( @pairs ) {
> ($name,$value)=split(/=/, $pair);
> $value =~ tr/+/ /;
> $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> $FORM{$name} = $value;
> }
Stop doing that. Use the CGI module. If you found the above in a
book then burn that book - it is a Perl4 book.
> `echo "$date" >> ./files.dat`;
Don't do that. Write it in Perl.
See also FAQ: What's wrong with using backticks in a void context?
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 15 Mar 2004 09:07:44 -0800
From: jab_joe@www.com (Joe)
Subject: Re: call a cgi script from a cgi script
Message-Id: <6586e7f6.0403150907.15292f69@posting.google.com>
"chatiman" <chatiman@free.fr> wrote in message news:<40521dc6$0$277$626a14ce@news.free.fr>...
> "Joe" <jab_joe@www.com> a 嶰rit dans le message de news:
> 6586e7f6.0403121215.55caa7f6@posting.google.com...
> > How do I do this?
> >
> > I want my cgi script to call a cgi script with a argument.
> >
> > is:
> >
> > my $cmd = "perl ".$SCRIPT_URL ."?".$POLL_CODE_SURVEY."|";
> >
> > open CMD, $cmd;
> >
> > right?
>
> I don't think this would work.
>
> The method I use is to setup the QUERY_STRING environement variable.
> This works most of the time :
>
> system ("QUERY_STRING=$POLL_CODE_SURVEY perl the_script.cgi");
>
> Some scripts may accept parameters passed on the command line.
> In this case you could probably use :
>
> system ("perl the_script.cgi $POLL_CODE_SURVEY");
>
> hth
Nearly got it working now.
I'm now doing:
$ENV{QUERY_STRING} = $POLL_CODE_SURVEY;
system ("perl $SCRIPT_URL");
The problem with this is it doesn't force a re-fresh of the existing
page. The text of the page before is still there.
Since I'm doing:
print $cgi->header(-cookie=>$cookie);
before causing this cgi re-call, I see this cookie information and the
top of the page.
Basicly what I doing is writing a test cookie, then relunching the cgi
script to test for the cookie. If it's not there then I know I can't
write out cookies.
So I need to cause a refresh some how. Other then that this seams to
work great. :-)
------------------------------
Date: 15 Mar 2004 17:22:55 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: call a cgi script from a cgi script
Message-Id: <slrnc5bpjf.j9q.xx087@smeagol.ncf.ca>
Joe <jab_joe@www.com> wrote:
[...]
> system ("perl $SCRIPT_URL");
>
> The problem with this is it doesn't force a re-fresh of the existing
> page. The text of the page before is still there.
Perhaps you should set the web server to the work for you:
print $cgi->redirect($SCRIPT_URL)
And then that cgi can redirect back to you.
--
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca
------------------------------
Date: Mon, 15 Mar 2004 16:31:12 +0000 (UTC)
From: "Luca Ferrari" <fluca1978@libero.it>
Subject: cgi & javascript
Message-Id: <e4f389e9fe366d578d4789325a58f43f.60620@mygate.mailgate.org>
Hi,
I'm developing some cgis using perl to access a database. Often I put a
button (submit) to delete one or more rows in a table, but I'd like to
ask the user before doing it. To do so I thought about using javascript,
and in particular javascript:confirm(..) as onClick property of the
submit button. The problem is that the form is submitted even if the
user says no. I've tried with a javascript button but I don't know how
to post data submitting the form.
My javascript code to check is:
Any suggestions on how to ask the user before submitting?
Thanks,
Luca
--
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG
------------------------------
Date: Tue, 16 Mar 2004 03:58:47 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: cgi & javascript
Message-Id: <5170687.t7kLfOueBI@GMT-hosting-and-pickle-farming>
Luca Ferrari wrote:
> Hi,
>
> Any suggestions on how to ask the user before submitting?
I suggest you use a javascript group; thus group is for Perl.
gtoomey
------------------------------
Date: Mon, 15 Mar 2004 13:11:32 -0500
From: Richard Morse <remorse@partners.org>
Subject: Re: cgi & javascript
Message-Id: <remorse-DAA5A9.13113215032004@plato.harvard.edu>
In article
<e4f389e9fe366d578d4789325a58f43f.60620@mygate.mailgate.org>,
"Luca Ferrari" <fluca1978@libero.it> wrote:
> Hi,
> I'm developing some cgis using perl to access a database. Often I put a
> button (submit) to delete one or more rows in a table, but I'd like to
> ask the user before doing it. To do so I thought about using javascript,
> and in particular javascript:confirm(..) as onClick property of the
> submit button. The problem is that the form is submitted even if the
> user says no. I've tried with a javascript button but I don't know how
> to post data submitting the form.
> My javascript code to check is:
I note that you didn't put in the javascript code...
Although this is off-topic (because it isn't about Perl), the solution I
usually use (if I'm doing client-side confirmation, which I usually
don't), is to have an <input type="button"
onclick="do_submit('item_desc')" />. Then, define:
function do_submit(item_desc) {
if (confirm("Do you really want to delete this item: " + item_desc)) {
var the_form = document.getElementById("formid");
the_form.submit();
}
}
Note that I just typed up this code from memory, so it may need tweaking
to actually work... Also, this will only work with a recent browser
(IE5.5 (maybe 5.0), Mozilla, Netscape 6+, Opera) -- the getElementById
is part of the newer DOM...
HTH,
Ricky
------------------------------
Date: 15 Mar 2004 17:07:10 GMT
From: ctcgag@hotmail.com
Subject: Re: env perl or simply perl?
Message-Id: <20040315120710.198$gX@newsreader.com>
Berk Birand <graffitiNOSPAM@NOSPAMyahoo.com> wrote:
> Hi,
>
> I am just starting out to learn perl. I have begun by reading the
> wonderful manual pages that comes with it. There, they define the first
> line of the script as:
> #!/bin/env perl
I have perl scripts NSF mounted from several machines. Some of those
machines have the version of perl I want to run in /usr/local/bin, some
in /usr/bin. By using "#!/usr/bin/env perl" , I'm able to have one shebang
line that works regardless of the machine I'm logged on to.
>
> I used this construct for a couple days. Then I got the O'Reilly book
> Learning Perl. In that one, they simply define it:
> #!/usr/bin/perl
>
> This seems a lot more logical. Plus we also have the ability to add the
> -w switch. However I am wondering whether the env version is more
> accurate, since Learning Perl is designed for absolute beginners.
I'd prefer the /usr/bin/perl, unless you are a situation similar to mine.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 15 Mar 2004 16:09:22 GMT
From: Roel van der Steen <roel-perl@st2x.net>
Subject: Re: Hash as a function argument.. plz help!
Message-Id: <slrnc5blan.r5q.roel-perl@localhost.localdomain>
> Karel Kubat <karel@e-tunity.com> wrote in message-id:
>
>Hi all,
>I have a problem with a snippet of code. I'm trying to pass a hash as an
>argument to a function. Below is some test code:
>
>--- snip snip
>use strict;
You should always use warnings, in that case you would have received
the warning: "Reference found where even-sized list expected" with
the following statement.
>
>my %map = {
^
That should be a '('; use '{' to create an anonymous hash.
> 1 => 'one',
> 2 => 'two',
> 3 => 'three',
>};
^
must be ')', then.
>
>sub fun {
> my $what = shift;
> my %hash = @_;
>
> print ("$what: ");
> foreach my $k (keys (%hash)) {
> print (" [$k]=[$hash{$k}]");
> }
> print ("\n");
>}
>
># Why won't this work..
>fun ("whatever", %map);
>
># But this will ?!
>fun ("again",
> 'a' => 'first char', 'b' => 'second');
>--- snip snip
>
Now both calls will work.
------------------------------
Date: Mon, 15 Mar 2004 17:19:38 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Hash as a function argument.. plz help!
Message-Id: <c34l12$22v0ui$1@ID-184292.news.uni-berlin.de>
Karel Kubat wrote:
> I have a problem with a snippet of code. I'm trying to pass a hash
> as an argument to a function. Below is some test code:
>
> --- snip snip
> use strict;
>
> my %map = {
> 1 => 'one',
> 2 => 'two',
> 3 => 'three',
> };
Try to use parentheses instead of brackets.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 15 Mar 2004 10:46:35 -0800
From: snazystyl@hotmail.com (KP)
Subject: Matching File Content Values within Multiple Folder
Message-Id: <dc2b0830.0403151046.7db67cb@posting.google.com>
I have a directory C:\Temp that contains multiple folders (300) to be
exact each one increments.
C:\temp\CL_100
C:\temp\CL_101
Within each of those 300 folders is a text file. Each text file
contains many of the same values however each one has 3 minor
differences between them.
FileName: Info.txt
ID 1 Blah
ID 3 Pizza
ID 30 Beer
ID 31 Blah
ID 32 Blah
ID 58 Pepto
I would like to be able to loop through all directories within C:\temp
from CL_1 to CL_300 read each Info.txt trying to match the values I'm
looking for withing the contents of the file. The goal is to be able
to print to the console all CL_* folders that contain the Info.txt
file that has the three values i'm looking for namely Pizza, Beer and
Pepto.
open (FILE, $filename) or die "Could not read file: $!";
while ($filename = <FILE>) {
if ($filename =~ /.*Pizza.*/) {
while ($match2 = <FILE>) {
if ($match2 =~ /.*Beer.*/) {
while ($match3 = <FILE>) {
if ($match3 =~ /.*Pepto.*/) {
$matchfound = $matchfound .';'. $1;
}
}last;
}
}
}
}
------------------------------
Date: Tue, 16 Mar 2004 01:28:34 +0800
From: "Tsui Wai-ming" <s020274@cuhk.edu.hk>
Subject: Re: new to perl
Message-Id: <c34p3r$1am3$1@justice.itsc.cuhk.edu.hk>
"Joe Smith" <Joe.Smith@inwap.com> 撰寫於郵件新聞
:v885c.14258$_w.316453@attbi_s53...
> Tsui Wai-ming wrote:
>
> > "Joe Smith" <Joe.Smith@inwap.com> 撰寫於郵件新聞
> > :jpM1c.177224$jk2.647006@attbi_s53...
> >
> >>Tsui Wai-ming wrote:
> >>
> >>
> >>>In fact I just changed to
> >>>
> >>>#!C:\perl\bin\perl
> >>>
> >>>This one
> >>># perl, and
> >>>#!C:\perl\bin
> >>>
> >>>didnt work at all...
> >>
> >>It depends on how you invoke your perl script.
> >>
> >>Double-clicking on an icon in a local file folder: Uses registry.
> >>Typing name into CMD.EXE command-line prompt: Uses registry.
> >>Typing name into some other command-line shell: Depends on shell (bash).
> >> (In particular, cygwin uses /usr/bin/perl.)
> >>Clicking on link in a browser: Depends on web server.
> >> Sambar Server for Windows: Uses shebang line.
> >> Apache Server for Windows: I believe it is a configuration option.
> >> IIS: Registry.
> >>
> >>Which method "didnt work at all"?
> >>-Joe
> >
> >
> > This one: #perl
> > And this one: #!C:\perl\bin
> >
> > Ming :)
>
> You didn't answer the question.
>
> What method are you using to start your perl script?
> -Joe
Oh, I typed the following the command line after getting into the directory
where the script is:
perl scriptname.pl
Ming.
------------------------------
Date: Mon, 15 Mar 2004 16:59:08 +0000 (UTC)
From: Hemant Shah <shah@typhoon.xnet.com>
Subject: Re: No more handles error with DBD::DB2 on Linux
Message-Id: <c34ncs$m90$1@flood.xnet.com>
While stranded on information super highway bialek wrote:
> RH7.3 is one of those antique Linux OS that need some parameter twitching in
> the /proc filesystem... Normally the handles run out if the number of system
> semaphores or else runs out... I think for RH7.3 you still need to manually
> echo the parameters in...
>
> echo 256000 > /proc/sys/kernel/shmmax
> echo 1024 > /proc/sys/kernel/msgmni
> echo "250 32000 32 1024" > /proc/sys/kernel/sem
I have increased the parameters on Linux. The problem seems to be with DBD
or DBI module.
I wrote a sample perl code that fetches same row from the database in a
loop. On Linux system is generates error after looping for 1243 iterations.
On AIX system (where the server is running) it generates error after 386
iterations.
>
> not full sure about the correct paths above right now (on the road and no
> LInux box in front of me) but you should be able to find them...
>
> "Hemant Shah" <shah@typhoon.xnet.com> wrote in message
> news:c2asif$hko$1@flood.xnet.com...
>>
>> Folks,
>>
>> I have DB2 UDB 7.2 EE installed on AIX 5.2 system. I think I am at
>> latest fixpack, see output of lslpp below. I have also installed DB2
>> UDB 7.2 EE on RedHat Linux 7.3 I believe that is also at the latest
>> fix pack, see rpm output below.
>>
>> The database is on AIX system and on the Linux system it is cataloged
>> as remote database.
>>
>> I have perl/TK GUI that uses DBD::DB2 interface to access the database.
>> If I run the GUI from AIX system (server) I have no problems. If I
>> run GUI from Linux system (client), then after using it for some time
>> I get following error:
>>
>> CLI0129E No more handles.
>>
>> Last time I got this error I ran following commands on the Server:
>>
>> db2 list applications
>> db2 get snapshot for applications on dbname
>>
>> There was only one connection to the database and that was the GUI,
>> the application also had only one section.
>>
>> I have checked my code and I always call finish() method on the
>> statement handle after I am done. All the access to the database is
>> done by calling various functions. When the GUI is started it connects
>> to the database. Each function creates and prepares the statement and
> then
>> executes it and then calls finish() before returning.
>>
>>
>> I am not sure why I am getting this error from the Linix client.
>>
>>
>>
>> # lslpp -l "db2_07_01*"
>> Fileset Level State Description
>> ------------------------------------------------------------------------
> ----
>> Path: /usr/lib/objrepos
>> db2_07_01.adt.rte 7.1.0.72 COMMITTED Application Development
> Tools
>> (ADT)
>> db2_07_01.adt.samples 7.1.0.72 COMMITTED ADT Sample Programs
>> db2_07_01.cdb 7.1.0.72 COMMITTED Control Database
>> db2_07_01.cj 7.1.0.72 COMMITTED Java Common files
>> db2_07_01.client 7.1.0.72 COMMITTED Client Application
> Enabler
>> db2_07_01.cnvucs 7.1.0.72 COMMITTED Code Page Conversion
> Tables -
>> Uni Code Support
>> db2_07_01.conn 7.1.0.72 COMMITTED Connect
>> db2_07_01.conv.jp 7.1.0.40 COMMITTED Code Page Conversion
> Tables -
>> Japanese
>> db2_07_01.conv.kr 7.1.0.40 COMMITTED Code Page Conversion
> Tables -
>> Korean
>> db2_07_01.conv.sch 7.1.0.40 COMMITTED Code Page Conversion
> Tables -
>> Simplified Chinese
>> db2_07_01.conv.tch 7.1.0.40 COMMITTED Code Page Conversion
> Tables -
>> Traditional Chinese
>> db2_07_01.cs.drda 7.1.0.72 COMMITTED Communication Support -
> DRDA
>> Application Server
>> db2_07_01.cs.ipx 7.1.0.72 COMMITTED Communication Support -
> IPX
>> db2_07_01.cs.rte 7.1.0.72 COMMITTED Communication Support -
> TCP/IP
>> db2_07_01.cs.sna 7.1.0.72 COMMITTED Communication Support -
> SNA
>> db2_07_01.ctsr 7.1.0.72 COMMITTED Control Server
>> db2_07_01.das 7.1.0.72 COMMITTED Administration Server
>> db2_07_01.db2.engn 7.1.0.72 COMMITTED Engine
>> db2_07_01.db2.rte 7.1.0.72 COMMITTED Run-time Environment
>> db2_07_01.db2.samples 7.1.0.40 COMMITTED Sample Database Source
>> db2_07_01.db2tie 7.2.0.2 COMMITTED Text Information Extender
>> db2_07_01.elic 7.1.0.72 COMMITTED Product Signature for UDB
>> Enterprise Edition
>> db2_07_01.jdbc 7.1.0.72 COMMITTED Java Support
>> db2_07_01.ldap 7.1.0.72 COMMITTED DB2 LDAP Support
>> db2_07_01.spb 7.1.0.72 COMMITTED Stored Procedure Builder
>> db2_07_01.tspf 7.1.0.72 COMMITTED Transformer Stored
> Procedure
>> Files
>> db2_07_01.wcc 7.1.0.72 COMMITTED Control Center
>>
>> ----------------------------------------------------------------------
>> # rpm -qa | grep db2
>> db2-2.4.14-10
>> db2das71-7.1.0-68
>> db2cnvc71-7.1.0-68
>> db2-devel-2.4.14-10
>> db2jdbc71-7.1.0-68
>> db2cj71-7.1.0-68
>> db2adt71-7.1.0-68
>> db2crte71-7.1.0-68
>> db2cnvj71-7.1.0-68
>> db2cliv71-7.1.0-68
>> db2engn71-7.1.0-68
>> db2conn71-7.1.0-68
>> db2smpl71-7.1.0-68
>> db2cnvt71-7.1.0-68
>> db2rte71-7.1.0-68
>> db2wcc71-7.1.0-68
>> db2adts71-7.1.0-68
>> db2cdrd71-7.1.0-68
>> db2cnvk71-7.1.0-68
>> db2cucs71-7.1.0-68
>> db2repl71-7.1.0-68
>> db2elic71-7.1.0-68
>>
>> --
>> Hemant Shah /"\ ASCII ribbon campaign
>> E-mail: NoJunkMailshah@xnet.com \ / ---------------------
>> X against HTML mail
>> TO REPLY, REMOVE NoJunkMail / \ and postings
>> FROM MY E-MAIL ADDRESS.
>> -----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
>> I haven't lost my mind, Above opinions are mine only.
>> it's backed up on tape somewhere. Others can have their own.
>
>
--
Hemant Shah /"\ ASCII ribbon campaign
E-mail: NoJunkMailshah@xnet.com \ / ---------------------
X against HTML mail
TO REPLY, REMOVE NoJunkMail / \ and postings
FROM MY E-MAIL ADDRESS.
-----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
I haven't lost my mind, Above opinions are mine only.
it's backed up on tape somewhere. Others can have their own.
------------------------------
Date: Mon, 15 Mar 2004 19:00:29 +0000
From: Stephen Patterson <s.patterson@freeuk.com>
Subject: Re: Send variable from cgi to an html or php page
Message-Id: <pan.2004.03.15.19.00.14.703205@freeuk.com>
On Mon, 15 Mar 2004 03:36:23 +0000, wrote:
> I have an html form which send details entered in form to a perl script
> (cgi)
>
> How can i send variables from a cgi script back to an html or php page.
I've done this quite a lot by having the CGI script generate the form
(print to STDOUT), or if executed with arguments (the form filled in)
process the form.
--
Stephen Patterson http://patter.mine.nu/
steveSPAM@.patter.mine.nu remove SPAM to reply
Linux Counter No: 142831 GPG Public key: 252B8B37
Caution: breathing may be hazardous to your health.
------------------------------
Date: Mon, 15 Mar 2004 11:12:19 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: variable initialization question
Message-Id: <pan.2004.03.15.16.12.17.578063@remove.adelphia.net>
On Mon, 15 Mar 2004 16:19:00 +0100, Tore Aursand wrote:
> On Mon, 15 Mar 2004 11:06:28 +0000, Anno Siegel wrote:
>>>> There's generally no reason to initialize a variable to 0.
>
>>> Unless you like clean programs.
>
>> You're not recommending to initialize *all* variables, are you?
>
> Why not, actually? I really _like_ the idea of having each variable in a
> program initialized before use. What are the arguments against doing
> this?
I agree and would like to see why it's a bad idea to initialize variables
up front before use. Other languages do - in fact, require it.
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
Hacker's Law: The belief that enhanced understanding will necessarily
stir a nation to action is one of mankind's oldest illusions.
------------------------------
Date: Mon, 15 Mar 2004 12:05:39 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: variable initialization question
Message-Id: <20040315115934.G27834@dishwasher.cs.rpi.edu>
On Mon, 15 Mar 2004, James Willmore wrote:
> On Mon, 15 Mar 2004 16:19:00 +0100, Tore Aursand wrote:
>
> > On Mon, 15 Mar 2004 11:06:28 +0000, Anno Siegel wrote:
> >>>> There's generally no reason to initialize a variable to 0.
> >
> >>> Unless you like clean programs.
> >
> >> You're not recommending to initialize *all* variables, are you?
> >
> > Why not, actually? I really _like_ the idea of having each variable in a
> > program initialized before use. What are the arguments against doing
> > this?
>
> I agree and would like to see why it's a bad idea to initialize variables
> up front before use. Other languages do - in fact, require it.
Other languages requiring it is a reason Perl is better, not a reason to
program Perl as though it was a different language.
It can be a bad idea because 1) It's generally unnecessary and 2) It can
have a connotation that's different than what's intended. The example
earlier in this thread was about accumulators. Let's use that.
my $accum;
while (...) {
if (...) {
$accum++;
}
if (...) {
$accum--;
}
}
if (defined ($accum)){
print "Finshed with $accum accumulated widgets\n";
} else {
print "No widget was ever accumulated\n";
}
If on the other hand, we had originally initialized $accum to 0, we have
no way of telling whether we ever saw any acuumulated widgets and later
saw an equal number of subtractions, or if no widgets were ever
accumulated.
Basically the undef value means "This variable has never been touched"
where as assigning a default value carries the meaning of "this variable
has been deliberately assigned to this specific value". The distinction
can be quite important in any number of programs.
To those who suggest variables should be defined to help readers of the
program know what's going on, I suggest those readers learn Perl better,
rather than need to be hand held through needless code.
There's my 2 cents.
Paul Lalli
------------------------------
Date: 15 Mar 2004 17:49:46 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: variable initialization question
Message-Id: <c34qbq$g89$1@mamenchi.zrz.TU-Berlin.DE>
Tore Aursand <tore@aursand.no> wrote in comp.lang.perl.misc:
> On Mon, 15 Mar 2004 11:06:28 +0000, Anno Siegel wrote:
> >>> There's generally no reason to initialize a variable to 0.
>
> >> Unless you like clean programs.
>
> > You're not recommending to initialize *all* variables, are you?
>
> Why not, actually? I really _like_ the idea of having each variable in a
> program initialized before use. What are the arguments against doing
> this?
For the same reason we don't write "$scalar" where $scalar suffices and
avoid useless escapes as in /\"abc\"/. It's unnecessary, and unnecessary
actions are stumbling blocks to the reader, who asks himself why and
spends time finding out that there is no reason. Needless initialization
can also mask bugs.
Unlike other languages, Perl variables *are* initialized. Despite its
name, undef is a well defined value with a well defined function, and
every scalar comes initialized to it. Nothing more dangerous than a
friendly warning happens if you use the value inappropriately. By
overwriting it you tell the reader, "Undef isn't good enough, I need
something else." Don't tell them that if it isn't true.
Anno
------------------------------
Date: Mon, 15 Mar 2004 12:51:06 -0500
From: Richard Morse <remorse@partners.org>
Subject: Re: variable initialization question
Message-Id: <remorse-C9AEDA.12510615032004@plato.harvard.edu>
In article <pan.2004.03.15.16.12.17.578063@remove.adelphia.net>,
James Willmore <jwillmore@remove.adelphia.net> wrote:
> On Mon, 15 Mar 2004 16:19:00 +0100, Tore Aursand wrote:
>
> > On Mon, 15 Mar 2004 11:06:28 +0000, Anno Siegel wrote:
> >>>> There's generally no reason to initialize a variable to 0.
> >
> >>> Unless you like clean programs.
> >
> >> You're not recommending to initialize *all* variables, are you?
> >
> > Why not, actually? I really _like_ the idea of having each variable in a
> > program initialized before use. What are the arguments against doing
> > this?
>
> I agree and would like to see why it's a bad idea to initialize variables
> up front before use. Other languages do - in fact, require it.
In point of fact, all Perl variables _are_ initialized automatically.
They are initialized to undef. In terms of other languages requiring
users to initialize variables, there are two possibilities for the other
language:
1) as this other language does not initialize variables by default (for
speed purposes, usually), you cannot use a variable before giving it
some value to help prevent issues where the memory allocated to the
variable has some other, residual, value in it
or
2) this other language has no way to indicate "undefinedness" of a
variable, and insists that you provide an initial value so that you know
what the "undefined" value for that variable is.
Note that Mr. Seigel wrote "initialize a variable to 0" -- not
"initialize a variable". Perl handles the initialization of variables
to undef automatically.
HTH,
Ricky
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 6260
***************************************