[20024] in Perl-Users-Digest
Perl-Users Digest, Issue: 2219 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 27 14:06:04 2001
Date: Tue, 27 Nov 2001 11:05:09 -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: <1006887908-v10-i2219@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 27 Nov 2001 Volume: 10 Number: 2219
Today's topics:
Re: A Perl Bug? <jake@chaogic.com>
Re: Can I avoid 2 passes? <Tassilo.Parseval@post.rwth-aachen.de>
Can I call a Perl subroutine from inside an HTML doc? <meuzelaj@student.dontspam.gvsu.edu>
Re: Do some time calculations... <andrew_harton@agilent.com>
Re: How to trap calls to undefined procedures at compil <dan@tuatha.sidhe.org>
Re: Internal Server Error <username@this.is.a.trap.graffl.net>
Re: Internal Server Error <admin@asarian-host.net>
Re: Internal Server Error <echang@netstorm.net>
Re: Internal Server Error <godzilla@stomp.stomp.tokyo>
Re: Intersectioning arrays nobull@mail.com
Re: New problem.. <mds@wam.umd.edu>
Re: PERL puzzler: Date re-ordering to meet xsd format? <kenfine@u.washington.edu>
Re: PERL puzzler: Date re-ordering to meet xsd format? (Helgi Briem)
Re: PERL puzzler: Date re-ordering to meet xsd format? <kenfine@u.washington.edu>
Re: PERL puzzler: Date re-ordering to meet xsd format? (John J. Trammell)
perl script (Bill Meyer)
Re: perl script <spam@thecouch.homeip.net>
PERL Script: telnet to WIN2K fails (Anand Ramamurthy)
Re: PERL Script: telnet to WIN2K fails <spam@thecouch.homeip.net>
Re: PERL Script: telnet to WIN2K fails <wolfram.pfeiffer@bigfoot.com>
Re: question about random~~~ help~~~ <5l259r001@sneakemail.com>
Re: Re: Do some time calculations... nobody@nowhere.com
Re: System call return value 256 - Bad file descriptor (Bryce Pursley)
Re: Top-posts <flavell@mail.cern.ch>
Using eval and $@ <peterca@ukgateway.net>
Re: Using eval and $@ nobull@mail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 27 Nov 2001 11:54:13 -0600
From: "Jake Fan" <jake@chaogic.com>
Subject: Re: A Perl Bug?
Message-Id: <9u0k0t$ftn$1@Masala.CC.UH.EDU>
Helgi Briem <helgi@decode.is> wrote:
> But here, there is always the danger of being answered
> by a clueless moron like you or Godzilla. A helpdesk
> usually has only clueful people like Randal, Uri or Tad
> answering questions. (My god, that would be a good
> helpdesk. )
What danger? I suspect that many (certainly not all) posters asking for
help here don't expect the luxury of being inspired by super-gurus. They
don't even expect "correct" answers. All they need is a hint, a keyword,
and google can take care of the rest.
Plus, a rational person shall not trust any answer as 100% precise and
correct until it's tested in a working program.
------------------------------
Date: Tue, 27 Nov 2001 20:03:12 +0100
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Can I avoid 2 passes?
Message-Id: <9u0o1g$nd0$03$1@news.t-online.com>
On Mon, 26 Nov 2001 19:57:28 -0800, Godzilla! wrote:
> Here is code exemplifying use of a true associative array.
> It is not as efficient as its equal in hash format. Still,
> this might inspire some intelligent extrapolation regarding
> efficiency of complex associative arrays and complex hashes.
>
>
> #!perl
>
> @Fruits = qw (apple plum grape orange);
>
> $user_input = "Fruits";
>
> print "@$user_input";
ethan@ethan:~$ perl -Mstrict
my @Fruits = qw (apple plum grape orange);
my $user_input = "Fruits";
print "@$user_input";
__END__
Can't use string ("Fruits") as an ARRAY ref while "strict refs" in use
at - line 3.
A true associative array, eh?
Better come back with a true associative array working under strictures
or return to your sandbox.
> What logical defining term would you tag to this array, @Menu?
[...]
Something that screws your symbol-table and hence is not allowed under
strict.
Tassilo
--
/*
* Please skip to the bottom of this file if you ate lunch recently
* -- Alan
*/
-- from Linux kernel pre-2.1.91-1
------------------------------
Date: Tue, 27 Nov 2001 12:55:48 -0500
From: "Moitz" <meuzelaj@student.dontspam.gvsu.edu>
Subject: Can I call a Perl subroutine from inside an HTML doc?
Message-Id: <u07l8f6g67fu54@corp.supernews.com>
I have a Perl script that generates an HTML form right from the get-go. Is
it possible to set that form to pass the data directly to a subroutine in my
script, instead of calling the script again, and then looping through an
if...elsif loop to decide what to do next?
moitz
------------------------------
Date: Tue, 27 Nov 2001 17:08:11 -0000
From: "Andrew Harton" <andrew_harton@agilent.com>
Subject: Re: Do some time calculations...
Message-Id: <1006880902.291784@cswreg.cos.agilent.com>
"nobody" <nobody@nobody.com> wrote in message
news:iJOM7.152944$QL2.4343163@amsnews03.chello.com...
>
> What I want to do now is use time() to get only the
> date with time 00:00:00.
print scalar localtime(int(time()/86400)*86400);
produces;
Tue Nov 27 00:00:00 2001
..well it does today anyway :-)
Andrew
------------------------------
Date: Tue, 27 Nov 2001 17:51:32 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: How to trap calls to undefined procedures at compile time
Message-Id: <EoQM7.72293$Y6.8068694@news1.rdc1.ct.home.com>
Peter Terpstra <terpstra@removepleasesmr.nl> wrote:
> cp@onsitetech.com (Curtis Poe) wrote in
> <9ttum3$jog@dispatch.concentric.net>:
>>I know of no way to accomplish that and frankly, I don't think it's
>>possible. With ease of access to symbol tables, AUTOLOAD, and
>>generating code on the fly, it would be impossible for Perl to know at
>>compile time if, in fact, a given function exists.
> I think this lack of verification is a serious flaw in the language
> design. It's a pity and makes Perl less suitable for large projects.
> Or do the Perl-language designers think that this is a feature and not a
> design flaw :)
It's neither a feature nor a flaw. The inability to do full compile-time
checking is a characteristic that perl shares with a whole host of
other languages. (Which generally get grouped together under the
"Dynamic Language" banner) It's a tradeoff of compile-time certainty
for runtime flexibility. That tradeoff may make perl less desirable in
some circumstances--the question, then, is whether perl's strengths
make up for those weaknesses in a particular situation. Sometimes they
do, and sometimes they don't.
It doesn't make perl worse or better than any other language, all
of which have a set of characteristics that should be evaluated
before they're used in any particular circumstance.
Dan
------------------------------
Date: Tue, 27 Nov 2001 16:07:34 -0000
From: "Andy Laurence" <username@this.is.a.trap.graffl.net>
Subject: Re: Internal Server Error
Message-Id: <9u0doe$5aq7t$1@ID-109625.news.dfncis.de>
> (snipped)
>
> > use CGI::Carp qw(fatalsToBrowser);
>
> You will benefit by reading your carp returned error messages:
The only error message I got was
--------
Internal Server Error
The server encountered an internal error or misconfiguration and was unable
to complete your request.
Please contact the server administrator, webmaster@themidwestgroup.com and
inform them of the time the error occurred, and anything you might have done
that may have caused the error.
More information about this error may be available in the server error log.
--------
> "syntax error at c:/apache/users//test/test.pl line 16,
> near ") print" Unmatched right curly bracket at
> c:/apache/users//test/test.pl line 18, at end of line
> syntax error at c:/apache/users//test/test.pl line 18, near "}"
> Execution of c:/apache/users//test/test.pl aborted due to compilation
errors."
AFAICS, line 18 is the blank one between $request="request.db"; and the open
statement. the only curly brackets I can see are at the end of the line
beginning 'while' and the last line. Am I going blind?
> > while (<REQUEST>)
>
> > print;
> > print "<A HRef=list.pl>edit</A><BR>";
> > }
>
>
> You are missing a right curly bracket after your while
> command as clearly delineated by your error message.
Interesting, as I can see the right curly bracket on my script, but the
right curly bracket has disappeared in my post. Someone else also mentioned
this when I made a similar post on a mailing list. The right curly bracket
is most definitely there in my script.
> while (<REQUEST>)
> {
> print;
> print "<A HRef=list.pl>edit</A><BR>";
> }
this is how my script reads.
Cheers for the input,
Andy <confused>
------------------------------
Date: Tue, 27 Nov 2001 16:47:09 GMT
From: "Mark" <admin@asarian-host.net>
Subject: Re: Internal Server Error
Message-Id: <hsPM7.75647$8q.10225581@bin2.nnrp.aus1.giganews.com>
"Andy Laurence" <username@this.is.a.trap.graffl.net> wrote in message
news:9u0bnr$5c783$1@ID-109625.news.dfncis.de...
> Hi All,
>
> while (<REQUEST>)
>
> print;
> print "<A HRef=list.pl>edit</A><BR>";
> }
> ---------
>
> I've been told that I didn't open the {} in the while statement, but
> it's on the first line of the statement (I'm not conventional).
> The script is so simple I don't know what could be wrong.
> The permissions are set 755 from the server console (I was worried
> Samba didn't work properly) and other scripts run fine from the
> same directory with the same permissions. Any help appreciated,
> TIA.
>
> Andy
>
Hi Andy,
As I was telling someone earlier today, in cases like this, it is very
useful to check the error_log. Depending on your platform, of course, it may
reside somewhere in the neighborhood of:
/usr/local/www/vhosts/your-site/logs/error_log
You told use you deliberately left out the { in the quotation of your code,
as it was the start of your code that you did not list here (not sure why
not). Well, since you also told us you are sending mail, things might go
wrong if you were trying to send mail, with sendmail, for instance, and
sendmail outputs an undesireable output to your web daemon.
Consider the following example:
----------------------------
#!/usr/bin/perl -w
use strict;
print "Content-type: text/html\n\n";
my $mailprog = '/usr/sbin/sendmail';
my $from = 'devnull@asarian-host.net';
my $to = 'postmasterasarian-host.net';
open (MAIL, "| $mailprog -f$from $to") || die $!;
close (MAIL);
exit 0;
----------------------------
Ok, I made a deliberate error in the $to address. Executing this script will
now cause an Internal Server Error. My error_log will say something like:
[Tue Nov 27 17:36:06 2001] [error] [client 212.238.195.5] malformed header
from script. Bad header=postmasterasarian-host.net... :
/usr/local/www/vhosts/asarian-host.net/cgi-bin/testcgi.cgi
You can prevent sendmail from generating such "malformed header" output, by
simple sending its output to the bitbucket:
open (MAIL, "| $mailprog -f$from $to >/dev/null") || die $!;
But what you probably might want to consider adding, is some proper email
validation prior to sending mail.
- Mark
------------------------------
Date: Tue, 27 Nov 2001 17:11:41 GMT
From: "E.Chang" <echang@netstorm.net>
Subject: Re: Internal Server Error
Message-Id: <Xns91667D21248A5echangnetstormnet@207.106.92.86>
"Andy Laurence" <username@this.is.a.trap.graffl.net> wrote in
news:9u0bnr$5c783$1@ID-109625.news.dfncis.de:
> Hi All,
>
> I'm struggling with 4 of my scripts. I'm trying to create a little
> system which E-Mails tasks to people. I've created a few bare
> scripts to run as I write them, but even the bare scripts are
> giving an 'internal server error'. Usually, this type of error
> would be if I had a typo in #!/usr/bin/perl but that's fine, and
> other's work ok too. I'll list one of the scripts here for you to
> pick at as it's truely baffled me. I'm not a Perl programmer so no
> laughing ok ;-)
>
> ---------
>#!/usr/bin/perl
> use CGI qw(:standard);
> use CGI::Carp qw(fatalsToBrowser);
>
> print "Content-type: text/html\n\n";
>
> $request="request.db"; #database path/filename
>
> open REQUEST, "$request" or die "Cannot open $request for read
> :$!";
>
> while (<REQUEST>)
>
> print;
> print "<A HRef=list.pl>edit</A><BR>";
> }
> ---------
>
> I've been told that I didn't open the {} in the while statement,
> but it's on the first line of the statement (I'm not conventional).
The bracket may have been removed by the reader's news client - it's
missing on mine too. With the bracket added, the script runs fine for
me, with CGI::Carp correctly reporting that the open failed because the
file doesn't exit.
> The script is so simple I don't know what could be wrong. The
> permissions are set 755 from the server console (I was worried
> Samba didn't work properly) and other scripts run fine from the
> same directory with the same permissions. Any help appreciated,
> TIA.
Did you try running the script from the server command line to see if
it conpiles properly there?
./scriptname
The error is occuring before CGI::Carp can catch it. The most likely
problem is that there is a bad end-of-line on the shebang line,
especialy since you are apparently transferring from Windows to Unix.
Are you uploading these recent scripts differently from the old ones?
The DOS newline characters may be being retained. You can edit the
file on the server (backspace to remove any bad end of line, then enter
a new one.) or use a local editor which will convert the file to Unix-
compatible line endings before you upload it. The error could also
occur if the use statement failed.
--
EBC
------------------------------
Date: Tue, 27 Nov 2001 10:06:57 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Internal Server Error
Message-Id: <3C03D641.FC159A4F@stomp.stomp.tokyo>
Andy Laurence wrote:
(snipped)
> > > use CGI::Carp qw(fatalsToBrowser);
> > You will benefit by reading your carp returned error messages:
> The only error message I got was
> Internal Server Error
> The server encountered an internal error or misconfiguration and was unable
This leaves only three suspect lines:
#!/usr/bin/perl
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
You have indicated previously you have checked your Perl
locale line and, it is ok. You also indicated permissions
are correctly set. Logic dictates there exists only two
problem lines:
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
Formats of those two lines are ok. This certainly
narrows down the nature of your problem, yes?
Your server error log will give precise details.
> > You are missing a right curly bracket after your while
> > command as clearly delineated by your error message.
> Interesting, as I can see the right curly bracket on my script, but the
> right curly bracket has disappeared in my post. Someone else also mentioned
> this when I made a similar post on a mailing list. The right curly bracket
> is most definitely there in my script.
I have not observed this behavior with numerous versions
of Microsoft Outlook Express.
Godzilla!
------------------------------
Date: 27 Nov 2001 18:01:38 +0000
From: nobull@mail.com
Subject: Re: Intersectioning arrays
Message-Id: <u9n118xfct.fsf@wcl-l.bham.ac.uk>
"Jonas Nilsson" <jonni@ifm.liu.nospam.se> writes:
> Is there a way to make arrays intersect?
>
> Like this (doen't work like I want).
>
> my @array1=("elem1","elem2","elem3");
> my @array2=("newelem1",\$array1[1]);
> my $scalar=\$array[2];
No, you can't do it with arrays in pure Perl. But just wait until I
publish Array::Splice. Unfortunately I haven't even started writing
it! But my PAUSE user ID arrived today so I'll be uploading an 'i'
("just an idea") state module RSN. Array::Splice is a working title
it may end up being called something else.
This module will export a splice() function that does what I think splice()
should have done all along.
use Array::Splice qw( splice ); # Replace inbuilt splice()
my @array1=("elem1","elem2","elem3");
my @array2=("newelem1");
splice @array2, 1, 0, $array1[1];
> But is there a way to make it more transparent, like making $scalar and
> $array2[1] pointing directly to the elements in @array1?
You declare lexical scalar aliases like this:
for my $scalar ( $array1[2] ) {
# $scalar is now alias for $array1[2]
}
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Tue, 27 Nov 2001 12:30:00 -0500
From: "Mike Schmitt" <mds@wam.umd.edu>
Subject: Re: New problem..
Message-Id: <9u0ine$o4q$1@hecate.umd.edu>
Bernard El-Hagin wrote in message ...
>This is in the FAQ. Part 3, by the way.
point it out, will ya?
thanx ;-)
------------------------------
Date: Tue, 27 Nov 2001 08:19:16 -0800
From: "Ken Fine" <kenfine@u.washington.edu>
Subject: Re: PERL puzzler: Date re-ordering to meet xsd format?
Message-Id: <9u0ef5$2p1c$1@nntp6.u.washington.edu>
This isn't homework ... just work (not nearly so much fun.)
I'll parse all of your suggestions. Thanks to everyone who lent a hand -
there's learning to be had even if someone walks you through a problem.
"Helgi Briem" <helgi@decode.is> wrote in message
news:3c03abbd.3476807805@News.CIS.DFN.DE...
> On Tue, 27 Nov 2001 06:17:10 -0800, "Ken Fine"
> <kenfine@hotmail.com> wrote:
>
> >7.1.2001
> >
> >How can I reorder it using PERL substitutions to meet the
> >xsd lexical form, which in the example above would be:
> >
> >2001-01-07
> >
> >It's a little trickier than your average PERL puzzle
>
> 1) It's Perl, not PERL.
>
> 2) Don't post homework questions.
>
> 3) Read perldoc -q "How do I pad a string with blanks or pad
>
> a number with zeroes?"
>
> 4) Reed perldoc -f split
>
> 5) Read perldoc -f sprintf
>
> 6) Here's one way:
>
> use strict;
> my $date = "7.1.2001";
> my ($day,$mth,$year) = split /\./,$date;
> $day = sprintf("%02d", $day);
> $mth = sprintf("%02d", $mth);
> $date = "$year-$mth-$day";
> __END__
>
> Regards,
> Helgi Briem
------------------------------
Date: Tue, 27 Nov 2001 17:01:03 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: PERL puzzler: Date re-ordering to meet xsd format?
Message-Id: <3c03c692.3483676963@News.CIS.DFN.DE>
On Tue, 27 Nov 2001 08:19:16 -0800, "Ken Fine"
<kenfine@u.washington.edu> wrote:
>This isn't homework ... just work (not nearly so much fun.)
>
>I'll parse all of your suggestions. Thanks to everyone who lent a hand -
>there's learning to be had even if someone walks you through a problem.
7) And don't top post. It'll ennoy the regulars
and cause them to ignore you, which means
you will only receive help from clueless morons.
Regards,
Helgi Briem
------------------------------
Date: Tue, 27 Nov 2001 09:03:00 -0800
From: "Ken Fine" <kenfine@u.washington.edu>
Subject: Re: PERL puzzler: Date re-ordering to meet xsd format?
Message-Id: <9u0h1a$2r48$1@nntp6.u.washington.edu>
John,
The confusing format is designed to meet an ISO standard for dates, which is
required for parsing XSD schema properly. My project involves stripping XML
data into tables in a relational database using MSSQLXML 2.0's BulkloadXML
object. Perl is just a very small part of a much bigger and broader project,
and the only reason I'm using it is because of some bad choices on my part
in my original XML specification.
So I'm a little amused that everyone thinks that I'm trying to get out of my
CS101 homework. If anyone cares to know more about what I've learned about
bulk loading XML, I'll be happy to help out without sending folks to the man
pages.
In the meantime, I'm still looking for a couple more spoon-fed answers to
help me finish my work. The instances in my XML source read as follows:
compiledate="8.1.2001"
I need to reorder all instances of this date per our earlier discussion, and
I need to know how to escape out the equals and quotes marks; a simple
backslash doesn't work
I also have another string that needs to be reordered (long story why it's a
dissimilar format...)
<pubdate>9-3-2001</pubdate>
If anyone can assist me, I can suggest what font you should use on your next
resume, or how to use Photoshop layer effects, or the finer points of xsd
Schema syntax. In any case, thanks again to the fine people who have helped
me out so far.
Ken
> But... yuck. So you're going from the confusing M.D.YYYY to the
> even more confusing YYYYDDMM? How about something unambiguous:
>
> 2001-1-Aug
>
> Or something that makes sense (from greatest to least significance,
> which is handy when sorting):
>
> 2001-07-01
>
> --
> [W]hen the manager knows his boss will accept status reports without
> panic or preeemption, he comes to give honest appraisals.
> - F. Brooks, _The Mythical Man-Month_
------------------------------
Date: Tue, 27 Nov 2001 11:32:56 -0600
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: PERL puzzler: Date re-ordering to meet xsd format?
Message-Id: <slrna07jno.hjc.trammell@haqq.el-swifto.com>
On Tue, 27 Nov 2001 09:03:00 -0800, Ken Fine <kenfine@u.washington.edu> wrote:
>
> The confusing format is designed to meet an ISO standard for dates, which is
> required for parsing XSD schema properly. My project involves stripping XML
> data into tables in a relational database using MSSQLXML 2.0's BulkloadXML
> object. Perl is just a very small part of a much bigger and broader project,
> and the only reason I'm using it is because of some bad choices on my part
> in my original XML specification.
Hrm. The only ISO standard for dates I know of is 8601, and that boils
down to YYYYMMDD in this case, e.g.
http://www.cl.cam.ac.uk/~mgk25/iso-time.html
> So I'm a little amused that everyone thinks that I'm trying to get out of my
> CS101 homework.
Not everyone. :-)
> In the meantime, I'm still looking for a couple more spoon-fed answers to
> help me finish my work. The instances in my XML source read as follows:
>
> compiledate="8.1.2001"
>
> I need to reorder all instances of this date per our earlier discussion, and
> I need to know how to escape out the equals and quotes marks; a simple
> backslash doesn't work
if ($string =~ /compiledate="\d+\.\d+\.\d+"/)
{
$string =~ s[compiledate="(\d+)\.(\d+)\.(\d+)"]
[sprintf('compiledate="%d-%02d-%02d"',$3,$2,$1)]e;
}
I may have gotten the ordering wrong here since I don't have your
spec handy. This is more than a bit ugly but very explicit.
> I also have another string that needs to be reordered (long story why it's a
> dissimilar format...)
>
> <pubdate>9-3-2001</pubdate>
[snip]
The same sort of solution applies. Regex, sprintf.
------------------------------
Date: 27 Nov 2001 09:48:04 -0800
From: bmeyer@raileurope.com (Bill Meyer)
Subject: perl script
Message-Id: <4456a3db.0111270948.7e98ccec@posting.google.com>
hello,
I have the following perl script
use HTTP::Request;
use LWP::UserAgent;
my $url = "http://www.techrepublic.com";
my $ua = LWP::UserAgent->new; #instantiate a user agent
my $request = HTTP::Request->new(GET => $url);
my $response = $ua->request($request);
if( $response->is_success ) {
# request succeeded
print $response->content;
} else {
# request failed
print $response->error_as_HTML;
}
This basically makes a http request and retrieves the information. I
would like to add a function to record the length of time it takes for
the request to be returned. Any ideas....Thanks in advance
------------------------------
Date: Tue, 27 Nov 2001 13:34:39 -0500
From: "Mina Naguib" <spam@thecouch.homeip.net>
Subject: Re: perl script
Message-Id: <%0RM7.17999$Mm.1793319@wagner.videotron.net>
"Bill Meyer" <bmeyer@raileurope.com> wrote in message
news:4456a3db.0111270948.7e98ccec@posting.google.com...
> hello,
>
> I have the following perl script
my $starttime = time;
>
> use HTTP::Request;
> use LWP::UserAgent;
>
> my $url = "http://www.techrepublic.com";
> my $ua = LWP::UserAgent->new; #instantiate a user agent
> my $request = HTTP::Request->new(GET => $url);
> my $response = $ua->request($request);
>
> if( $response->is_success ) {
> # request succeeded
> print $response->content;
> } else {
> # request failed
> print $response->error_as_HTML;
> }
my $totaltime = time - $starttime;
>
>
> This basically makes a http request and retrieves the information. I
> would like to add a function to record the length of time it takes for
> the request to be returned. Any ideas....Thanks in advance
The above 2 lines I added should set $totaltime to the amount of time your
code took. There are better ways out there using Benchmark I beleive, but
I'm not familiar with them.
The above will be accurate with up to a 2 second margin of error.
------------------------------
Date: 27 Nov 2001 09:09:05 -0800
From: anand_ramamurthy@yahoo.com (Anand Ramamurthy)
Subject: PERL Script: telnet to WIN2K fails
Message-Id: <761041e6.0111270909.6f05a573@posting.google.com>
I can telnet (manually) to a WIN2K box and run Windows commands.
But, my PERL script fails:
use strict;
use Net::Telnet;
my $t;
my $host = "xxx.xxx.x.xxx";
my $username = "user";
my $passwd = "passwd";
print "Telnet to [$host]\n";
$t = new Net::Telnet (Timeout => 120);
$t->open("$host");
print "Login with [$username]\n";
$t->login($username, $passwd);
print $t->cmd("date /t");
$t-> close;
I get following error:
D:\Anand\win>perl xx.pl
Telnet to [192.168.0.242]
Login with [user]
timed-out waiting for command prompt at xx.pl line 16
The script works well b/w UNIX boxes. Do I need to do anything
special for WIN.
Thank you
------------------------------
Date: Tue, 27 Nov 2001 12:32:37 -0500
From: "Mina Naguib" <spam@thecouch.homeip.net>
Subject: Re: PERL Script: telnet to WIN2K fails
Message-Id: <R6QM7.11164$et3.1738695@weber.videotron.net>
"Anand Ramamurthy" <anand_ramamurthy@yahoo.com> wrote in message
news:761041e6.0111270909.6f05a573@posting.google.com...
> I can telnet (manually) to a WIN2K box and run Windows commands.
> But, my PERL script fails:
>
> use strict;
> use Net::Telnet;
>
> my $t;
>
> my $host = "xxx.xxx.x.xxx";
> my $username = "user";
> my $passwd = "passwd";
>
> print "Telnet to [$host]\n";
> $t = new Net::Telnet (Timeout => 120);
>
> $t->open("$host");
> print "Login with [$username]\n";
>
> $t->login($username, $passwd);
>
> print $t->cmd("date /t");
>
> $t-> close;
>
>
> I get following error:
>
> D:\Anand\win>perl xx.pl
> Telnet to [192.168.0.242]
> Login with [user]
> timed-out waiting for command prompt at xx.pl line 16
>
>
> The script works well b/w UNIX boxes. Do I need to do anything
> special for WIN.
I've never used Net::Telnet or a win2k telnet server, but when you telnet to
the box, do the login prompts look exactly like this ?
login:
password:
?
And once successfully authenticated, what does the shell prompt look like ?
My guess is Net::Telnet expects to see the "login:" and "password:" as well
as something it recognizes as a shell prompt "#" to consider the login
successfull, and these conditions aren't being met.
>
> Thank you
------------------------------
Date: 27 Nov 2001 17:41:22 GMT
From: Wolfram Pfeiffer <wolfram.pfeiffer@bigfoot.com>
Subject: Re: PERL Script: telnet to WIN2K fails
Message-Id: <9u0j82$fqs$1@news.rz.uni-karlsruhe.de>
Anand Ramamurthy <anand_ramamurthy@yahoo.com> wrote:
> I can telnet (manually) to a WIN2K box and run Windows commands.
> But, my PERL script fails:
[snip Perl script]
> I get following error:
> D:\Anand\win>perl xx.pl
> Telnet to [192.168.0.242]
> Login with [user]
> timed-out waiting for command prompt at xx.pl line 16
> The script works well b/w UNIX boxes. Do I need to do anything
> special for WIN.
Did you read the Net::Telnet documentation?
perldoc Net::Telnet:
| o The methods "login()" and "cmd()" use the prompt setting
| in the object to determine when a login or remote
| command is complete. The method will fail with a time-
| out if you don't set the prompt correctly.
|
| [...]
|
| Login prompts must match either of the case
| insensitive patterns:
|
| /login[: ]*$/i
| /username[: ]*$/i
|
| Password prompts must match the case insensitive
| pattern:
|
| /password[: ]*$/i
|
| The command interpreter prompt must match the current
| setting of prompt.
|
| Use "dump_log()" to debug when this method keeps
| timing-out and you don't think it should.
HTH,
Wolfram
------------------------------
Date: Tue, 27 Nov 2001 20:03:45 +0100
From: "Steffen Müller" <5l259r001@sneakemail.com>
Subject: Re: question about random~~~ help~~~
Message-Id: <9u0o12$nbk$03$1@news.t-online.com>
"Logan Shaw" <logan@cs.utexas.edu> schrieb im Newsbeitrag
news:9tvpb3$1gl$1@starbuck.cs.utexas.edu...
| In article <9tvn7e$r5f$1@mail.cn99.com>, swansun <swansun@kali.com.cn>
wrote:
| >there is a question about random numbers troubles me many days
| >
| >using perl to create 5000 numbers that every numbers contains 6 digits.
[...]
| >and there are rules
| >1.these 5000 numbers must be diffrent with each other
|
| In that case, there are two approaches. The first is to keep track of
| the numbers already used and try again if you get one that has been
| used. The second is more complicated: instead of taking the random
| numbers straight, you use them to select an element from a set. To
| start with, the set is all possible 6-digit numbers and you remove ones
| as you pick them. (You'd have to come up with some implementation
| of sets where you don't need to store all elements.)
|
| In your case, I recommend the first approach because it's easier and
| the performance will be fine with the numbers you've given.
I wonder whether the second approach is possible without storing them all
(in the wider sense of RAM&HD) somehow. If you don't have them somewhere,
you need to keep track of the ones you supposedly removed, so you're at
approach one again. It doesn't make sense to me, but I'm neither into
computer science nor mathematics.
A thought on the following rule:
"5.those special numbers must distribute random in 5000 numbers"
If you are talking about few special numbers, the following script should
work.
Note that this *might* get into unlimited loops if the number of special
numbers is too high. Please excuse my posting lots of code and ugly code
that is. This is a hack, not a good program.
#!perl
use strict;
use warnings;
# synopsis:
# $indices_to_ignore =
# rule(
# \@array_of_numbers,
# \%hash_of_chosen_numbers, # (keys contain the data!)
# \%hash_of_indices_to_ignore, # (keys contain the data!)
# $fixed_number_of_matches,
# \&callback_sub_for_testing_match,
# \&callback_sub_for_making_match,
# \&callback_sub_for_removing_match
# );
sub rule {
my $array_ref = shift;
my $already_ref = shift;
my $forbidden = shift;
my $matches = shift;
my $test = shift;
my $fix = shift;
my $unfix = shift;
my %matches;
for ( my $i=0; $i < @$array_ref; ++$i) {
redo if $forbidden->{ $array_ref->[$i] };
$matches{$i}++ if $test->( $array_ref->[$i] );
}
print 'matches: ', scalar keys %matches, "\n";
return if keys(%matches) == $matches; # good.
if ( keys(%matches) < $matches ) { # not enough.
foreach ( 1 .. $matches - keys(%matches) ) {
# as often as matches are missing
my $index = int(rand @$array_ref); # random index
redo if $matches{$index} || $forbidden->{$index};
# retry if already a match or forbidden
$already_ref->{ $array_ref->[$index] } = 0; # not taken any more
$array_ref->[$index] = $fix->( $array_ref->[$index] );
# let the fix callback function modify it.
redo if $already_ref->{ $array_ref->[$index] };
$already_ref->{ $array_ref->[$index] }++; # register as taken
$matches{$index}++; # register as match.
}
} else { # too many matches.
foreach ( 1 .. keys(%matches) - $matches ) {
# as often as the number of excess matches
my @indices = keys %matches; # list of indices.
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# I do this because I'm unsure whether I can rely on
# Perl keeping the order of the hash keys as long as
# I don't modify the hash. One could use (keys %matches)[?]
# otherwise.
my $index = $indices[ int(rand @indices) ]; # random
# matching index
my $prev;
while (
$test->( $array_ref->[$index] ) || # still matching
$already_ref->{ $array_ref->[$index] } # or taken
) {
$prev = $array_ref->[$index];
$array_ref->[$index] = $unfix->( $array_ref->[$index] );
last if $prev eq $array_ref->[$index];
# do not get stuck in unlimited loops
}
redo if $prev eq $array_ref->[$index];
$matches{$index} = 0; # remove match.
}
}
return { %matches, %$forbidden };
}
my $needed = 5000;
my %already;
my @chosen;
while ($needed > 0)
{
my $chosen = int (rand (900_000)) + 100_000;
if (not $already{$chosen})
{
$already{$chosen}++;
push (@chosen, $chosen);
$needed--;
}
}
my $forbidden = rule( \@chosen,
\%already,
{},
2,
sub { substr($_[0], -4, 4) == 2222 },
sub { substr($_[0], 0, -4) . '2222' },
sub { int( rand 900_000) + 100_000 }
);
$forbidden = rule( \@chosen,
\%already,
$forbidden,
10,
sub { substr($_[0], -3, 3) == 222 },
sub { substr($_[0], 0, -3) . '222' },
sub { int( rand 900_000) + 100_000 }
);
$forbidden = rule( \@chosen,
\%already,
$forbidden,
100,
sub { substr($_[0], -2, 2) eq '02' },
sub { substr($_[0], 0, -2) . '02' },
sub { int( rand 900_000) + 100_000 }
);
HTH,
Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;$o=$_;push@o,substr($o,$_*8,8) for(0..
24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\r";$i++};print"\n"#stm
------------------------------
Date: Tue, 27 Nov 2001 18:29:41 GMT
From: nobody@nowhere.com
Subject: Re: Re: Do some time calculations...
Message-Id: <pYQM7.155472$QL2.4782888@amsnews03.chello.com>
>
> "nobody" <nobody@nobody.com> wrote in message
> news:iJOM7.152944$QL2.4343163@amsnews03.chello.com...
> >
> > What I want to do now is use time() to get only the
> > date with time 00:00:00.
>
> print scalar localtime(int(time()/86400)*86400);
>
> produces;
> Tue Nov 27 00:00:00 2001
>
> ...well it does today anyway :-)
>
> Andrew
>
>
>
It produces:
Tue Nov 27 01:00:00 2001
on my pc!
------------------------------
Date: Tue, 27 Nov 2001 18:51:56 GMT
From: hbpursle@duke-energy.com (Bryce Pursley)
Subject: Re: System call return value 256 - Bad file descriptor
Message-Id: <3c07e038.102151295@news.infoave.net>
I appreciate that Bob. I was about to decide that me and Godzilla
were the only two people around. I have seen this happen before but
it's the first time it's ever happened to me. I'll live.
Bryce
On Tue, 27 Nov 2001 09:38:22 -0600, "Bob Dover"
<dover@nortelnetworks.com> wrote:
>"Bryce Pursley" wrote in message news:3c0584f0.78783464@news.infoave.net...
>>
>> You give this group a bad name. I guess that's why you don't even
>> want to use yours.
>
>Hang around, though. Signal-to-noise ratio is pretty good here.
>
>-BD
>
------------------------------
Date: Tue, 27 Nov 2001 17:24:03 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Top-posts
Message-Id: <Pine.LNX.4.30.0111271719110.16273-100000@lxplus023.cern.ch>
On Nov 27, Andrew Hamm inscribed on the eternal scroll:
> >When you've promoted your deviant scheme on the appropriate news
> Not my deviant scheme
Apologies for the poor choice of words. I would better have said
something like "the scheme to which you were referring". No offence
meant.
------------------------------
Date: Tue, 27 Nov 2001 16:06:28 +0000
From: Peter Cameron <peterca@ukgateway.net>
Subject: Using eval and $@
Message-Id: <3c03ba79$0$8514$cc9e4d1f@news.dial.pipex.com>
I'm forwarding this on behalf of a colleague:
Hello,
I need help using the perl 'eval' function which doesn't seem to work on my
Unix system.
I am trying to trap an exception using open2 on a process which is not
available.
$Rbin = "Run a process which has no licence";
eval { open2(\*README , \*WRITEME, $Rbin); };
if ( $@) {
die "Error submitting run:$@\n Check licence is available";
} else {
print WRITEME "\n";
print WRITEME "\n";
while (<README>) {
etc...
Running this with the perl debugger, it crashes when I print to WRITEME.
I've tried enclosing
the 'print' line in an eval block, but $@ is still not set.
I need to trap the error submitting the process. It could be no licence,
too many users,
no disk space, whatever.
Can anyone help?
Ceri
------------------------------
Date: 27 Nov 2001 18:01:24 +0000
From: nobull@mail.com
Subject: Re: Using eval and $@
Message-Id: <u9ofloxfd7.fsf@wcl-l.bham.ac.uk>
Peter Cameron <peterca@ukgateway.net> writes:
> I need help using the perl 'eval' function which doesn't seem to work on my
> Unix system.
The Perl eval function traps errors if the form of thown execptions
that would otherwise cause Perl to terminate.
Most Perl functions (inbuilt or in popular modules) that deal with the
outside world do not indicate failure by throwing exceptions, they
return success codes as their return values. For details see the
documentation of those functions.
> I am trying to trap an exception using open2 on a process which is not
> available.
When performing operations that involve creating an aynchronous
subprocess the subprocess the function that creates the subprocess
cannot report in any way that the subprocess subsequently terminates
abnormally because this would require information to travel backwards
in time. This has nothing to do with Perl. This is fundamental
physics.
> $Rbin = "Run a process which has no licence";
> eval { open2(\*README , \*WRITEME, $Rbin); };
> if ( $@) {
> die "Error submitting run:$@\n Check licence is available";
> } else {
> print WRITEME "\n";
> print WRITEME "\n";
> while (<README>) {
> etc...
>
>
> Running this with the perl debugger, it crashes when I print to WRITEME.
> I've tried enclosing
> the 'print' line in an eval block, but $@ is still not set.
Ahh... this is probably a SIGPIPE problem.
For historical reasons in POSIX writing to a pipe the other end of
which has been closed can be treated as much more serious than normal
IO errors. It actually does throw an exception ("syncronous signal")
at the operating system level which terminates the running process
with extreem prejudice. This operating system level exception is not
trapped by eval. Trapping of signals is achieved using the %SIG
special variable.
I suggest that in Perl you say:
$SIG{PIPE} = 'IGNORE';
This will make EPIPE behave like an ordinary IO error. (i.e. the Perl
the print() to WRITEME will complete without throwing any kind of
exception return but false and $! will contain the numeric and string
forms of EPIPE).
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 2219
***************************************