[19473] in Perl-Users-Digest
Perl-Users Digest, Issue: 1668 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 31 11:05:32 2001
Date: Fri, 31 Aug 2001 08:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <999270308-v10-i1668@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 31 Aug 2001 Volume: 10 Number: 1668
Today's topics:
[OT] Re: Which language better <joe+usenet@sunstarsys.com>
A better way <jclover@nati.org>
Re: arrays question <ren@tivoli.com>
Re: Environment variables and AOL <samneric@tigerriverOMIT-THIS.com>
Re: Environment variables and AOL <jurgenex@hotmail.com>
Re: file search <bjlockie@nortelnetworks.com>
Finding differences in two text strings <gortona@cs.man.ac.uk>
Re: Finding differences in two text strings <kevin@vaildc.net>
Re: Finding differences in two text strings <ren@tivoli.com>
Re: help understanding this snippet <tomcat@visi.com>
Re: help understanding this snippet <ren@tivoli.com>
Re: help understanding this snippet (Anno Siegel)
Re: help understanding this snippet (Martien Verbruggen)
Re: help understanding this snippet (Martien Verbruggen)
Re: help with pipes please <ren@tivoli.com>
Re: most effective way to search for different words in <philippe.perrin@sxb.bsf.alcatel.fr>
Re: Network topology mapping (Adam)
Re: Passing arbitray data between ro co-operating per s (Stan Brown)
Re: Passing arbitray data between ro co-operating per s (Anno Siegel)
Re: Programming sockets <Crazydj@web.de>
Re: Programming sockets (Ronald Blaschke)
Re: Programming sockets <Crazydj@web.de>
Re: Programming sockets (Ronald Blaschke)
Q: File globbing and scalar vars <newspost@coppit.org>
Re: Q: File globbing and scalar vars (Ronald Blaschke)
Re: Q: File globbing and scalar vars (Rafael Garcia-Suarez)
Re: registration worries (Mr. Green)
Re: registration worries (Martien Verbruggen)
Re: unable to install AdminMisc Module <bart.lateur@skynet.be>
Re: Which language better <pmishra@mailcity.com>
Re: Which language better (Cameron Laird)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 31 Aug 2001 09:33:06 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: [OT] Re: Which language better
Message-Id: <m3d75cl5gt.fsf_-_@mumonkan.sunstarsys.com>
"John W. Krahn" <krahnj@acm.org> writes:
[...]
> The six best languages ...
>
>
> (no one expects the language inquisition)
>
I see- so you recommend Python then?
--
Joe Schaefer "Buy land. They've stopped making it."
--Mark Twain
------------------------------
Date: Fri, 31 Aug 2001 09:56:13 -0500
From: "Jonathan Clover" <jclover@nati.org>
Subject: A better way
Message-Id: <tov8vu1bmc4maf@corp.supernews.com>
I have this code to insert a new row into a database and I would like to
make the code, that's focused on(!) more concise, but am unsure on how.
Ideas anyone.
Jonathan Clover
NATI
P.S. @question will always and only contain 10 values
my $dbh = DBI->connect("DBI:CSV:f_dir=$database_dir")
or diehtml("Cannot connect: " . $DBI::errstr);
! $dbh->do( "insert into test_ans values
('$test','$questions[0]','$questions[1]','$questions[2]','$questions[3]','$q
uestions[4]','$questions[5]','$questions[6]','$questions[7]','$questions[8]'
,'$questions[9]')" )
! or diehtml("Cannot do: " . $dbh->errstr());
$dbh->disconnect();
------------------------------
Date: 31 Aug 2001 07:16:05 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: arrays question
Message-Id: <m3heuov30a.fsf@dhcp9-161.support.tivoli.com>
On Fri, 31 Aug 2001, goldbb2@earthlink.net wrote:
> Tad McClellan wrote:
>>
>> Calin Guga <CalinG@cfgroup.ca> wrote:
>> >
>> > How could I place 2(for ex. @numbers and @dates) or more
>> > arrays
>> > together in a file, array 1 items would go on first row, array 2
>> > items would go on second, etc. separated by comma, consecutively?
>>
>> { local $" = ',';
>> die "Barf! Commas in the data fields!\n"
>> if grep /,/, @numbers, @dates;
>> print FILE "@numbers\n";
>> print FILE "@dates\n";
>> }
>
> Unless perl has a magical optomization I don't know of, this first
> stringifies and joins, then prints. ISTM it would be better to have
> print itself do the stringifying and inserting of commas.
>
>
> { die "Barf! Commas in the data fields!\n"
> if grep /,/, @numbers, @dates;
> my $sel = select(FILE);
> local $, = ',';
> print @numbers; print "\n";
> print @dates ; print "\n";
> select($sel);
> }
I believe this would qualify as a micro-optimization. It's not even
clear that it really is faster once you factor in the select and the
separate calls to print for the newlines.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Fri, 31 Aug 2001 09:24:04 -0400
From: Samneric <samneric@tigerriverOMIT-THIS.com>
Subject: Re: Environment variables and AOL
Message-Id: <MPG.15f959bf3ba1e4429896a9@news.onemain.com>
G.A.D.Miles wrote:
> My script needs to know the URL of the web page from which it was
> invoked.
You need to redesign it. You can't count on a value fake-able by users to
guarantee anything.
> Using any of the main browsers it can get this information from:
> $ENV{HTTP_REFERER}
That environment variable isn't always returned by many browsers - not just the
ones crapped-onto AOL.
See:
http://groups.google.com/groups?q=environment+http_referer
------------------------------
Date: Fri, 31 Aug 2001 08:00:31 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Environment variables and AOL
Message-Id: <3b8fa697$1@news.microsoft.com>
"G.A.D.Miles" <usad1@gadnet.com> wrote in message
news:3b8f6225.174455117@news.newsguy.com...
> Using any of the main browsers it can get this information from:
> $ENV{HTTP_REFERER}
>
> But, in AOL only, if the user invokes the script in a new window (ie
> right clicks on the link to the script and selects the new window
> option) the above variable is blank. Doing the same thing in IE or
> Netscape works fine.
Then obviously you don't have a Perl problem.
> a) where can I get the information from, if not from
> $ENV{HTTP_REFERER}
Try asking in a newsgroup that deals with CGI.
> b) Is this a bug in AOL or are they welcome to populate environment
> variables with anything they feel like?
How should Perl people know? Try asking in a newsgroup that deals with CGI
or AOL.
What was your Perl question?
jue
------------------------------
Date: Fri, 31 Aug 2001 10:52:53 -0400
From: "Bob Lockie" <bjlockie@nortelnetworks.com>
Subject: Re: file search
Message-Id: <9mo8c5$dk0$1@bcarh8ab.ca.nortel.com>
Thanks guys.
------------------------------
Date: Fri, 31 Aug 2001 14:22:56 +0100
From: Andrew Paul Gorton <gortona@cs.man.ac.uk>
Subject: Finding differences in two text strings
Message-Id: <3B8F8FB0.355566FD@cs.man.ac.uk>
Hi all,
I have two arrays with the values changing at different places in my
script. I need to compare the two arrays and save the difference
between them.
So I have a @stored and a @current array, which can be of any length and
contain any text.
I first calculate the length of the arrays and if they are different
then I need to find how they are different. I persume this requires
converting the arrays to a text string and comparing them. So:
if($current_length < $stored_length){
$current = "@current"; #text string
$stored = "@stored"; #text string
#But then how would I compare the two strings and get the difference
}
Cheers for any help
------------------------------
Date: Fri, 31 Aug 2001 09:48:02 -0400
From: Kevin Michael Vail <kevin@vaildc.net>
Subject: Re: Finding differences in two text strings
Message-Id: <310820010948025102%kevin@vaildc.net>
In article <3B8F8FB0.355566FD@cs.man.ac.uk>, Andrew Paul Gorton
<gortona@cs.man.ac.uk> wrote:
> Hi all,
>
> I have two arrays with the values changing at different places in my
> script. I need to compare the two arrays and save the difference
> between them.
>
> So I have a @stored and a @current array, which can be of any length and
> contain any text.
You want Algorithm::Diff, available on CPAN. It's made to handle just
this situation.
[snip]
--
Kevin Michael Vail | a billion stars go spinning through the night,
kevin@vaildc.net | blazing high above your head.
. . . . . . . . . | But _in_ you is the presence that
. . . . . . . . . | will be, when all the stars are dead. (Rainer Maria Rilke)
------------------------------
Date: 31 Aug 2001 08:46:38 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Finding differences in two text strings
Message-Id: <m3y9o0tk8x.fsf@dhcp9-161.support.tivoli.com>
On Fri, 31 Aug 2001, gortona@cs.man.ac.uk wrote:
> Hi all,
>
> I have two arrays with the values changing at different places in my
> script. I need to compare the two arrays and save the difference
> between them.
>
> So I have a @stored and a @current array, which can be of any length
> and contain any text.
>
> I first calculate the length of the arrays and if they are different
> then I need to find how they are different. I persume this requires
> converting the arrays to a text string and comparing them. So:
>
> if($current_length < $stored_length){
if (@current != @stored) {
> $current = "@current"; #text string
> $stored = "@stored"; #text string
>
> #But then how would I compare the two strings and get the difference
Well, it depends on what you mean by "difference". Various CPAN
modules may help there.
> }
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Fri, 31 Aug 2001 09:07:19 -0500
From: uNcONvEntiOnaL <tomcat@visi.com>
Subject: Re: help understanding this snippet
Message-Id: <3B8F9A17.67B84683@visi.com>
This is the code, it's not pseudo code, it's 5+ years old and I don't
recognize what this portion does exactly. Thank you for your
responses. The first thing I did was dig out some perl books, but
the combination of syntax makes it hard (for me) to understand what's
going on. pop(@nbrs) i think is taking numbers off a stack, int
must be casting them to integer? Could I cast them to decimal?
I don't get the =~ m.(1,12)"sg this is regex isn't it?
where are the slashes - is this "old" perl syntax?
Thanks for your patience.
Tom
------------------------------
Date: 31 Aug 2001 07:27:08 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: help understanding this snippet
Message-Id: <m37kvkv2hv.fsf@dhcp9-161.support.tivoli.com>
On Fri, 31 Aug 2001, davidhilseenews@yahoo.com wrote:
>
> "Tad McClellan" <tadmc@augustmail.com> wrote in message
> news:slrn9otip3.192.tadmc@tadmc26.august.net...
>> uNcONvEntiOnaL <tomcat@visi.com> wrote:
>> >
>> >$oldline = substr($line,86,721);
>> >@nbrs = reverse(($oldline =~ m".(1,12)"sg));
>> >for (x$=0;$x < 24; $x++) {
>>
>>
>> There is a syntax error in the previous line.
>>
>>
>> This would seem more clear to me:
>>
>> foreach my $x ( 0..24 ) {
>>
>>
>
> You mean
>
> foreach my $x ( 0..23 ) {
Which seems to exemplify Tad's point... :)
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 31 Aug 2001 14:18:39 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: help understanding this snippet
Message-Id: <9mo6bv$5ii$2@mamenchi.zrz.TU-Berlin.DE>
According to uNcONvEntiOnaL <tomcat@visi.com>:
>
>
> This is the code, it's not pseudo code, it's 5+ years old and I don't
> recognize what this portion does exactly.
That's a bad case of bit rot then :)
Seriously, the code you posted can never have run. It looks like
you typed it in instead of cutting and pasting it from the source,
and you didn't type very carefully at that.
[...]
> I don't get the =~ m.(1,12)"sg this is regex isn't it?
Here you did it again. This expression makes no sense as Perl code.
One could surmise you forgot a " and meant to type
=~ m".(1,12)"sg
But, frankly, I feel disinclined to explain code you couldn't be
bothered to type in correctly.
Anno
------------------------------
Date: Sat, 1 Sep 2001 00:24:09 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: help understanding this snippet
Message-Id: <slrn9ov7g9.3ga.mgjv@martien.heliotrope.home>
On Fri, 31 Aug 2001 09:07:19 -0500,
uNcONvEntiOnaL <tomcat@visi.com> wrote:
>
> I don't get the =~ m.(1,12)"sg this is regex isn't it?
That wasn't in your original post, which you don't even quote. Please,
read up on Usenet etiquette, so that you know for the next time how to
keep a thread going.
Your original post said:
m".(1,12)"sg
Which is a very odd regular expression anyway. It matches any character
9including a newline), followed by the string "1,12", as often as this
appears in the string, and returns all the matched "1,12" strings.
Are you sure the original code didn't say
m".{1,12}"sg
? Did you copy the code into your post, or did you retype it, and made a
mistake? if so, I hope that next time you post code, you will remember
to copy it in. Never retype. it introduces unnecessary bugs.
> where are the slashes - is this "old" perl syntax?
The perlop documentation explains exactly how m// and s/// work. The
first character after the m becomes the delimiter, or you can use (),
[], or {}.
See the section 'Quote and Quote-like Operators'.
The perlre documentation explains about regular expressions. The Perl
FAQ, section 6 has many frequently asked questions about regular
expressions. You probably want to read this documentation.
To read the documentation, use man (Unix), perldoc (Unix, Win32, OS/2?,
VMS?), Shuck (Mac) or a webbie browser clickie linkie thing
(ActiveState).
Martien
--
Martien Verbruggen |
Interactive Media Division | In a world without fences, who needs
Commercial Dynamics Pty. Ltd. | Gates?
NSW, Australia |
------------------------------
Date: Sat, 1 Sep 2001 00:28:02 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: help understanding this snippet
Message-Id: <slrn9ov7ni.3ga.mgjv@martien.heliotrope.home>
On Thu, 30 Aug 2001 19:24:19 -0400,
Tad McClellan <tadmc@augustmail.com> wrote:
> uNcONvEntiOnaL <tomcat@visi.com> wrote:
>>
>>$oldline = substr($line,86,721);
>>@nbrs = reverse(($oldline =~ m".(1,12)"sg));
>>I think this used to read in whole numbers,
>
> It _would_ "read in" strings that are 1 to 12 characters long. The
Check the brackets in the regex again. Unless $oldstring contains
"1,12", not much will end up in @nbrs.
> Please do not post pseudo code. Post Perl code.
Indeed.
Martien
--
Martien Verbruggen |
Interactive Media Division | Little girls, like butterflies, need
Commercial Dynamics Pty. Ltd. | no excuse - Lazarus Long
NSW, Australia |
------------------------------
Date: 31 Aug 2001 07:22:22 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: help with pipes please
Message-Id: <m3bskwv2pt.fsf@dhcp9-161.support.tivoli.com>
On Thu, 30 Aug 2001, khanrahan@cypresscom.net wrote:
> I am trying to read log data, one line at a time as it comes in, and
> then act upon it. If I use :
>
> $alertmsg = <STDIN>;
> ......remainder of script....
>
> and feed it manually it works great but I want it to be fed
> automatically so instaed of using <STDIN> I tried:
>
> $alertmsg = open(ALERT, "tail -f /opt/apps/logs/alarm.log|") or die
> "Can't fork";
You might consider using the approach discussed in the FAQ:
perldoc -q tail
How do I do a "tail -f" in perl?
> while(<ALERT>)
> {
> .....remainder of script........
>
> and it dies when it gets new data! ....I am trying to take the
> result of tail -f /opt/apps/logs/alarm.log and use it as input for
> the script..
I tried this and had no trouble. How, exactly is it dying?
> What have I done wrong? This is my first attempt at a script....I
> am trying to understand the use of pipes
We're going to need to see more of what your doing to figure out what
you're doing wrong. What you've shown works for me.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Fri, 31 Aug 2001 15:58:14 +0200
From: Philippe PERRIN <philippe.perrin@sxb.bsf.alcatel.fr>
Subject: Re: most effective way to search for different words in a text
Message-Id: <3B8F97F6.EB070CFD@sxb.bsf.alcatel.fr>
Philippe PERRIN wrote:
> # $text is the entry
> my @words = ("WORD1", "WORD2", "WORD3");
> foreach my $word (@words) {
> if($text =~ /\Q$word\E/i && # i for non-case-sensitive
> $text =~ /MUST/i) { # i for non-case-sensitive
> print "I found $word and MUST !\n";
> ...
> }
> }
My answer was an example for *any* word instead of "WORD1,2,3".
Or maybe you really meant the words "WORD1", "WORD2" and "WORD3" ? In
that simple case, see Liviu's shorter solution with "WORD[123]" !
--
PhP
($r1,$r2,$r3,$r4)=("19|20","0|1","28|29","5|24");($r5,$r6)=("9|10|15|16|$r1|$r2","9|10|$r3");%h=("1|",$r6,"1=","[1-5]|2[0-4]","1/","0|19","1\\","6|25","2|","0|6|19|25|$r6","2/","1|20","2\\",$r4,"3|","$r2|6|$r1|25|$r6","3/",$r4,"4|","$r2|$r1|$r6","4=","2|3|4|11|12|13|14|21|22|23","4/",$r4,"4\\",15,"5|","$r2|9|15|$r1|20|$r3","5/",10,"6|",$r5,"7|",$r5,"7/",$r3);for($l=1;$l<8;$l++){b:for($i=0;$i<30;$i++){c:foreach(keys
%h){next c if(!(/^$l(.*)$/));$a=$1;if($i=~/^($h{$_})$/){print $a;next
b;}}print " ";}print "\n";}
------------------------------
Date: 31 Aug 2001 07:38:57 -0700
From: xenite9@my-dejanews.com (Adam)
Subject: Re: Network topology mapping
Message-Id: <b67a511f.0108310638.55788371@posting.google.com>
billy@arnis-bsl.com (Ilja Tabachniks) wrote in message news:<5d4a715a.0108300710.4da3df22@posting.google.com>...
> xenite9@my-dejanews.com (Adam) wrote in message news:<b67a511f.0108292137.63f7bac0@posting.google.com>...
> > Hello,
> >
> > How do I take the output of traceroute each time it is run, compare it
> > to a previous (array?) route, remove duplicates, and store new values
> > in an array?
> >
>
> BTW, you may wish to take a look at Net::Traceroute module
> (available from CPAN).
>
> Good luck,
>
> Ilja.
I tried installing Net::Traceroute and have been having some trouble
installing it. I'll try it out again soon. Thanks.
-AC
------------------------------
Date: 31 Aug 2001 09:29:18 -0400
From: stanb@panix.com (Stan Brown)
Subject: Re: Passing arbitray data between ro co-operating per scripts via a pipe
Message-Id: <9mo3fe$rf5$1@panix1.panix.com>
In <9mnveq$rmo$1@mamenchi.zrz.TU-Berlin.DE> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
>According to Stan Brown <stanb@panix.com>:
>> I have an application where I need to pass arbitray data (happens to be
>> rows retrieved from a db table) between two co-operating perl scripts via a
>> pipe. The data will be retrived as collumns and rows using DBI, and I want
>> to put it back together as collumn/row data sets on the recieving end. Data
>> may be arbitray text strings, mixed with numbers, and dates.
>>
>> Is there a standard way of doing this inperl?
>Look at Data::Dumper and the other serializing modules.
I have been looking around a bit. Does Storable sound like a good way to do
this?
Other sugestions wlecome.
------------------------------
Date: 31 Aug 2001 13:54:52 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Passing arbitray data between ro co-operating per scripts via a pipe
Message-Id: <9mo4vc$5ii$1@mamenchi.zrz.TU-Berlin.DE>
According to Stan Brown <stanb@panix.com>:
> In <9mnveq$rmo$1@mamenchi.zrz.TU-Berlin.DE>
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
>
> >According to Stan Brown <stanb@panix.com>:
> >> I have an application where I need to pass arbitray data (happens to be
> >> rows retrieved from a db table) between two co-operating perl scripts via a
> >> pipe. The data will be retrived as collumns and rows using DBI, and I want
> >> to put it back together as collumn/row data sets on the recieving end. Data
> >> may be arbitray text strings, mixed with numbers, and dates.
> >>
> >> Is there a standard way of doing this inperl?
>
> >Look at Data::Dumper and the other serializing modules.
> I have been looking around a bit. Does Storable sound like a good way to do
> this?
As good as any. You are not giving any criteria to prefer one over
another.
Anno
------------------------------
Date: Fri, 31 Aug 2001 15:10:27 +0200
From: Crazydj <Crazydj@web.de>
Subject: Re: Programming sockets
Message-Id: <3B8F8CC3.D8462CC6@web.de>
Villy Kruse schrieb:
> On Fri, 31 Aug 2001 11:41:38 +0200,
> Crazydj <Crazydj@web.de> wrote:
>
> >Hi @ll!!! =)
> >I have got a question on how to program sending sockets.
> >To send an email through an SMTP server I would it do this way:
> >
> >use IO::Socket;
> >$socket = new IO::Socket::INET(PeerAddr => 'test.server.net',
> > PeerPort =>
> >'25',
> > Proto =>
> >'tcp') || die "Cannot create socket: $!";
> >
> >print $socket "HELO mailserver.net";
> >print $socket "MAIL FROM: perllover@crazydj.de";
> >print $socket "RCPT TO: nice@tester.net";
> >print $socket "DATA";
> >print $socket "bla test and so on";
> >print $socket ".";
> >print $socket "QUIT";
> >close($socket);
> >
> >This program can be run without any problems, but I will never receive
> >this email! Is this a fault of my perlscript or maybe a fault of my
> >mailserver?
> >Where can I get a detailed Tutorial about Socket Programming with Perl?
> >Thanx and best greets
> >
>
> You realy need to make your program listen to what the smtp
> server has to say. Then you might find out what is wrong.
>
> Villy
I am not that good in programming sockets. I can create a listening socket,
but how does the SMTP server know to which socket he should talk?
Can you please explain me how I could program this?
Thanx
--
Djz rule the world! ...and some other staff ;-p Find out at http://www.crazydj.de
------------------------------
Date: 31 Aug 2001 13:50:32 GMT
From: TGVCDPVNTLMI@spammotel.com (Ronald Blaschke)
Subject: Re: Programming sockets
Message-Id: <9mo4n8$37itu$1@ID-57488.news.dfncis.de>
On Fri, 31 Aug 2001 15:10:27 +0200, Crazydj <Crazydj@web.de> wrote:
> Villy Kruse schrieb:
>
> > On Fri, 31 Aug 2001 11:41:38 +0200,
> > Crazydj <Crazydj@web.de> wrote:
> >
> > >Hi @ll!!! =)
> > >I have got a question on how to program sending sockets.
> > >To send an email through an SMTP server I would it do this way:
> > >
[ SMTP snippet removed ]
> > >
> > >This program can be run without any problems, but I will never receive
> > >this email! Is this a fault of my perlscript or maybe a fault of my
> > >mailserver?
> > >Where can I get a detailed Tutorial about Socket Programming with Perl?
> > >Thanx and best greets
> > >
> >
> > You realy need to make your program listen to what the smtp
> > server has to say. Then you might find out what is wrong.
>
> I am not that good in programming sockets. I can create a listening socket,
> but how does the SMTP server know to which socket he should talk?
> Can you please explain me how I could program this?
> Thanx
A good metaphor when thinking about TCP is a telephone line. So, when
you call someone and he picks up the line, how does he know how to
talk to you? :-)
I'd recommend using Net::SMTP to send an email, especially if you are
not too TCP and SMTP wary.
If you absolutely have to do it yourself, here are some hints:
- Remember the telephone line metaphor
- perldoc IO::Handle for read/write methods
[your $socket can also be used like a filehandle, e.g.
print $socket "...", $line = <$socket>, etc.]
- read the RFC 821 (SMTP) http://www.rfc-editor.org/rfc/rfc821.txt
and follow the protocol!
- use "telnet your.hostname 25" to play around with your SMTP Server
- Remeber that the line separator is "\r\n"
Don't know where to find a good tutorial. I can recommend a book
or two, though.
Hope this helps a litte,
Ron
--
------------------------------
Date: Fri, 31 Aug 2001 16:33:07 +0200
From: Crazydj <Crazydj@web.de>
Subject: Re: Programming sockets
Message-Id: <3B8FA023.9E74DD68@web.de>
Ronald Blaschke schrieb:
> A good metaphor when thinking about TCP is a telephone line. So, when
> you call someone and he picks up the line, how does he know how to
> talk to you? :-)
>
> I'd recommend using Net::SMTP to send an email, especially if you are
> not too TCP and SMTP wary.
>
> If you absolutely have to do it yourself, here are some hints:
> - Remember the telephone line metaphor
> - perldoc IO::Handle for read/write methods
> [your $socket can also be used like a filehandle, e.g.
> print $socket "...", $line = <$socket>, etc.]
> - read the RFC 821 (SMTP) http://www.rfc-editor.org/rfc/rfc821.txt
> and follow the protocol!
> - use "telnet your.hostname 25" to play around with your SMTP Server
> - Remeber that the line separator is "\r\n"
>
> Don't know where to find a good tutorial. I can recommend a book
> or two, though.
>
> Hope this helps a litte,
> Ron
> --
O.K I have got it, just read from the created socket ;-p
But I have still the problem that the SMTP server doesn't get my DATA command...
Here is my newest version of that script:
#!/usr/bin/perl
use IO::Socket;
$socket = new IO::Socket::INET(PeerAddr => 'localhost',
PeerPort => '25',
Proto => 'tcp') || die "Cannot create socket!";
print "Connected.\n";
print $socket "HELO mailserver.net\r\n";
$echo = <$socket>;
print "$echo\n";
print $socket "MAIL FROM: perllover\@crazydj.de\r\n";
$echo = <$socket>;
print "$echo\n";
print $socket "RCPT TO: dj\@localhost\r\n";
$echo = <$socket>;
print "$echo\n";
print $socket "DATA\r\n";
print $socket "bla test and so on\r\n";
print $socket ".\r\n";
$echo = <$socket>;
print "$echo\n";
print $socket "QUIT\r\n";
$echo = <$socket>;
print "$echo\n";
close($socket);
--
Djz rule the world! ...and some other staff ;-p Find out at http://www.crazydj.de
------------------------------
Date: 31 Aug 2001 14:48:41 GMT
From: TGVCDPVNTLMI@spammotel.com (Ronald Blaschke)
Subject: Re: Programming sockets
Message-Id: <9mo848$3bc8s$1@ID-57488.news.dfncis.de>
On Fri, 31 Aug 2001 16:33:07 +0200, Crazydj <Crazydj@web.de> wrote:
> Ronald Blaschke schrieb:
>
> > A good metaphor when thinking about TCP is a telephone line. So, when
> > you call someone and he picks up the line, how does he know how to
> > talk to you? :-)
> >
> > I'd recommend using Net::SMTP to send an email, especially if you are
> > not too TCP and SMTP wary.
> >
> > If you absolutely have to do it yourself, here are some hints:
[ hints removed ]
> >
> > Don't know where to find a good tutorial. I can recommend a book
> > or two, though.
> >
> O.K I have got it, just read from the created socket ;-p
> But I have still the problem that the SMTP server doesn't get my DATA command...
>
> Here is my newest version of that script:
>
[ script removed ]
Just ran your script and it worked fine for me. Output follows.
----------
Connected.
220 localhost ESMTP Exim 3.12 #1 Fri, 31 Aug 2001 16:43:38 +0200
250 localhost Hello rb at localhost [127.0.0.1]
250 <perllover@crazydj.de> is syntactically correct
250 <rb@localhost> is syntactically correct
354 Enter message, ending with "." on a line by itself
---------
Could you give me more details regarding your problem? Error msg, etc.
--
------------------------------
Date: Fri, 31 Aug 2001 10:29:04 -0400
From: David Coppit <newspost@coppit.org>
Subject: Q: File globbing and scalar vars
Message-Id: <3B8F9F30.7010307@coppit.org>
perl -e '$a = "*";print <$a>'
fails
perl -e "$a = "*";print <$a\0>'
succeeds
Why?
David
------------------------------
Date: 31 Aug 2001 14:54:53 GMT
From: TGVCDPVNTLMI@spammotel.com (Ronald Blaschke)
Subject: Re: Q: File globbing and scalar vars
Message-Id: <9mo8fs$3bc8s$2@ID-57488.news.dfncis.de>
On Fri, 31 Aug 2001 10:29:04 -0400, David Coppit <newspost@coppit.org> wrote:
> perl -e '$a = "*";print <$a>'
>
> fails
>
> perl -e "$a = "*";print <$a\0>'
>
> succeeds
>
> Why?
perl -w -e '$a = "*";print <$a>'
readline() on unopened filehandle * at -e line 1.
Makes sense to you?
--
------------------------------
Date: 31 Aug 2001 14:52:58 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Q: File globbing and scalar vars
Message-Id: <slrn9ov9h3.qi9.rgarciasuarez@rafael.kazibao.net>
David Coppit wrote in comp.lang.perl.misc:
} perl -e '$a = "*";print <$a>'
}
} fails
}
} perl -e "$a = "*";print <$a\0>'
}
} succeeds
}
} Why?
Use -w, it will give you a clue :
$ perl -wle '$a = "*";print <$a>'
readline() on unopened filehandle * at -e line 1.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: 31 Aug 2001 07:08:07 -0700
From: greenseaweed@aol.com (Mr. Green)
Subject: Re: registration worries
Message-Id: <5370f8aa.0108310608.e48069d@posting.google.com>
Very helpful. Thanks. But I wonder if it would be more efficient to
ditch the random method and simply count the total number of files in
the directory and then let the file name be the total number plus one.
--------------------------------------------------------------------
$Dir = "/local/etc/httpd/htdocs/requests/reservations/entries";
opendir(DIR, $Dir) || die "Cannot read directory $Dir: $!\n";
foreach $_ (grep(!/^\./, readdir(DIR))) { # Skip dot files
push @files, $_;
} closedir(DIR);
$filename = (scalar @files) + 1;
--------------------------------------------------------------------
This would reduce my code to 6 lines. :)
mjd@plover.com (Mark Jason Dominus) wrote in message news:<3b8ed8a7.11f9$2e8@news.op.net>...
> In article <5370f8aa.0108301506.a953820@posting.google.com>,
> Mr. Green <greenseaweed@aol.com> wrote:
> >sub random_name {
> >
> > srand(time() ^ ($$ + ($$ << 15)) );
>
> srand() should be called at most once per program execution. It is
> incorrect to call it each time random_name() is invoked.
>
> > $rand1 = int(rand(9999));
> > while ($rand1 < 1000) {
> > $rand1 = int(rand(9999));
> > }
>
> Here you want to use the 'do-while' construction:
>
> do {
> $rand1 = int(rand(9999));
> } while ($rand1 < 1000);
>
> This does the assignment before the test. But it's simpler yet to
> just get the generation right on the first try. You want to generate
> a random number between 1000 and 9999. So do:
>
> $rand1 = int(1000 + rand(9000));
>
> (Notice also that your original code has an off-by-one error; it only
> generates numbers up to 9998, not 9999.)
>
>
> ># See if the random name/number already exists in the directory.
> ># If so, call the subroutine again.
> >
> > $results = grep(/$rand1/,@allfiles);
>
> Here you're using a pattern match to see if $rand1 appears in
> @allfiles. At best, this is inefficient. At worst, it's incorrect,
> because if you one day decide to allow numbers of different lengths,
> you'll find that /1234/ matches "71234" when you don't want it to.
> Better code is:
>
> $results = grep($rand1 eq $_ , @allfiles);
>
> This tests to see if $rand1 is identical to any item of @allfiles.
>
> The $results variable is useless, because you use it only once,
> immediately after setting it, and never again. (Such variables
> sometimes have value as documentation, but the name 'results' doesn't
> accomplish that either.) Instead, just use:
>
> if (grep($rand1 eq $_ , @allfiles)) {
> ...
>
> This gets rid of $results.
>
> With these changes, the code looks like this:
>
> sub random_name {
> $rand1 = int(1000 + rand(9000));
> if (grep($rand1 eq $_ , @allfiles)) {
> random_name();
> } else {
> return $rand1;
> }
> }
>
> We should declare $rand1 with 'my', so that it won't conflict with any
> other use of '$rand1' that happens to appear elsewhere in the program:
>
> my $rand1 = int(1000 + rand(9000));
>
> The 'grep' is going to be slow if @allfiles is large. When you want
> to know if a certain item is present in an array, that's usually a
> good sign that the array should have been a hash.
>
> We could use a hash here, but there's an even better option: What
> you're really trying to find out is if the file already exists. Perl
> has a built-in way of asking if a file already exists, written '-e'.
> ('e' for 'exists'.)
>
> Using '-e', the 'grep' test simply becomes:
>
> if (-e "$Path/$rand1") {
> random_name();
> } else {
> return $rand1;
> }
>
> Now you can get rid of @allfiles completely, and you can also get rid
> of the opendir-readdir-closedir code.
>
> random_name() contains a recursive call to itself, which is simple,
> but in this case what you're really trying to accomplish is simply to
> repeat the selection of $rand1 until you find an unused value. This
> can be accomplished with a simple loop:
>
> sub random_name {
> my $rand1;
> do {
> $rand1 = int(1000 + rand(9000));
> } while ( -e "$Path/$rand1" );
> return $rand1;
> }
>
>
> The final, complete version is:
>
> $Path = '/local/etc/httpd/htdocs/blah/registration';
> srand(time() ^ ($$ + ($$ << 15)) );
>
> # Generate random file name (which will be a random number.)
> $filename = random_name();
>
> sub random_name {
> my $rand1;
> do {
> $rand1 = int(1000 + rand(9000));
> } while ( -e "$Path/$rand1" );
> return $rand1;
> }
>
>
> This is 8 lines long, and the original version was 14, so we've
> eliminated about half the code while improving performance and
> reliability.
>
> You may also enjoy these articles, which are similar to this one:
>
> http://www.perl.com/pub/2000/04/raceinfo.html
> http://www.perl.com/pub/2000/06/commify.html
> http://www.perl.com/pub/2000/11/repair3.html
> http://www.oreillynet.com/pub/a/network/2001/05/18/perl_redflags.html
>
> Hope this helps.
------------------------------
Date: Sat, 1 Sep 2001 00:47:39 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: registration worries
Message-Id: <slrn9ov8sb.3ga.mgjv@martien.heliotrope.home>
[Please, in the future, put your reply _after_ the suitably trimmed text
you reply to. It's the commonly accepted quoting method on this
newsgroup, and Usenet in general]
On 31 Aug 2001 07:08:07 -0700,
Mr. Green <greenseaweed@aol.com> wrote:
[reorganised, wrapped]
> mjd@plover.com (Mark Jason Dominus) wrote in message
> news:<3b8ed8a7.11f9$2e8@news.op.net>...
>> In article <5370f8aa.0108301506.a953820@posting.google.com>,
>> Mr. Green <greenseaweed@aol.com> wrote:
>> >sub random_name {
>> >
>> > srand(time() ^ ($$ + ($$ << 15)) );
>>
>> srand() should be called at most once per program execution. It is
>> incorrect to call it each time random_name() is invoked.
[snip lengthy discussion on generation of random file name]
> Very helpful. Thanks. But I wonder if it would be more efficient to
> ditch the random method and simply count the total number of files in
> the directory and then let the file name be the total number plus one.
Maybe, but then, why did you ask for a random name in the first place?
Your code calculated a random name, and that idea got improved upon. If
you don't need a random name, then anything else will do, *as long* as
it generates a unique file name. The method you describe above doesn't
necessarily do that.
> $Dir = "/local/etc/httpd/htdocs/requests/reservations/entries";
>
> opendir(DIR, $Dir) || die "Cannot read directory $Dir: $!\n";
> foreach $_ (grep(!/^\./, readdir(DIR))) { # Skip dot files
> push @files, $_;
> } closedir(DIR);
A faster way to do that is:
@files = grep !/^\./, readdir(DIR);
Are you going to use that list of files somewhere else? Or do you just
need it for the number?
> $filename = (scalar @files) + 1;
(the scalar isn't needed here) And what if that filename already exists?
Scenario: Your program generates 20 files, "1" to "20". You delete file
"11". What file name will your program enerate the next time around?
Right.
> This would reduce my code to 6 lines. :)
And potentially overwrite another file.
You could only look at files with "numerical" file names, take the
largest, and add 1. Something like (untested):
$filename = (sort { $a <=> $b } grep !/\D/, readdir DIR)[-1] + 1;
If you have many files, you might want to avoid the sort, and determine
the maximum from a loop.
However, this looping and/or sorting is going to be expensive for larger
lists of files. The following may be the cheapest:
$filename = @files + 1;
$filename++ while -e "$Dir/$filename";
But in (extremely) pathological cases this could become a bit expensive
as well.
Martien
--
Martien Verbruggen |
Interactive Media Division | Useful Statistic: 75% of the people
Commercial Dynamics Pty. Ltd. | make up 3/4 of the population.
NSW, Australia |
------------------------------
Date: Fri, 31 Aug 2001 14:24:29 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: unable to install AdminMisc Module
Message-Id: <s47votk3k434k72qqnjlt7c4b6m368i6lc@4ax.com>
Klaus Peter Weirich wrote:
>I'm an absolute Beginner an forced to use the win32::adminmisc module. I've
>installed ActiveState WIN32 Perl Version 509 and downloaded the module from CPAN
>(I think Version 971022). I've followed the instructions from readme-file:
> 3) Rename AdminMisc310.pll to AdminMisc.pll and copy it to...
You're still using 5xx? Be sure that your stuff is compatible wit hthat
version of perl. Since you're using a DLL (here called a "pll"), that is
very important.
You'd better see if there's no version of this module available from
Activestate's own repository: <http://www.activestate.com/PPMpackages/>
and make sure you get one for your binary (you've got 5.005, that's what
the 5xx stands for). Yup, there it is:
<http://www.activestate.com/PPMpackages/5.005/Win32-AdminMisc.ppd>
<http://www.activestate.com/PPMpackages/5.005/x86/Win32-AdminMisc.tar.gz>
Download both files, put them into the same relative position, i.e. the
.tag.gz file in a subdirectory called "x86", and use PPM to install it
from the directory with the PPD file from the DOS prompt as:
ppm install Win32-AdminMisc
There. That should do it.
--
Bart.
------------------------------
Date: Fri, 31 Aug 2001 18:38:03 +0530
From: Prakash Mishra <pmishra@mailcity.com>
Subject: Re: Which language better
Message-Id: <3B8F8C33.2D8D88B4@mailcity.com>
I am working on developing a tool which would be used for functionality testing
of DSL devices. Mostly it will be used for testing the SNMP agent part of the
device. Now here the speed of the application, memory usage etc does matter.
Platform is Solaris. So I wanted information in these regards.
Cameron Laird wrote:
>
> In article <3B8F7BA0.6BEAF6B4@mailcity.com>,
> Prakash Mishra <pmishra@mailcity.com> wrote:
> >For developing a testing tool, which language is better to use...Perl or Tcl ?
>
> The one that better fulfills all your other
> requirements--the ones you haven't yet told
> us.
>
> People successfully use both Perl and Tcl in
> this role. In fact, *I* use both, for test-
> ing (among other purposes). I prefer Tcl,
> for reasons whose pertinence to your situation
> is impossible to know in the absence of more
> information.
> --
>
> Cameron Laird <claird@NeoSoft.com>
> Business: http://www.Phaseit.net
> Personal: http://starbase.neosoft.com/~claird/home.html
------------------------------
Date: 31 Aug 2001 08:41:36 -0500
From: claird@starbase.neosoft.com (Cameron Laird)
Subject: Re: Which language better
Message-Id: <B3C2C9436ACCA637.10263E25F2C695BC.30D3972BDC2EDF93@lp.airnews.net>
In article <3B8F8C33.2D8D88B4@mailcity.com>,
Prakash Mishra <pmishra@mailcity.com> wrote:
>I am working on developing a tool which would be used for functionality testing
>of DSL devices. Mostly it will be used for testing the SNMP agent part of the
>device. Now here the speed of the application, memory usage etc does matter.
>Platform is Solaris. So I wanted information in these regards.
.
.
.
Ah!
I strongly prefer Scotty, the Tcl-based SNMP-savvy shell.
It's far more mature and capable than anything Perl offers.
However, if you're far more comfortable with Perl than Tcl,
and don't need all of Scotty's power, than Perl might be
better for you.
--
Cameron Laird <claird@NeoSoft.com>
Business: http://www.Phaseit.net
Personal: http://starbase.neosoft.com/~claird/home.html
------------------------------
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 1668
***************************************