[11907] in Perl-Users-Digest
Perl-Users Digest, Issue: 5507 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 28 14:07:25 1999
Date: Wed, 28 Apr 99 11:01:27 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 28 Apr 1999 Volume: 8 Number: 5507
Today's topics:
strange problem with the month from a date!! pablocosta@iname.com
Re: strange problem with the month from a date!! <dgris@moiraine.dimensional.com>
Re: strange problem with the month from a date!! <sarmad@fas.harvard.edu>
Re: strange problem with the month from a date!! (Larry Rosler)
Re: strict vs. Win32::Registry <cassell@mail.cor.epa.gov>
Re: stupid single quote " wipes out REST OF TEXT (Tad McClellan)
Re: Telnet problems <jay@rgrs.com>
Transactions not working with ODBC module <sjivan@yahoo.com>
Re: Using Expect to run Top <bowen@imall.com>
Re: Using string content as an a variable name <cassell@mail.cor.epa.gov>
Re: What does this error message mean? <aqumsieh@matrox.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 28 Apr 1999 16:09:47 GMT
From: pablocosta@iname.com
Subject: strange problem with the month from a date!!
Message-Id: <7g7bs7$b3k$1@nnrp1.dejanews.com>
I have never programmed in perl.
I have a perl program that splits the date:
#!/usr/bin/perl
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
print $mon;
Today, that returns "3"
Today, my system date is Wed Apr 28 16:52:57 CEST 1999
If it's APRIL, the program should return "4" shouldn't it?
well, sec, min, hour, day and year are right, but the month isn't.
Any idea??
THANKS in advance.
pablo
pablocosta@iname.com
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 28 Apr 1999 10:28:36 -0600
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: strange problem with the month from a date!!
Message-Id: <m3iuag3e17.fsf@moiraine.dimensional.com>
pablocosta@iname.com writes:
> Today, that returns "3"
Yes.
> Today, my system date is Wed Apr 28 16:52:57 CEST 1999
Yes. (well, probably not _all_ day)
> If it's APRIL, the program should return "4" shouldn't it?
Why? April is definitely month 3. perldoc -f localtime
for an explanation of why.
dgris
--
Daniel Grisinger dgris@moiraine.dimensional.com
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'
------------------------------
Date: 28 Apr 1999 16:25:26 GMT
From: Shaikh Sarmad <sarmad@fas.harvard.edu>
Subject: Re: strange problem with the month from a date!!
Message-Id: <7g7cpm$4b9$1@news.fas.harvard.edu>
Rumour has it, pablocosta@iname.com said:
> If it's APRIL, the program should return "4" shouldn't it?
no. the numbering starts from 0. note that this means
$mon will never be 12!
jan = 0
feb = 1
mar = 2
apr = 3
...
nov = 10
dec = 11
sarmad :)
--
===========================================================================
Sarmad M Shaikh 617.495.9647 (work)
Manager, HSA Computer Services 617.493.2453 (home)
67 Mount Auburn Street http://hsa.net/comp_services
Cambridge MA 02138 http://www.fas.harvard.edu/~sarmad
===========================================================================
------------------------------
Date: Wed, 28 Apr 1999 10:00:31 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: strange problem with the month from a date!!
Message-Id: <MPG.1190de86cf9d7043989968@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <7g7bs7$b3k$1@nnrp1.dejanews.com> on Wed, 28 Apr 1999
16:09:47 GMT, pablocosta@iname.com <pablocosta@iname.com> says...
...
> #!/usr/bin/perl
> ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
> print $mon;
>
> Today, that returns "3"
> Today, my system date is Wed Apr 28 16:52:57 CEST 1999
>
> If it's APRIL, the program should return "4" shouldn't it?
>
> well, sec, min, hour, day and year are right, but the month isn't.
Others have commented on the month. I'll comment on your observation
that the year is 'right'. How 'right' do you think it will be in a
little over seven months from now? How would you plan on dealing with
it?
perldoc -f localtime
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 28 Apr 1999 09:56:51 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: strict vs. Win32::Registry
Message-Id: <37273DD3.6B49A19D@mail.cor.epa.gov>
homeless wrote:
>
> I'm trying to use:
> use strict;
> (in package main)
> While at the same time using Win32::Registry (in a subroutine.)
>
> The objects exported by Registry.pm,
> namely $HKEY_LOCAL_MACHINE and such, disagree with strict in
> my program.
>
> Could someone please direct me to a faq on how to
> declare objects from other modules in order to satisfy strict.
> My search so far has been unsuccessful.
Check the docs on use strict.. that should be sufficient.
Let me ask a question, since you aren't showing any code.
Are you saying something like:
$remote_key = $Registry->{"yadda/yadda/yadda"...};
If so, then you want to add a `my' immediately before:
my $remote_key = $Registry->{"yadda/yadda/yadda"...};
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior Computing Specialist phone: (541) 754-4468
mathematical statistician fax: (541) 754-4716
------------------------------
Date: Wed, 28 Apr 1999 08:39:35 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: stupid single quote " wipes out REST OF TEXT
Message-Id: <7iv6g7.oe6.ln@magna.metronet.com>
NOSPAMcrstlblu@planet.eon.net wrote:
: On Wed, 28 Apr 1999 08:38:33 GMT, aspinelli@ismes.it (Andrea L. Spinelli) wrote:
: >On Tue, 27 Apr 1999 11:08:15 GMT, NOSPAMcrstlblu@planet.eon.net wrote:
: >>when I OPEN the dbm, extract, and display the text in THE FIRST SCRIPT, no prob,
: >>it gets displayed in its' entirety,....
: >>when i pass the value into a hidden formfield and forward to the next
: >I suspect that you write directly something like
: > print "<input type=\"hidden\" name=\"foo\" value=\"$value\">";
: >where $value is 5'10".
: correct! ALMOST!
: actually,
: $value = "200 characters, 5'10" followed by another 200 characters";
: notice the SOLITARY QUOTATION mark in the center of the VALUE?
You have been told multiple times what you must do to fix the
problem.
Why don't you just do it and see if it fixes things since you
have been told a bunch of times that it will fix things.
STOP POSTING YOUR HTML PROBLEMS IN THE PERL NEWSGROUP!!!
*plonk*
$value =~ s/"/"/g; # escape double quotes as REQUIRED
# by the HTML specification!!!
: >Now, what you'll print is
: > <input type="hidden" name="foo" value="5'10"">
: >You should see that there is an inconsistency after the 10.
: no, what is in the cgi script is:
He isn't talking about what is in the CGI script.
I wasn't talking about what is in the CGI script.
You are the only one talking about what is in the CGI script,
and you have repeated yourself several times. We all know
what is in the CGI script.
We are both talking about what the *browser sees* (which is the
*output* from your CGI script).
Which makes sense. Since the browser is screwing things up,
it makes sense to go look at what the browser is looking at.
The browser never sees your CGI script, it sees only the *output*
from the script.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 28 Apr 1999 12:51:00 -0400
From: Jay Rogers <jay@rgrs.com>
Subject: Re: Telnet problems
Message-Id: <82n1zs3czv.fsf@shell2.shore.net>
scott@sboss.net writes:
> I have never had as much trouble with a perl script as I am having now with
> the Net::Telnet module. I am trying to telnet to many machines, one at a
> time so I can do a "health check" of the system. When I try to telnet to the
> machines, (Sun E3000s, E4000s, E6000s, E10000s, SSPs (ultra 5s), HP 9000s, HP
> 735, HP E45s) It gets past the point of the login/password but times out
> before my first command can execute.
You can save yourself much trouble by reading the pertinent
sections of the manpage that comes with the Net::Telnet module.
In particular the section "What To Know Before Using" and the
description for login() - which you say is failing.
Based on the code you provide in a later post, it doesn't appear
as those you realize you must provide an expected prompt for
login(). This is well documented.
scott@sboss.net writes:
> Here is some of the code I have tried....
>
> #!/usr/bin/perl -w # $|=1; $login="root"; $pass='password is removed'; use
> Net::Telnet; # $t = new Net::Telnet (Timeout=>300); print "1";
> $t->open("1.1.2.2"); # real IP removed so I do not get in trouble with
> Security print "2"; $t->login($login,$pass); print "6"; print $t->cmd(String
> => "/bin/ls"); print "7"; $t->close; print ".\n";
Since you say you are trying to do a health check on many
machines, you may be interested in the utility "fping" (it can be
found on the 'net). It can be used to quickly make a first pass
at identifying which hosts are unreachable.
--
Jay Rogers
jay@rgrs.com
------------------------------
Date: Wed, 28 Apr 1999 13:32:44 -0400
From: "sanjiv" <sjivan@yahoo.com>
Subject: Transactions not working with ODBC module
Message-Id: <NP#e01Zk#GA.231@news1.i2.com>
Hi,
I am using a System DSN to an Access Database. According the the MS docs,
the MS Access driver supports transactions. However I am not able to get
this simple piece of code to work
use Win32::ODBC;
my($db) = new Win32::ODBC('MyDSN');
$db->SetConnectOption('SQL_AUTOCOMMIT_OFF');
$val = $db->GetFunctions($db->SQL_API_SQLTRANSACT);
print " Is Transaction Supported : $val\n"; # returns 1
$sql = "insert into MyTable(name) values ('Sanjiv')";
#$sql ="delete * from Sanjiv";
if ($db->sql($sql)) {
die "Died on $sql: " . $db->Error();
}
$db->Transact('SQL_ROLLBACK');
print "done";
$db->Close();
exit();
This piece of code should first insert a record and since the transaction is
aborted, it should undo this insert.
However the record is inserted in the db. Similarly, the delete query doesnt
work.
Has anyone sucessfully used transactions with an ODBC connection to an
Access DB?
Thanks,
Sanjiv
------------------------------
Date: Wed, 28 Apr 1999 10:04:04 -0600
From: Peter Bowen <bowen@imall.com>
Subject: Re: Using Expect to run Top
Message-Id: <37273174.9921B9C2@imall.com>
Ok -
"Can't locate Expect.pm in @INC at test_expect line 2"
Is it where it belongs. I'm wondering if you are running the correct
perl (executable) on your machine - Perl is in usr/local/bin and you're
installing the modules under /usr/freeware/lib. However not a big
deal. Change the use lines to...
use lib "/usr/freeware/lib/perl5/site_perl";
use Expect;
use IO::Pty;
use IO::Tty;
use IO::Stty;
I am assuming that "/usr/freeware/lib/perl5/site_perl" is the correct
path. You are looking for Expect.pm It must be in the path refrenced
with the use lib. BTW - I ran the script using your code w/ my changes
(w/ my paths of course), and it worked but produced nothing. My Top is
a little different, and it was a modules issue so I didn't pursue it.
Good Luck!
-Peter
*** If you were afraid that I glossed over the "Can't call method
"spawn" in empty package "Expect" at run_top7 line8", It's because libs
point to places where the modules live, and perl had NO idea what you
were trying to do. I also found it interesting that the use lines were
missing closing quotes. (I'm assuming it was typed and not copied :)
montereykent@my-dejanews.com wrote:
>
> I wanted to run top from a cron job, capturing the output to a file.
> I thought the expect module would allow me to do this.
>
> Downloaded and did the typical perl installation of Expect.pm-1.07,
> IO-Stty-.02 and IO-Tty-0.02: perl Makefile.PL, make, make install
>
> When I try to put "use Expect in my code I get:
>
> "Can't locate Expect.pm in @INC at test_expect line 2".
>
> What's up?
>
> I next tried putting in the explicit path to the modules in my code, they are
> there:
>
> This code was based on chapter 15:13 of the Perl Cookbook "Controlling
> Another Program with Expect".
>
> #!/usr/local/bin/perl
>
> use lib "/usr/freeware/lib/perl5/site_perll/Expect";
> use lib "/usr/freeware/lib/perl5/site_perl/IO/Pty;
> use lib "/usr/freeware/lib/perl5/site_perl/IO/Tty;
> use lib "/usr/freeware/lib/perl5/site_perl/IO/Stty;
>
> $command = Expect->spawn("/usr/sbin/top -D /tmp/top.dump") or print
> "Can't spawn to : $!\n";
>
> $command->log_stdout(0);
> sleep(6);
> print $command "D";
> $command->hard_close();
>
> When this runs I get:
> "Can't call method "spawn" in empty package "Expect" at run_top7 line8.
>
> Thank you for any assistance you can provide,
> John Kent
> Naval Research Laboratory
> Monterey, CA
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
--
Peter Bowen
Unix System Programmer
iMALL Inc.
bowen@imall.com
(801)226-5007
------------------------------
Date: Wed, 28 Apr 1999 10:28:42 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Using string content as an a variable name
Message-Id: <3727454A.F105EE1F@mail.cor.epa.gov>
Ronny wrote:
>
> When you execute
>
> $x="y"; $y="abc"; print "$$x\n"
>
> abc gets printed. The important thing to note is that $x contains the variable
> name without a leading "$", i.e. if you wrote $x="$y", this would not work.
> You can also use this construct to change the value of $y:
>
> $$x="xyz"; # sets $y
>
> For more sophisticated applications, you may want to look at the eval
> function.
I would say that the *important* thing to note is that using
symbolic references is deprecated in modern Perl. For more
sophisticated applications, you may want to look at FAQ 7.28, which
Tom posted just *yesterday*:
Subject: FAQ 7.28: How can I use a variable as a variable name?
(This excerpt from perlfaq7 - Perl Language Issues
($Revision: 1.25 $, $Date: 1999/04/14 03:46:19 $)
part of the standard set of documentation included with every
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq7.html
if your negligent system adminstrator has been remiss in his duties.)
How can I use a variable as a variable name?
Beginners often think they want to have a variable contain the name
of a variable.
$fred = 23;
$varname = "fred";
++$$varname; # $fred now 24
This works *sometimes*, but it is a very bad idea for two reasons.
The first reason is that they *only work on global variables*. That
means above that if $fred is a lexical variable created with my(),
that the code won't work at all: you'll accidentally access the
global and skip right over the private lexical altogether. Global
variables are bad because they can easily collide accidentally and
in general make for non-scalable and confusing code.
Symbolic references are forbidden under the `use strict' pragma.
They are not true references and consequently are not reference
counted or garbage collected.
The other reason why using a variable to hold the name of another
variable a bad idea is that the question often stems from a lack of
understanding of Perl data structures, particularly hashes. By
using symbolic references, you are just using the package's symbol-
table hash (like `%main::') instead of a user-defined hash. The
solution is to use your own hash or a real reference instead.
$fred = 23;
$varname = "fred";
$USER_VARS{$varname}++; # not $$varname++
There we're using the %USER_VARS hash instead of symbolic
references. Sometimes this comes up in reading strings from the
user with variable references and wanting to expand them to the
values of your perl program's variables. This is also a bad idea
because it conflates the program-addressable namespace and the
user-addressable one. Instead of reading a string and expanding it
to the actual contents of your program's own variables:
$str = 'this has a $fred and $barney in it';
$str =~ s/(\$\w+)/$1/eeg; # need double eval
Instead, it would be better to keep a hash around like %USER_VARS
and have variable references actually refer to entries in that
hash:
$str =~ s/\$(\w+)/$USER_VARS{$1}/g; # no /e here at all
That's faster, cleaner, and safer than the previous approach. Of
course, you don't need to use a dollar sign. You could use your own
scheme to make it less confusing, like bracketed percent symbols,
etc.
$str = 'this has a %fred% and %barney% in it';
$str =~ s/%(\w+)%/$USER_VARS{$1}/g; # no /e here at all
Another reason that folks sometimes think they want a variable to
contain the name of a variable is because they don't know how to
build proper data structures using hashes. For example, let's say
they wanted two hashes in their program: %fred and %barney, and to
use another scalar variable to refer to those by name.
$name = "fred";
$$name{WIFE} = "wilma"; # set %fred
$name = "barney";
$$name{WIFE} = "betty"; # set %barney
This is still a symbolic reference, and is still saddled with the
problems enumerated above. It would be far better to write:
$folks{"fred"}{WIFE} = "wilma";
$folks{"barney"}{WIFE} = "betty";
Another reason that folks sometimes think they want a variable to
contain the name of a variable is because they don't know how to
build proper data structures using hashes. For example, let's say
they wanted two hashes in their program: %fred and %barney, and to
use another scalar variable to refer to those by name.
$name = "fred";
$$name{WIFE} = "wilma"; # set %fred
$name = "barney";
$$name{WIFE} = "betty"; # set %barney
This is still a symbolic reference, and is still saddled with the
problems enumerated above. It would be far better to write:
$folks{"fred"}{WIFE} = "wilma";
$folks{"barney"}{WIFE} = "betty";
And just use a multilevel hash to start with.
The only times that you absolutely *must* use symbolic references
are when you really must refer to the symbol table. This may be
because it's something that can't take a real reference to, such as
a format name. Doing so may also be important for method calls,
since these always go through the symbol table for resolution.
In those cases, you would turn off `strict 'refs'' temporarily so
you can play around with the symbol table. For example:
@colors = qw(red blue green yellow orange purple violet);
for my $name (@colors) {
no strict 'refs'; # renege for the block
*$name = sub { "<FONT COLOR='$name'>@_</FONT>" };
}
All those functions (red(), blue(), green(), etc.) appear to be
separate, but the real code in the closure actually was compiled
only once.
So, sometimes you might want to use symbolic references to directly
manipulate the symbol table. This doesn't matter for formats,
handles, and subroutines, because they are always global -- you
can't use my() on them. But for scalars, arrays, and hashes -- and
usually for subroutines -- you probably want to use hard references
only.
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior Computing Specialist phone: (541) 754-4468
mathematical statistician fax: (541) 754-4716
------------------------------
Date: Wed, 28 Apr 1999 11:49:38 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
To: blairk@istar.ca (Blair Kingsland)
Subject: Re: What does this error message mean?
Message-Id: <x3y676ghhil.fsf@tigre.matrox.com>
[Posted and CCed]
blairk@istar.ca (Blair Kingsland) writes:
> I'm running ActivePerl on an Apache server. The program output is
> correct, but I always get the following server error (warning)
> message:
>
> Value of <HANDLE> construct can be "0"; test with defined() at
> /usr/local/etc/httpd/htdocs/tigron/cgi-bin/glossary.pl line 65535.
>
> I can't find an explanation of this message anywhere. What does "line
> 65535" mean? The program file is only 25 lines long. Any help would be
> appreciated.
All of Perl's warning messages are explained in the 'perldiag'
documentation. Check it out for more info.
This specific warning indicates that you don't have the most recent
version of Perl :-)
Assuming you use a snippet of code similar to:
while ($line = <FH>) {
bla_bla();
}
Before version 5.005, you were required to test whether $line read a
'0' or not. If it did, then the code above will evalute to false
(since 0 is false), the while() loop will exit, and no more data will
be read from FH, even though the end of file has not been reached. To
solve this, you need to do:
while (defined($line = <FH>)) {
bla_bla();
}
In version 5.005 and later, the defined() is implicitly put for you,
so you don't need to worry about it.
HTH,
Ala
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 5507
**************************************