[21758] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3962 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 13 09:05:36 2002

Date: Sun, 13 Oct 2002 06:05:08 -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           Sun, 13 Oct 2002     Volume: 10 Number: 3962

Today's topics:
        -d:ptkdb in windows XP <evilflint@hotmail.com>
    Re: complex hash structure -- any ideas? <piranha@602.org>
        Email link to a word Document (GetWebWise)
    Re: Help! How do you move one html page to another in P (Zordiac)
    Re: How to create a bundle? <enrico@sorcinelli.it>
    Re: Multiple Pings/Second <smackdab1@hotmail.com>
    Re: newb here learning Perl <bart.lateur@pandora.be>
    Re: newb here learning Perl <bart.lateur@pandora.be>
    Re: Perl 5.8 test failure <rgarciasuarez@free.fr>
    Re: STDIN and choices on screen? <darin@naboo.to.org.no.spam.for.me>
    Re: Switching from Python to Perl <derek@wedgetail.com>
        use strict (kit)
    Re: use strict (Jay Tilton)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sun, 13 Oct 2002 14:21:19 +1000
From: "Tom" <evilflint@hotmail.com>
Subject: -d:ptkdb in windows XP
Message-Id: <3da8f4c5$0$18874$afc38c87@news.optusnet.com.au>

hey guys,

I have this problem in windows 98/2k when I run a script with
#!perl -d:ptkdb from the web a window with ptkdb actually open up...

but with apache on windows XP for some reason it just won't open.. it says
can not fork child

__________________________________________
Server error!
  The server encountered an internal error and was unable to complete your
request.
  Error message:
  couldn't create child process: 22503: login.pl
  If you think this is a server error, please contact the webmaster
Error 500

  fof
  10/13/02 14:19:57
  Apache/2.0.40 (Win32)
__________________________________________
ummm... it would be alot easier in development if I could get :ptkdb to open
from the web that way I won't have to worry about typing out session details
or param() details over and over again...

Thanks
Tom




------------------------------

Date: Sun, 13 Oct 2002 06:17:27 GMT
From: Jeremy Miller <piranha@602.org>
Subject: Re: complex hash structure -- any ideas?
Message-Id: <Xd8q9.24838$r83.2027526@news1.west.cox.net>

Garry Williams wrote:
> On 12 Oct 2002 17:26:20 -0700, Jeremy Miller <piranha@602.org> wrote:
> 
>>Hello,
>>I've recently taken on a project involving mapping out a network
>>device's
>>physical slots, ports, logical ports and pvcs.. Anyhow, I'm running
>>into a situation where I would like to present the data in a
>>hierarchical way so that it's easy to read and understand, but storing
>>the data in an elegant fashion is posing quite a challenge.  Here's
>>the output I would like to have:
>>
>>SLOT    PPORT   LPORT   PVC     STATE
>>------- ------- ------- ------- -------
>>13 .... ....... ....... ....... up
>>        1 ..... ....... ....... up
>>                19 .... ....... down
>>        2 ..... ....... ....... up
>>                19 .... ....... down
>>                30 .... ....... down
>>                        200 ... inactive
>>14 .... ....... ....... ....... down
>>        2 ..... ....... ....... down
>>                37 .... ....... down
>>                        33 .... inactive
>>                        131147  inactive
>>
>>As you can see, I need to be able to keep track of all "slots", each
>>"pport" on the "slot", each "lport" on each "pport", each "pvc" on
>>each "lport" and finally, the "state" of each item.  I currently have
>>all the above data in various hashes, and can print it individually,
>>but would like to combine them into one, so that I can have one main
>>loop to access and print the data in a nice way =)  Anybody have any
>>ideas/insight??
> 
> 
> Add sorting, if desired: 
> 
>   #!/usr/local/bin/perl
>   use warnings;
>   use strict;
>   use Data::Dumper;
> 
>   my %elements = (
> 	  "192.168.50.173" => {
> 	      13 => {
> 		  STATE => "up",
> 		  1     => {
> 		      STATE => "up",
> 		      19    => {
> 			  STATE  => "down",
> 		      },
> 		  },
> 		  2     => {
> 		      STATE => "up",
> 		      19    => {
> 			  STATE  => "down",
> 		      },
> 		      30    => {
> 			  STATE  => "down",
> 			  200    => "inactive",
> 		      },
> 		  },
> 	      },
> 	      14 => {
> 		  STATE => "down",
> 		  2     => {
> 		      STATE => "down",
> 		      37    => {
> 			  STATE  => "down",
> 			  33     => "inactive",
> 			  131147 => "inactive",
> 		      },
> 		  },
> 	      },
> 	  },
> 	  );
> 
>   while ( my ($elt, $elt_val) = each %elements ) {
>       print "$elt\n\n";
>       print "SLOT    PPORT   LPORT   PVC     STATE\n",
> 	    "------- ------- ------- ------- -------\n";
> 
>       while ( my ($slot, $slot_val) = each %{ $elt_val } ) {
> 	  next if $slot eq "STATE";
> 	  printf "%-7d %s %s %s %s\n", $slot, '.'x7, '.'x7,
> 	      '.'x7, $slot_val->{STATE};
> 
> 	  while ( my ($pport, $pport_val) = each %{ $slot_val } ) {
> 	      next if $pport eq "STATE";
> 	      printf "        %-7d %s %s %s\n", $pport, '.'x7, 
> 		  '.'x7, $pport_val->{STATE};
> 
> 	      while ( my ($lport, $lport_val) = each %{ $pport_val } ) {
> 		  next if $lport eq "STATE";
> 		  printf "                %-7d %s %s %s\n", $lport,
> 		      '.'x7, $lport_val->{STATE};
> 
> 		  while ( my ($pvc, $pvc_val) = each %{ $lport_val } ) {
> 		      next if $pvc eq "STATE";
> 		      printf "                        %-7d %s %s %s\n",
> 			  $pvc, $pvc_val;
> 		  }
> 	      }
> 	  }
>       }
>   }
>
Very, very nice indeed!  Your response is gratefuly appreciated.
Thank you =)
--
-jm



------------------------------

Date: 13 Oct 2002 09:21:29 GMT
From: getwebwise@aol.com (GetWebWise)
Subject: Email link to a word Document
Message-Id: <20021013052129.20288.00000100@mb-fp.aol.com>

Hi there

I am a real perl/html novice....

II am using a form to send an email, in which I would like a link to a word
document or zip file.

Please can someone help me understand how to make this work. 

#     open(REPLY, "|/usr/sbin/sendmail -t");
#     print REPLY "To: $email \n"; # SEND TO ENQUIRER
#     print REPLY "From: $emailsales \n";
#     print REPLY "Subject: Internet Enquiry \n";
#     print REPLY "Dear $fn \n";
#     print REPLY "I have just received your enquiry which is being processed.
\n";
#     print REPLY " \n";

       This is the part I cannot seem to make work??? -----------
#     print REPLY "<HREF="http://www.cleanandeasymoney.co.uk/cgi-
#     bin/infopack/infopack.doc">Click Here to Download Information Pack>
\n\n";

Thank you
Ian



------------------------------

Date: 13 Oct 2002 04:47:59 -0700
From: zordiac@hotmail.com (Zordiac)
Subject: Re: Help! How do you move one html page to another in Perl?
Message-Id: <7744b29b.0210130347.71b44c63@posting.google.com>

Funny I always tell myself to NEVER assume anything
then I find that I have again done just that ie I 
thought the CGI module was an add on and it seems 
it isn't....

I downloaded ActivePerl v5.6.1 just a few months ago
and thought that the CGI module was an add on - I'm
sure I tried to run a CGI script similar to the one Jeff
kindly posted but failed to get it to work and the error
made me conclude an extra CGI module was needed. Maybe
I was wrong here. But that is why I did not use this 
module. I've since used PPM to install the CGI module
and managed to run Jeff's script except of course I
had to remove the -T from the first line. Reason for 
this I have since discovered is due to windows IIS
web server. 

>When a Perl program is run by Windows it is always as 
>if it had been run like: perl program.pl

Suggestion is to :

>create a new association for your cgi-bin directory for 
>files with a .plt extension:
>  .plt   -->  C:\perl\bin\perl.exe -T %s %s

[ from http://nms-cgi.sourceforge.net/faq_prob.html ]

Interestingly if my perl cgi script has a .cgi extension
and I have included the -T then the error I get going to:

http://localhost/cgi-bin/test.cgi

is:

> 'C:\Inetpub\wwwroot\cgi-bin\test.cgi' script produced no output 

and cannot see anything extra in the log files.

But if I use a .pl extension I get 

>The specified CGI application misbehaved by not returning a complete
set of >HTTP headers. The headers it did return are:

> Too late for "-T" option at C:\Inetpub\wwwroot\cgi-bin\test.pl line 1.

And there is an explanation for this in the faq mentioned above.

Thanks again one and all for your help and I will
use the CGI module and -T.

Steve


------------------------------

Date: Sun, 13 Oct 2002 12:45:43 GMT
From: Enrico Sorcinelli <enrico@sorcinelli.it>
Subject: Re: How to create a bundle?
Message-Id: <3DA96C7D.A48219DA@sorcinelli.it>

Domizio Demichelis wrote:

> I found just a little section in the CPAN pod, nothing at all in the faq,

Are you sure?
See
    http://www.cpan.org/misc/cpan-faq.html#How_make_bundle

    - Enrico



------------------------------

Date: Sun, 13 Oct 2002 05:11:59 GMT
From: "smackdab" <smackdab1@hotmail.com>
Subject: Re: Multiple Pings/Second
Message-Id: <zg7q9.142957$S32.10161040@news2.west.cox.net>

Wow what great timing...I was looking @ trying to do this, gave up and then
saw
these posts.  I have used an example of yours for nonblocking port scanning,
which works great (took me a while to understand it though...)
It used IO::Select, which seems easier for us beginners...

I can't get this to run, I currently get
    Error in recv: Unknown error at test.pl line 53.
Here are the lines:
my $resp =  "";
my $responder = recv( $socket, $resp, 8, 0 )
     or die "Error in recv: $!"; # shouldn't happen.
(I changed the my ($resp), as I saw the above in another book, but
it didn't help...).  $socket is valid at this point...

This line was confusing, so I dropped the $t as my book only
said 1 thing came back from this call...
I noticed that IO::Select->select() returns 3 things though...
#(my ($n), $t) = select($rvec, $wvec, '', 0.5);
my $n = select($rvec, $wvec, '', 0.5);

It *seems* to create the socket and call the select, but I never
see it call send().

This line:
if( $wvec =~ tr/^\0// ) {
Is it looking for a NULL in a buffer...don't understand
this whole part, as $wvec is a "@" or a "." ... well beyond me ;-)


Here is the entire thing, taking your latest suggestions about $sentinel

use IO::Socket;
use strict;
use warnings;

my @host_file = qw(192.168.0.1 192.168.0.2);

my $socket = IO::Socket::INET->new(Proto => 'icmp');

my @hosts = map { inet_aton($_) } @host_file;

my %hosts = map {; pack_sockaddr_in(0, $_) => $_ } @hosts;

my @checksums;
vec( my $svec = "", fileno($socket), 1 ) = 1;
my $expire = 30 + time;
my ($lastsent, $sentinel, $wvec) = scalar(each %hosts);

while( (my $seq = $expire - time) >= 0 ) {
  my ($msg) = @{$checksums[$seq] ||= do {
     $sentinel = $hosts{$lastsent} ?
        $lastsent :
        (each %hosts or each %hosts);
     $wvec = $svec;

     # code, subcode, checksum, pid, seq, [data ommited]
     my $msg = pack("C2S3", 8, 0, 0, $$ & 0xFFFF, $seq);
     my $chk = unpack("%32S*", $msg);
     # $chk += ord(substr( $msg, -1 )) if length($msg) % 2;
     $chk = ($chk & 0xFFFF) + ($chk >> 16) for 1..2;
     $chk = 0xFFFF & ~$chk;
     $msg = pack("C2S3", 8, 0, $chk, $$ & 0xFFFF, $seq);
     [ $msg, $chk ];
  }};

  my $rvec = $svec;

#(my ($n), $t) = select($rvec, $wvec, '', 0.5);
#i only know of 1 ret val for select...
my $n = select($rvec, $wvec, '', 0.5);

  die "select failed: $!" if !defined($n) or $n < 0;
  next if $n == 0; # timeout.

  if( $wvec =~ tr/^\0// ) {
     my $ip; $ip ||= each %hosts for 1..2;
send( $socket, $msg, 0, $lastsent = $ip ) or die;
     $wvec = "" if $ip eq $sentinel;
  }

  $rvec =~ tr/^\0// or next;

my $resp = "";
my $responder = recv( $socket, $resp, 4, 0 )
     or die "Error in recv: $!"; # shouldn't happen.

  my ($port, $ip) = unpack_sockaddr_in($responder);
  die "Expected port to be zero" if $port;
  my ($rtype, undef, $rchk, $rpid, $rseq) =
     unpack("C2S3", $resp);
  # make sure this is a valid packet:
  $rtype == 0 and $rpid == ($$ & 0xFFFF)
     and defined $checksums[$rseq]
     and $rchk == $checksums[$rseq][1] or next;

  # remove this host from the %hosts hash, and
  # if wasn't previously there, ignore the packet.
  delete $hosts{$responder} or next;

  # I've just realized that there's a bit of a logic bug in my program
  # here... if the element we've just deleted was $sentinel, the loop-
  # through-%hosts-stopping-code will be confused, and, umm, not stop... So
  # I need to set $sentinel to something else, if that's the case; the next
  # element after where $sentinal was would be ideal, but I don't know how
  # to efficiently find that out, especially not after we've just deleted
  # it.  So instead, set it to $lastsent:
  if( $sentinel eq $responder ) {
    $sentinel = $hosts{$lastsent} ?
      $lastsent :
      (each %hosts or each %hosts);
  }

  # print out the fact that we've discovered
  # that the host is alive.
  print inet_ntoa($ip) . " is alive\n";

  last unless %hosts;
} # end while(1)

print inet_ntoa($_)." is down\n" for values %hosts;






"Benjamin Goldberg" <goldbb2@earthlink.net> wrote in message
news:3DA7A518.547D2F8B@earthlink.net...
> Kevin Vaughn wrote:
> >
> > Somehow I have a feeling like this code would greatly help me out...
> > if I understood it.  I guess I'll have to break out the Perl book and
> > start learning =)
>
> None of the individual parts are horribly complex -- it's just one
> simple thing and another simple thing and another simple thing, which
> put together look like one complicated thing.
>
> > Thank all of you for your responses.  I wasn't expecting much, and I
> > got a lot.  Maybe I can get better at this stuff and repay you one of
> > these days.
> >
> > -Kevin
> >
> > >
> > > Ok, revised code:
>
> And now, with comments:
>
> > >    my $socket = ...;
>
> This should be an icmp socket, probably created with:
>    my $socket = IO::Socket::INET->new(Proto => 'icmp');
>
> > >    my @hosts = ...; # 4 byte ip addresses.
>
> You'll probably create the elements of this list by doing inet_aton on
> strings "1.2.3.4", or gethostbyname on strings like "foo.bar.com".
>
> This 4 byte strings are packed in_addr structs.  (Or you could consider
> them to be packed in_addr_t numbers, but that's silly).
>
> > >    my %hosts = map {; pack_sockaddr_in(0, $_) => $_ } @hosts;
>
> This creates a hash, with keys as sockaddr_in structs, and values as
> in_addr structs.
>
> > >    my @checksums;
>
> For each sequence number, we compute one message and checksum.  Since we
> reuse these, it makes sense to cache them.
>
> > >    vec( my $svec = "", fileno($socket), 1 ) = 1;
>
> Create a variable $svec, set it to "", then use vec() to set a bit
> corresponding to the fileno of the socket... see perldoc -f select to
> understand it's use.
>
> > >    my $expire = 30 + time;
>
> This is a 30 second timeout.
>
> > >    my ($lastsent, $sentinel, $wvec) = scalar(each %hosts);
>
> Create three variables, and assign to $lastsent the first key in the
> %hosts hash.
>
> > >    while( (my $seq = $expire - time) >= 0 ) {
>
> Calculate the sequence number based on the time, and also check that we
> haven't timed out.
>
>
> > >       my ($msg) = @{$checksums[$seq] ||= do {
>
> Each element of $checksums[...] is an arrayref, containing a pair of the
> form: [message, checksum].  We're essentially doing here:
>    my ($msg) = @{ that pair };
> which assigns the message part of the pair to the variable $msg, and
> ignores the checksum part.
>
> The ||= means, if there *isn't* an element in $checksums[$seq] yet (and
> there might not be, since @checksums is initally an empty array),
> evaluate the expression on the right, assign it to the part on the left,
> and use that as the result.
>
> The "do {" means, we have stuff that's not a simple expression, but a
> block, but we want to use that block as if it were a simple expression.
>
> So the last element of the following block is used as the [message,
> checksum] pair to store in $checksums[$seq], and to get the message to
> put into $msg.
>
> > >          $sentinel = $lastsent;
>
> This is a bit hard to understand.  Further on, we repeatedly loop
> through the %hosts hash.  But I don't want to always start in the
> beginning, each time we get a new sequence number -- I want to start
> just after the last item that was sent.  That means that for each new
> sequence number, we need to *stop* when we've sent the last one that was
> sent on the prior sequence number.
>
> > >          $wvec = $svec;
>
> For each sequence number, we only loop through the hosts once -- to mark
> that we've already looped through the list once, we later assign "" to
> $wvec.  This sets it back to the socket bitvector whenever we get a new
> sequence number, indicating to begin/continue looping through hosts.
>
> > >          # code, subcode, checksum, pid, seq, [data ommited]
> > >          my $msg = pack("C2S3", 8, 0, 0, $$ & 0xFFFF, $seq);
>
> Create a ping message.
>
> > >          my $chk = unpack("%32S*", $msg);
> > >          # $chk += ord(substr( $msg, -1 )) if length($msg) % 2;
> > >          $chk = ($chk & 0xFFFF) + ($chk >> 16) for 1..2;
> > >          $chk = 0xFFFF & ~$chk;
>
> Calculate the checksum.
>
> > >          $msg = pack("C2S3", 8, 0, $chk, $$ & 0xFFFF, $seq);
>
> Remake the ping message, but with the checksum.  I suppose I could have
> done:
>              substr( $msg, 2, 2 ) = pack("S", $chk);
> But since Net::Ping remakes the message, so do I.
>
> > >          [ $msg, $chk ];
>
> This is the last expression of the do block, and hence it is the value
> of the do block.  It becomes the right side value of the "||=" up above.
>
> > >       }};
>
> One of these is to match the "do {", the other is to match "@{".
>
> > >
> > >       my $rvec = $svec;
>
> We *always* try to read the socket (even if we're not trying to write to
> the socket.
>
> > >       (my ($n), $t) = select($rvec, $wvec, '', 0.5);
> > >       die "select failed: $!" if !defined($n) or $n < 0;
> > >       next if $n == 0; # timeout.
>
> This tests if the socket is ready for reading or writing.
>
> > >       if( $wvec =~ tr/^\0// ) {
>
> If we haven't looped all the way through the %hosts hash for this
> sequence number, then we need to send another ping packet.
>
> > >          my $ip; $ip ||= each %hosts for 1..2;
>
> This gets the next sockaddr_in struct from %hosts, repeating from the
> beginning if we've gone off the end.
>
> > >          send( $s, $msg, 0, $lastsent = $ip ) or die;
>
> Send the packet.
>
> > >          $wvec = "" if $ip eq $sentinel;
>
> If we've reached our starting point, don't send any more packets during
> this sequence number.
>
> > >       }
> > >
> > >       $rvec =~ tr/^\0// or next;
>
> If the socket is readable, continue.  If not, then repeat the loop.
>
> > >       my $responder = recv( $s, my ($resp), 8, 0 )
> > >          or die "Error in recv: $!"; # shouldn't happen.
>
> Get an icmp packet.
>
> > >       my ($port, $ip) = unpack_sockaddr_in($responder);
>
> Split the originating host into it's address and port number.
>
> > >       die "Expected port to be zero" if $port;
>
> This really ought to be "next if $port != 0;", since it probably is
> possible to send icmp packets from ports other than 0.  I think.
>
> > >       my ($rtype, undef, $rchk, $rpid, $rseq) =
> > >          unpack("C2S3", $resp);
>
> Unpack the parts of the icmp packet (ignoring the subtype field).
>
> > >       # make sure this is a valid packet:
> > >       $rtype == 0 and $rpid == ($$ & 0xFFFF)
> > >          and defined $checksums[$rseq]
> > >          and $rchk == $checksums[$rseq][1] or next;
>
> Check that the same data is coming back that we sent out.
>
> > >       # remove this host from the %hosts hash, and
> > >       # if wasn't previously there, ignore the packet.
> > >       delete $hosts{$responder} or next;
>
> When you delete a thing from a hash, it returns the old value of what
> had been there.  If you try to delete a thing that wasn't there to begin
> with, it returns undef.  So this will do a 'next' if the host that sent
> us the packet isn't in %hosts (either because it's from a machine we
> didn't ping, or because we've already recieved a ping response from
> them).
>
> I've just realized that there's a bit of a logic bug in my program
> here... if the element we've just deleted was $sentinel, the loop-
> through-%hosts-stopping-code will be confused, and, umm, not stop... So
> I need to set $sentinel to something else, if that's the case; the next
> element after where $sentinal was would be ideal, but I don't know how
> to efficiently find that out, especially not after we've just deleted
> it.  So instead, set it to $lastsent:
>
>    $sentinel = $lastsent if $sentinel eq $responder;
>
> Hmm, but even that might not work, if this response is *from* the last
> item we sent, or if we've previously recieved a response to the one
> which we last sent... so:
>
>    if( $sentinel eq $responder ) {
>       $sentinel = $hosts{$lastsent} ?
>          $lastsent :
>          (each %hosts or each %hosts);
>    }
>
> (The 'each %hosts or each %hosts' means that if we've gone past the last
> element of %hosts, use the first element.)
>
> Furthermore, way up above, the first item in the "do {" block, this same
> mistake needs to be fixed... where it says:
>
> >          $sentinel = $lastsent;
>
> It needs to be:
>
>            $sentinel = $hosts{$lastsent} ?
>               $lastsent :
>               (each %hosts or each %hosts);
>
> > >       # print out the fact that we've discovered
> > >       # that the host is alive.
> > >       print inet_ntoa($ip) . " is alive\n";
>
> The ntoa function means, "network format to ascii format".  You could
> probably use gethostbyaddr and print the host's real name, but that's
> your decision (it'll probably slow things down a bit, and you want your
> program to run as quickly as possible).
>
> > >       last unless %hosts;
>
> Exit the while loop if there are no more hosts to recieve pings from,
> since we've gotten pings from everyone.
>
> > >    } # end while(1)
>
> Err, this comment is wrong.  The condition of the while loop actually is
> for whether we've timed out or not.
>
> > >    print inet_ntoa($_)." is down\n" for values %hosts;
>
> Any element still in the %hosts hash after the while loop exits is one
> which we haven't gotten a response for.
>
> --
> my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
> ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]




------------------------------

Date: Sun, 13 Oct 2002 12:52:31 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: newb here learning Perl
Message-Id: <n0riqucdrt7jg310jhm1gb2lf45mlrlffo@4ax.com>

Mark Jason Dominus wrote:

>>I've tried to post there several times, never received anything.
>>I tried to register by sending E-mail to the administrators, never 
>>received a reply.
>
>What address did you use?  I'm an administrator, and I've never seen
>any mail from you.

Likely the trouble is with his ISP. I'm having trouble posting to
<news:comp.lang.perl.moderated> as well, my posts never seem to get
through to the moderators. That's why I post anything there from
<http://groups.google.com>.

-- 
	Bart.


------------------------------

Date: Sun, 13 Oct 2002 12:56:42 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: newb here learning Perl
Message-Id: <h5riqukpb3u1c4h0eao44hqtnna1l68j8c@4ax.com>

Jeff Zucker wrote:

>> I am learning Perl and was directed to this newsgroup by an e-book. It said
>> something about an E-Mail/FAQ thing I will get when I post for the first
>> time, so I am posting.
>
>
>No, I don't think you'll get the perl FAQs that way. 

Well, I remember I got a mail every time I first posted here with  a new
email address. I think it was Tom Christiansen who was responsible for
that.

No... I still have a copy here, and it starts like this:

>To: bart.mediamind@tornado.be
>Subject: WELCOME to comp.lang.perl.misc
>From: <gnat@frii.com> (Nathan Torkington)
>Date: Sun, 17 Nov 1996 16:00:05 -0700 (MST)
>
>Hello, 
>
>This email is automatically sent to every new poster to
>comp.lang.perl.misc.  You should only receive it once.  My apologies
>if the program contacts you twice, perhaps at two different accounts.
>This is not a flame, only an attempt to help newcomers get the most
>out of the newsgroup.
>
>If you are an experienced Perl programmer who simply has not posted
>before, or have inadvertently cross-posted to comp.lang.perl.misc, I
>apologize for inconveniencing you with this message.  Keep in mind
>that it is intended to help inform newcomers and cut down on redundant
>posts, which you then won't have to read.  Some of the resources in it
>may prove useful to you anyway, however.

 ...

-- 
	Bart.


------------------------------

Date: 13 Oct 2002 09:26:17 GMT
From: Rafael Garcia-Suarez <rgarciasuarez@free.fr>
Subject: Re: Perl 5.8 test failure
Message-Id: <slrnaqifc8.r7.rgarciasuarez@rafael.example.com>

Rob wrote in comp.lang.perl.misc :
> I have a web server running an old version of Suse Linux, I got caught 
> in a upgrade cascade trying to add some capabilities.
> 
> I wanted to up upgrade the Perl installation to 5.8 and it compiled 
> without failure but make test failed on Users:pwent. It was the only 
> failure.
> 
> I ran the additional test recommended but it did not give any more 
> information. I also tried to compile 5.6.1, with identical results.
> 
> Any suggestions on what may be wrong or how to go about tracking it down?

I've already seen this test failure on SuSe systems.

Apparently, the test makes some basic assumptions about the format of
your /etc/passwd, but your system uses a specific format, or has
specific users, or something. This is typically unportable, hence hard
to test.

Don't bother about this test, your perl most probably runs fine.

Can you post the full output of the test lib/User/pwent.t ?
(Or send it to me.)


------------------------------

Date: Sun, 13 Oct 2002 06:17:58 GMT
From: Darin McBride <darin@naboo.to.org.no.spam.for.me>
Subject: Re: STDIN and choices on screen?
Message-Id: <qe8q9.519789$Ag2.20161539@news2.calgary.shaw.ca>

Tavish Muldoon wrote:

> Hello,
> 
> I have a screen and I want to prompt the users for 1 of 3 choices.
> 
> Let's say I have a screen that says:
> 
> Choose 1 of the 3 options:
> 1=Turkey
> 2=Steak
> 3=Apple
> 
> Choose one:
> 
> What would be a good method to code this?


I recently did something like this - and I'm sure I could create a
module out of it ...

my @choices = (
               {
                   NAME => 'Turkey',
                   CODE => \&choose_turkey,
               },
               {
                   NAME => 'Steak',
                   CODE => \&choose_steak,
               },
               {
                   NAME => 'Apple',
                   CODE => \&choose_apple,
               },
               {
                   NAME => 'Quit',
                   OPT  => 'q',
               },
              )

my %opts;
my $opt_len = 0;
{
    my $idx = 0;
    for my $o (@choices)
    {
        unless ($o->{OPT})
        {
            $o->{OPT} = ++$idx;
        }
        $opts{$o->{OPT}} = $o;
        $opt_len = length($o->{OPT}) if length($o->{OPT}) > $opt_len;
    }
}

while (1)
{
    for my $o (@choices)
    {
        printf "%${opt_len}s - %s\n", $o->{OPT}, $o->{NAME};
    }
    my $choice = <STDIN>;
    chomp($choice);
    print("Invalid option [$choice]\n"),
        next unless exists $opts{$choice};
    if ($opts{$choice}{NAME} =~ /^Quit/)
    {
        last;
    }
    $opts{$choice}{CODE}->(@parameters);
}

(Untested - this wasn't a cut&paste job!)

> Is there a perl CASE statement or am I doing a bunch of if-then
> statemetents?

Often a case statement can be devolved (evolved?) into a hash table. 
This is because most languages with case statements can't put code refs
in hash tables as easily as Perl does.  e.g., C++ doesn't come with
hash tables standard, while Java can do it, you need a separate file
for each choice (you would put Runnable objects in the hash table, and
each Runnable object would then be its own class, thus its own file). 
Technically, you can use inner classes for this in Java, but I know
that the coding standards where I work say "no inner classes"  (another
topic for another newsgroup).


> i.e.
> 
> $choice=<STDIN>;
> if ($choice="1") {

Warning - $choice will include the \n.  Use chomp.

>    $choice="Turkey";
> }
> else choice="2"...etx
> 
> 
> 
> Ultimately I am going to have many choices (10-20).
> 
> Any suggestions on how to tackle this efficiently?

Hope this helps.  :-)

-- 
To reply, please remove the obvious spam filter


------------------------------

Date: Sun, 13 Oct 2002 16:17:46 +1000
From: Derek Thomson <derek@wedgetail.com>
Subject: Re: Switching from Python to Perl
Message-Id: <3da91047$0$23169$afc38c87@news.optusnet.com.au>

Hi,

Thomas Guettler wrote:
> 
> There are a lot of people who switched from
> perl to python. 

Where "a lot" is defined as "greater than zero"?

> Is there anyone who switched
> from python to perl?

Yes. Basically. I learned Python first, if that's what you mean. Then I 
learned Perl, and now I use Perl mostly, with Python occasionally.

Why do you ask? Why does it have to be mutually exclusive? Can't you 
like and use both? I am also using, right now, in some capacity, C, 
Java, Tcl, Lisp (my Emacs functions!) and I've done a fair bit of C++ in 
the past.

I've never understood this whole argument, to be honest.

--
D.



------------------------------

Date: 12 Oct 2002 23:00:23 -0700
From: manutd_kit@yahoo.com (kit)
Subject: use strict
Message-Id: <1751b2b5.0210122200.73b5de50@posting.google.com>

can anyone tell me please?

In the book, they've mentioned to put

use strict;   # on the top of the program

then I do,

my $qwer = 1;
my $qw_er =3; # compile time error 

Why is it happened?


------------------------------

Date: Sun, 13 Oct 2002 06:23:43 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: use strict
Message-Id: <3da910de.459181056@news.erols.com>

manutd_kit@yahoo.com (kit) wrote:

| can anyone tell me please?
| 
| In the book, they've mentioned to put
| 
| use strict;   # on the top of the program
| 
| then I do,
| 
| my $qwer = 1;
| my $qw_er =3; # compile time error 
| 
| Why is it happened?

Not a chance.  There must be more to the story than that.

    H>cat foo.pl
    #!perl
    use warnings;
    use strict;
    my $qwer = 1;
    my $qw_er =3;

    H>perl -c foo.pl
    foo.pl syntax OK




------------------------------

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 3962
***************************************


home help back first fref pref prev next nref lref last post