[24216] in Perl-Users-Digest
Perl-Users Digest, Issue: 6408 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 16 00:05:58 2004
Date: Thu, 15 Apr 2004 21:05:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 15 Apr 2004 Volume: 10 Number: 6408
Today's topics:
Re: A serious question about cgi (intermediate-newbie) <robin @ infusedlight.net>
Grabbing data from telnet host (Mark)
Re: Handling international characters in filenames on W <kalinaubears@iinet.net.au>
Re: Many filename arguments: EOF in "while(@slurp=<>){. <fma@doe.carleton.ca>
Re: One question <andy@andyh.co.uk>
Re: One question <edgrsprj@ix.netcom.com>
Re: One question <emschwar@pobox.com>
Re: Perl Script Not Running From Crontab. <tadmc@augustmail.com>
Re: Perl Script Not Running From Crontab. <nospam@bigpond.com>
Re: question about substr <robin @ infusedlight.net>
Re: question about substr <tore@aursand.no>
Re: question about substr <bart.lateur@pandora.be>
Re: question about substr <matthew.garrish@sympatico.ca>
recording votes (user99)
Re: recording votes <robin @ infusedlight.net>
Re: recording votes <matthew.garrish@sympatico.ca>
Re: recording votes <wherrera@lynxview.com>
Re: strange side-effect (bug?) in Net::SMTP <invalid-email@rochester.rr.com>
Re: Two mini-golfish problems (Xavier Noria)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 15 Apr 2004 15:33:43 -0700
From: "Robin" <robin @ infusedlight.net>
Subject: Re: A serious question about cgi (intermediate-newbie)
Message-Id: <c5n4am$ut8$1@reader2.nmix.net>
"Vetle Roeim" <vetro@online.no> wrote in message
news:m33c75ndtu.fsf@quimby.dirtyhack.org...
> * robin @ infusedlight.net
> > I'm beginng to understand cgi.pm....and I'm wondering if there's any
> > way to deny a client side user their privelege to submit a form over
> > and over again by clicking back on their browser and submitting it
> > again or clicking the button to submit the form before the page with
> > the form goes on to the next page...do I have to log ips or
> > something?
>
> You can generate a "ticket" that can only be used
> once. I.e. generate a ticket when the form is accessed, and check
> that the ticket is valid in the Perl code that recieves the form
> data when the user clicks the submit button.
good point. Thanks.
-Robin
------------------------------
Date: 15 Apr 2004 17:41:49 -0700
From: markp@asnet.co.nz (Mark)
Subject: Grabbing data from telnet host
Message-Id: <a7195d8e.0404151641.4f78155a@posting.google.com>
I have a script setup to log into a host using the Net::Telnet CPAN
module.
It logs on to this host, sends a username and password and then sends
some commands, prints a message to the screen and then closes the
session.
This is working fine for the purpose but I would like to modify it so
that I can get a status of the host before I send commands to change
the configuration of the host.
I would like to do something like the following: (bear with me my
psuedocode aint that great)
get <system route table>
put output -> $variable
grep $variable "0.0.0.0 0.0.0.0 192.168.1.1" -> $newvariable
if $newvariable = "0.0.0.0 0.0.0.0 192.168.1.1" then
print = "Device online"
else
print = "Device not online"
end if
Any ideas?
------------------------------
Date: Fri, 16 Apr 2004 09:51:28 +1000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: Handling international characters in filenames on Win32
Message-Id: <407f2127$0$16598$5a62ac22@freenews.iinet.net.au>
Stéphane Bourdeaud wrote:
> Hi,
>
> I am struggling with handling accented characters in Win32 long filenames
> correctly in Perl.
>
> If I try to get a recursive list of directories in a given path by doing
> something like this:
>
> my @list = `dir /a:d /b /s $path`;
>
> Where $path is a user specified path (and yes, the path does exist, yes I
> chomp @list before using it, and yes this does work when there are no
> international characters in the sub directories names).
>
> If I then look at the values stored in @list or try to use them, if they do
> contain an international character (such as an accented vowel), then the
> call fails because the path can't be found (even though it does exist).
>
> Any ideas on how I could get Perl to store the path names correctly in that
> array?
>
> Any help would be appreciated.
>
Sounds like one of those codeset conversion problems. DOS uses cp850 and
windows uses cp1252 which is the same for 'normal' characters but
differs wrt wide characters. It's a fairly simple task using Text::Iconv
to convert from one to the other - which would be one way to get around
the problem. It's probably just as simple to convert from one to the
other using the Encode module which is part of the perl core with perl
5.8 (though I've not used it).
Alternatively, if you use perl functions (rather than a sytem command)
to fill @list then the problem might go away. (I think that will work
because it will keep you within the one codeset - but I'm unsure :-)
Cheers,
Rob
--
To reply by email u have to take out the u in kalinaubears.
------------------------------
Date: 16 Apr 2004 02:30:10 GMT
From: Fred Ma <fma@doe.carleton.ca>
Subject: Re: Many filename arguments: EOF in "while(@slurp=<>){..}"?
Message-Id: <407F452C.1B8F9E9F@doe.carleton.ca>
Joe Smith wrote:
>
> The things to remember are:
> After {my $line = <INFILE>} returns anything, the file handle is
> still open. It stays that way until eof, when it returns undef.
> Using this syntax in a while() loop is the usual practice.
>
> After {my @lines = <INFILE>}, the entire file has been read
> all the way to eof. It is not wise to attempt to read any more.
>
> <> is magic. It reads all the files whose names are in @ARGV,
> all the way to eof on all of them. (A "-" in $ARGV[0] or an
> empty @ARGV means to read from STDIN.)
>
> Therefore: Putting a slurp from <> in a while statement is not
> what you want to do. It's going to return undef the second time
> around and STDIN on the third.
>
> Do not slurp when using "perl -pi.bak".
> -Joe
Got it. Thanks.
Fred
--
Fred Ma
Dept. of Electronics, Carleton University
1125 Colonel By Drive, Ottawa, Ontario
Canada, K1S 5B6
------------------------------
Date: Thu, 15 Apr 2004 23:07:31 +0100
From: Andy Hassall <andy@andyh.co.uk>
Subject: Re: One question
Message-Id: <is1u70t4bc1ouep736lu7dri38esu4c646@4ax.com>
On Thu, 15 Apr 2004 21:43:35 GMT, "edgrsprj" <edgrsprj@ix.netcom.com> wrote:
>Q: Is it possible to have Perl generate a copy of a program which can run
>by itself as an .exe program for example without the need to have Perl on
>the system?
>
>If it is possible, how do you do that?
Search for PAR (Perl Archive Toolkit).
--
Andy Hassall <andy@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
------------------------------
Date: Thu, 15 Apr 2004 22:18:20 GMT
From: "edgrsprj" <edgrsprj@ix.netcom.com>
Subject: Re: One question
Message-Id: <MSDfc.10167$zj3.8126@newsread3.news.atl.earthlink.net>
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnc7u2l5.efa.tadmc@magna.augustmail.com...
> edgrsprj <edgrsprj@ix.netcom.com> wrote:
> What programming language _is_ forgiving regarding code violations?
I like this one version of Basic that I used for years. If you did
something wrong then when you told it to run it let you know in no uncertain
terms that you were mistaken!
A problem with running Perl from Windows is the fact that if you start a
program using a shortcut file and there is an error in it, nothing happens.
The screen flashes for a second and you have no idea what went wrong. There
are ways around that. But I have not yet figured out how to best deal with
the problem. You can start it from DOS and see the error messages. But
that means more work dropping down to DOS and changing directories etc
But as I said, I like Perl. And I will eventually probably be making some
suggestions regarding the creation of a powerful new module for inclusion
with the ActivePerl downloadable program. I contacted ActiveState about it
a while back and they sounded interested.
------------------------------
Date: Thu, 15 Apr 2004 17:13:57 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: One question
Message-Id: <etopta8ltqi.fsf@fc.hp.com>
"edgrsprj" <edgrsprj@ix.netcom.com> writes:
> The number of characters in the lines on different system is confusing it.
> With my system I told it to compare the string with the complete line minus
> one character. With other systems that apparently causes an error. This is
> easy to correct. When it reads a fixed number of characters on the line it
> runs Ok.
I strongly recommend spending some time with Learning Perl and the
Camel book. One of the things you'll pick up quickly is that when
you're reading lines from a file, and you don't care about the
line-ending characters, you should use chomp(). Read the
documentation for chomp with 'perldoc -f chomp' for more details.
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
------------------------------
Date: Thu, 15 Apr 2004 18:29:59 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Perl Script Not Running From Crontab.
Message-Id: <slrnc7u6nn.elq.tadmc@magna.augustmail.com>
Matt Cluver <cluver@netdepict.com> wrote:
> I'm having a problem with crontab running my perl script, it runs
> perfectly fine from the prompt while logged in. The script is chmodded
> to 777, I have included a lib statement to take care of possible
> enviroment variable issues.
A "use lib" statement does not take care of all possible environment
variable issues.
> I would appreciate someone taking a look, thanks in advance.
> Crontab:
> 0 0 * * * perl /full/path/to/qotd.pl
> use lib '/full/path/to/cgi-bin';
> require ".sys.conf";
> use rcgi;
Is this program supposed to run in the cron environment or in
a CGI environment?
You can't (easily) get both.
What is rcgi.pm?
> if ($d{'cmd'} eq "prcsAdd") {
> $cgi->print_header();
> &page_header();
> &process_add();
> &page_footer();
> exit();
> }
Indent code blocks.
Don't use ampersands on function calls unless you know what it means,
and what it means is what you want.
> open (QUOTE, ">/full/path/to/quote.html");
You should always, yes *always*, check the return value from open():
open (QUOTE, ">/full/path/to/quote.html") or
die "could not open '/full/path/to/quote.html' $!";
> print QUOTE "$quote[0]";
You should not use useless quotes:
print QUOTE $quote[0];
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 16 Apr 2004 11:18:58 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: Perl Script Not Running From Crontab.
Message-Id: <60117961.Mz90U2tasU@GMT-hosting-and-pickle-farming>
Matt Cluver wrote:
> Hello All,
>
> I'm having a problem with crontab running my perl script, it runs
> perfectly fine from the prompt while logged in. The script is chmodded
> to 777, I have included a lib statement to take care of possible
> enviroment variable issues.
>
> I would appreciate someone taking a look, thanks in advance.
>
> Cheers!
>
> Matt
>
> Crontab:
> 0 0 * * * perl /full/path/to/qotd.pl
>
It may be easier to run in a known directory:
0 0 * * * (cd /full/path/to/; perl /qotd.pl)
or if you are using linux
HOME=/full/path/to/
0 0 * * * perl qotd.pl
gtoomey
------------------------------
Date: Thu, 15 Apr 2004 15:37:42 -0700
From: "Robin" <robin @ infusedlight.net>
Subject: Re: question about substr
Message-Id: <c5n4ap$ut8$2@reader2.nmix.net>
"Chuck" <EatMeSpammers_cwtart@commpay.tv> wrote in message
news:0wxfc.985$KG2.1629@reggie.win.bright.net...
> I am a new perl learner and have a question about substr
>
> Does the starting string position x in substr("string",x,y) need to be set
> to zero to start reading at the 1st postion or set to one? I found some
> examples that seem to show it both ways - am I assuming correctly that the
> starting postion parameter is always one less than the position you want
to
> start at?
RTFM.
and it's 0
-Robin
------------------------------
Date: Fri, 16 Apr 2004 04:21:37 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: question about substr
Message-Id: <pan.2004.04.16.02.21.03.203039@aursand.no>
On Thu, 15 Apr 2004 11:48:06 -0500, Chuck wrote:
> I checked the docs and the book "perl in a nutshell" and found two
> different examples with conflicting data
> [...]
Really? I don't have that book you refer to at hand, but it would be
interesting to see those examples.
Anyway. You _couldn't_ have looked it up in the Perl documentation.
What's unclear with the documentation for the 'substr' function? It says
very clear that strings are zero-based;
substr EXPR,OFFSET,LENGTH
substr EXPR,OFFSET
Extracts a substring out of EXPR and returns it. First charac-
ter is at offset 0, or whatever you've set $[ to (but don't do
that).
What is it that you don't understand with this? And - if you're still in
doubt - why don't try it yourself? It would certainly have given you the
answer much faster.
And: Please don't top-post. It's a bad thing.
--
Tore Aursand <tore@aursand.no>
"There are three kinds of lies: lies, damn lies, and statistics."
(Benjamin Disraeli)
------------------------------
Date: Fri, 16 Apr 2004 02:36:37 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: question about substr
Message-Id: <8jhu70d1molfqtdu4iakap6epqii7t3sjp@4ax.com>
Chuck wrote:
>Does the starting string position x in substr("string",x,y) need to be set
>to zero to start reading at the 1st postion or set to one? I found some
>examples that seem to show it both ways - am I assuming correctly that the
>starting postion parameter is always one less than the position you want to
>start at?
I find it easier to think of it this way:
the offset x is the number of characters you want to skip.
So yes, to start at the very first position, this offset is 0.
--
Bart.
------------------------------
Date: Thu, 15 Apr 2004 22:42:17 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: question about substr
Message-Id: <8KHfc.30055$vF3.1771083@news20.bellglobal.com>
"Robin" <robin @ infusedlight.net> wrote in message
news:c5n4ap$ut8$2@reader2.nmix.net...
>
> "Chuck" <EatMeSpammers_cwtart@commpay.tv> wrote in message
> news:0wxfc.985$KG2.1629@reggie.win.bright.net...
> > I am a new perl learner and have a question about substr
> >
> > Does the starting string position x in substr("string",x,y) need to be
set
> > to zero to start reading at the 1st postion or set to one? I found some
> > examples that seem to show it both ways - am I assuming correctly that
the
> > starting postion parameter is always one less than the position you want
> to
> > start at?
>
> RTFM.
> and it's 0
> -Robin
>
>
For someone who's never bothered to read that same manual, your posturing is
quite amusing.
Matt
------------------------------
Date: 15 Apr 2004 16:12:27 -0700
From: user99@austin.rr.com (user99)
Subject: recording votes
Message-Id: <a16bd472.0404151512.be42d3e@posting.google.com>
my page has a drop down with names which
people can vote for. any ideas on how
i can record the individual count of
votes for each name. i'm thinking about
using a text file to store the names with
the vote count and incrementing the counts
and then write them back to the same file.
any better ideas????
------------------------------
Date: Thu, 15 Apr 2004 16:48:27 -0700
From: "Robin" <robin @ infusedlight.net>
Subject: Re: recording votes
Message-Id: <c5n876$cq$1@reader2.nmix.net>
"user99" <user99@austin.rr.com> wrote in message
news:a16bd472.0404151512.be42d3e@posting.google.com...
> my page has a drop down with names which
> people can vote for. any ideas on how
> i can record the individual count of
> votes for each name. i'm thinking about
> using a text file to store the names with
> the vote count and incrementing the counts
> and then write them back to the same file.
>
> any better ideas????
your way is how I did it for my poll unless your planning to use a database,
this seems like the best option to me....remember not to make your vote
files
world readable.
-Robin
------------------------------
Date: Thu, 15 Apr 2004 19:58:22 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: recording votes
Message-Id: <qkFfc.24338$2Z6.1012774@news20.bellglobal.com>
"Robin" <robin @ infusedlight.net> wrote in message
news:c5n876$cq$1@reader2.nmix.net...
>
> "user99" <user99@austin.rr.com> wrote in message
> news:a16bd472.0404151512.be42d3e@posting.google.com...
> > my page has a drop down with names which
> > people can vote for. any ideas on how
> > i can record the individual count of
> > votes for each name. i'm thinking about
> > using a text file to store the names with
> > the vote count and incrementing the counts
> > and then write them back to the same file.
> >
> > any better ideas????
>
> your way is how I did it for my poll unless your planning to use a
database,
> this seems like the best option to me....remember not to make your vote
> files
> world readable.
>
>
Care to share what steps you took to ensure that multiple instances of your
script aren't trying to read and write to the file at the same time?
Matt
------------------------------
Date: Thu, 15 Apr 2004 21:25:01 -0600
From: Bill <wherrera@lynxview.com>
Subject: Re: recording votes
Message-Id: <cY-dnUJrvc2Jz-LdRVn-jw@adelphia.com>
user99 wrote:
> my page has a drop down with names which
> people can vote for. any ideas on how
> i can record the individual count of
> votes for each name. i'm thinking about
> using a text file to store the names with
> the vote count and incrementing the counts
> and then write them back to the same file.
>
> any better ideas????
It's not perfect, but look at http://www.datacomm.ch/atair/perlscript/
------------------------------
Date: Fri, 16 Apr 2004 02:48:10 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: strange side-effect (bug?) in Net::SMTP
Message-Id: <407F462E.6050803@rochester.rr.com>
Ian D. wrote:
> This is perl, version 5.005_02 built for sun4-solaris
>
> I have an array that is wiped out when calling Net::SMTP->new. Here
> is a debug from it. Note my array is intact at line 356, but after a
> 'next', it is gone:
>
> main::check_mailservers(./conchk:356):
> 356: $smtp = Net::SMTP->new('ondar',Timeout=>10,Debug=>0);
> DB<2> x @MAILSERVERS
> 0 ARRAY(0x6ea244)
> 0 'sendmail'
> 1 'ondar'
> 2 'nobody@cablelabs.com'
> 3 'nobody@localhost'
> 4 150
So, @MAILSERVERS is a one-element array, the value of which is a
reference to another array with 5 elements. The first four of those
elements have values which are various strings, and the fifth has a
value which is an integer.
> DB<3> n
>
> main::check_mailservers(./conchk:357):
> 357: $td=tv_interval($t0);
> DB<3> x @MAILSERVERS
> 0 undef <======= WHAT THE HECK JUST HAPPENED???
And now @MAILSERVERS is still a one-element array, but the value of it
is now undef, rather than an array reference. This behavior could be
explained if junk450.pl is the following program:
D:\junk>type junk450.pl
$MAILSERVERS[0]=[
'sendmail',
'ondar',
'nobody@cablelabs.com',
'nobody@localhost',
150,
];
for $smtp (@MAILSERVERS){
$smtp=undef;
}
--------------------------------
and it is stepped through as follows:
--------------------------------
D:\junk>perl -d junk450.pl
Loading DB routines from perl5db.pl version 1.19
Editor support available.
Enter h or `h h' for help, or `perldoc perldebug' for more help.
main::(junk450.pl:1): $MAILSERVERS[0]=[
main::(junk450.pl:2): 'sendmail',
main::(junk450.pl:3): 'ondar',
main::(junk450.pl:4): 'nobody@cablelabs.com',
main::(junk450.pl:5): 'nobody@localhost',
main::(junk450.pl:6): 150,
main::(junk450.pl:7): ];
DB<1> s
main::(junk450.pl:8): for $smtp (@MAILSERVERS){
DB<1> s
main::(junk450.pl:9): $smtp=undef;
DB<1> x @MAILSERVERS
0 ARRAY(0x1558798)
0 'sendmail'
1 'ondar'
2 'nobody@cablelabs.com'
3 'nobody@localhost'
4 150
DB<2> n
main::(junk450.pl:8): for $smtp (@MAILSERVERS){
DB<2> x @MAILSERVERS
0 undef
DB<3>
Note the debug output which is identical to yours (except of course for
the address of the anonymous array and the line numbers).
>
> A bug?
Yes, in your code.
>
> Ian
>
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: 15 Apr 2004 15:45:40 -0700
From: fxn@hashref.com (Xavier Noria)
Subject: Re: Two mini-golfish problems
Message-Id: <31a13074.0404151445.58d956d7@posting.google.com>
"Ala Qumsieh" <xxala_qumsiehxx@xxyahooxx.com> wrote in message news:> The title does say "golf":
> $x=~s/..?/$&
> /g;
>
> :-)
Heh, but $n seems to be a parameter. If it was what about
$x=~s/(??{".?"x$n})/$&
/g;
What does the spec say about the empty string? :-)
-- fxn
------------------------------
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 6408
***************************************