[22030] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4252 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 12 00:10:37 2002

Date: Wed, 11 Dec 2002 21:10:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 11 Dec 2002     Volume: 10 Number: 4252

Today's topics:
    Re: Simplify split and s/// statement <krahnj@acm.org>
    Re: Simplify split and s/// statement (Tad McClellan)
    Re: Simplify split and s/// statement <mgjv@tradingpost.com.au>
    Re: Telnet using "character mode" for modem control <jay@rgrs.com>
    Re: what perl calls is the challenge <xxxxxxx@xxx.xxx>
    Re: what perl calls is the challenge <bobx@linuxmail.org>
    Re: what perl calls is the challenge (Tad McClellan)
    Re: Why doesn't my array grow? <bstutes@eskimo.com>
        Windows to Unix Net::SCP or SFTP, public key authentica (Daveo)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 12 Dec 2002 01:39:02 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Simplify split and s/// statement
Message-Id: <3DF7E888.2E78B17@acm.org>

Alexander Stremitzer wrote:
> 
> I am using the following code segment in my program. The code does what
> it is supposed to do. However, it looks somewhat cludgy.
> Is there a way to simplify the statement below ? The goal is to remove
> the trailing white space from all fields.
> 
> my ($pat_name,$pat_id,$birth_date,$accnbr,$study_date) = split (/\|/,
> $PDS_LINE);
>     $pat_name =~ s/\s*$//;        # remove trailing white space
>     $pat_id =~ s/\s*$//;        # remove trailing white space
>     $birth_date =~ s/\s*$//;    # remove trailing white space
>     $accnbr =~ s/\s*$//;        # remove trailing white space
>     $study_date =~ s/\s*$//;    # remove trailing white space
> 
> __DATA__
> Patient name          |patient id       |1926.02.02|123456789
>  |2002.10.12


my ($pat_name,$pat_id,$birth_date,$accnbr,$study_date) = split /\s*\|\s*/, $PDS_LINE;



John
-- 
use Perl;
program
fulfillment


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

Date: Wed, 11 Dec 2002 21:16:54 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Simplify split and s/// statement
Message-Id: <slrnavfvt6.37o.tadmc@magna.augustmail.com>

Alexander Stremitzer <stremitz@consultant.com> wrote:
> I am using the following code segment in my program. The code does what 
> it is supposed to do. However, it looks somewhat cludgy.
> Is there a way to simplify the statement below ? The goal is to remove 
> the trailing white space from all fields.
> 
> my ($pat_name,$pat_id,$birth_date,$accnbr,$study_date) = split (/\|/, 
> $PDS_LINE);


   foreach ( $pat_name, $pat_id, $birth_date, $accnbr, $study_date ) {
      s/\s+$//;
   }


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 12 Dec 2002 04:23:57 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Simplify split and s/// statement
Message-Id: <slrnavg3uf.865.mgjv@verbruggen.comdyn.com.au>

On Wed, 11 Dec 2002 17:33:04 -0500,
	Alexander Stremitzer <stremitz@consultant.com> wrote:
> I am using the following code segment in my program. The code does what 
> it is supposed to do. However, it looks somewhat cludgy.
> Is there a way to simplify the statement below ? The goal is to remove 
> the trailing white space from all fields.
> 
> my ($pat_name,$pat_id,$birth_date,$accnbr,$study_date) = split (/\|/, 
> $PDS_LINE);

Just to add another possibility:

my ($pat_name,$pat_id,$birth_date,$accnbr,$study_date) = 
    map { s/\s+$// } split (/\|/, $PDS_LINE);

I like map for the readability of the code.

Martien
-- 
                        | 
Martien Verbruggen      | For heaven's sake, don't TRY to be cynical.
Trading Post Australia  | It's perfectly easy to be cynical.
                        | 


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

Date: 11 Dec 2002 18:16:33 -0500
From: Jay Rogers <jay@rgrs.com>
Subject: Re: Telnet using "character mode" for modem control
Message-Id: <828yywcfji.fsf@shell2.shore.net>

Milan <me@planet-earth.com> writes:
> Does anyone know of a way to make the Net::Telnet modules use 
> "character" mode instead of "line" mode.  I have checked the 
> documentation but cannot find anything about this.

This is item from the section "What To Know Before Using" of the
Net::Telnet doc may be helpful:

     . The output record separator for print() and cmd() is set
       to "\n" by default, so that you don't have to append all
       your commands with a newline.  To avoid printing a
       trailing "\n" use put() or set the output_record_separator
       to "".

--
Jay Rogers
jay@rgrs.com


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

Date: Thu, 12 Dec 2002 00:29:28 GMT
From: "Brad" <xxxxxxx@xxx.xxx>
Subject: Re: what perl calls is the challenge
Message-Id: <ILQJ9.18518$y14.1658330@news1.east.cox.net>


"Eric Osman" <os7man@attbi.com> wrote in message
news:3DF7B95E.D32CE1FC@attbi.com...
>
> Hi,
>
> My challenge seems to be with the things my perl
> script is calling, rather than perl itself.
>
> So, when you read this question and feel I need to
> be asking "elsewhere" and you can suggest a useful
> newsgroup, please let me know.
>
> I'm having trouble getting the following perl (excerpt
> only shown) to work :
>
> #!/usr/bin/perl
> %postInputs = readPostInput();
> $dateCommand = "date";
> $time = `$dateCommand`;
> open (MAIL, "|/usr/sbin/sendmail -t") || return 0;
> select (MAIL);
>         . . .
>
> This example is suggested in  "writing your first program"
> in my perl book.  If you want to see the entire
> program, it's on this web page :
>
>       ftp://ftp.sybex.com/2200/Perllist1.pdf
>
> My environment is windows 98 with indigoperl .

The main problem is that you are using Windows 98, and the sendmail command
is a UNIX command.  This is not what I would call a "first" program to use.
INot sure why it would be listed as one either.  I'm sure there are perl
books out there for the Windows users.

Brad




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

Date: Thu, 12 Dec 2002 00:35:23 GMT
From: "Bob X" <bobx@linuxmail.org>
Subject: Re: what perl calls is the challenge
Message-Id: <fRQJ9.1521$uV4.1158683@news2.news.adelphia.net>

http://www.oreilly.com/catalog/lperlwin/




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

Date: Wed, 11 Dec 2002 20:39:15 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: what perl calls is the challenge
Message-Id: <slrnavftmj.2jd.tadmc@magna.augustmail.com>

Eric Osman <os7man@attbi.com> wrote:

> My challenge seems to be with the things my perl
> script is calling, rather than perl itself.


Your challenge is really that you are using a very poor
source of information.


> I'm having trouble getting the following perl (excerpt
> only shown) to work :
> 
> 	#!/usr/bin/perl
> 	%postInputs = readPostInput();
> 	$dateCommand = "date";
> 	$time = `$dateCommand`;
> 	open (MAIL, "|/usr/sbin/sendmail -t") || return 0;
> 	select (MAIL);
>         . . .
> 
> This example is suggested in  "writing your first program"
> in my perl book.  


What Perl book is that?

Does it have a title and author?

(time passes...)

Oh. It appears to be "Mastering Perl 5" by Eric C. Herrmann.

Is that the one?


> If you want to see the entire
> program, it's on this web page :
> 
>       ftp://ftp.sybex.com/2200/Perllist1.pdf


That is not a web page. Web pages use the hypertext transfer
protocol (HTTP), not the file transfer protocol (FTP).


> My environment is windows 98 with indigoperl .
> 
> I'll present my MAIN challenge first, then a more
> minor one.
> 
> The main one is with
> 
> 	open (MAIL, "|/usr/sbin/sendmail -t")  . . .

> I'm sure "sendmail" is standard on unix systems, but
> should I be using something else in indigoperl on
> windows 98 ?


I expect so, but I can't help with that because I don't do Windows.

Your anonymous "perl book" appears to assume that you are
on a Unix system.

(time passes...)

Err, except he also uses `dir/w`...


> Or am I supposed to be installing "sendmail" from
> some independently different place ?  (what do you
> suggest ?) .


The author does not know Perl very well.

The author is not a very good teacher.

I suggest selling the book to a sucker on Ebay and getting
a Real Book.   :-)


> The more minor challenge is with this morsel:
> 
> 	$dateCommand = "date";
> 	$time = `$dateCommand`;
> 
> 
> That was HANGING my script, because on windows 98,
> the "date" command not only displays the date but asks
> you to type in a new one !!!!


> What should I be using instead.


The author of the "book" should have used something else instead.

He inserted a system dependency when he didn't need to, he could
have gotten what he wanted using only native Perl:

   my $time = localtime;


> Thanks for any ideas.


Your book sucks. Ditch it before you learn more bad habits.

Below are some examples of its suckiness:

   no warnings
   no strictures
   no CGI.pm on any of the programs shown!
   barewords galore
   ignores perlstyle.pod
   uses select() for few print()s


-----

Confuses folks right off the bat with alternative quoting
delimiters, when it doesn't have to:

book:
   print qq|The value of $key is $ENV{"$key"}\n|;

better:
   print "The value of $key is $ENV{$key}\n";

Since this code is labeled as "Listing 1.1" I assume it is
the very first code that readers are exposed to?


-----

More unnecessary complexity:

book:
   select (MAIL); 
   print << "EOF";       <== useless double quotes
    ...
   EOF
   select (STDOUT);

better:
   print MAIL << EOF;
    ...
   EOF

-----

So far they have just been presented badly, this one
is a plain bug!

The purpose of file locking is to avoid data corruption due to
a "race condition", this code _has_ a race condition, the very
thing it supposed to be protecting against.

   flock(OUTFILE, LOCK_UN)|| warn $!;     <== delete this line of code
   close (OUTFILE);

-----

   @carMakes = (Mitsubishi, Geo, Chevrolet, Ford);

Bare words are bad. Strings should be quoted.

-----

C code, written in Perl:

book:
   for ($index = 0; $index <= $#inventory; $index++){

better:
   for $index ( 0 .. $#inventory ) {

-----

You should always, yes *always*, check the return value from open().

book:
   open (STOREINV, "$store${num}.txt");
                           ^   ^
                           ^   ^ useless use of curlies
better:
   open(STOREINV, "$store$num.txt") or 
      die "could not open '$store$num.txt' $!";

-----

perlvar.pod says "Its use is highly discouraged."

   $[ = 1501;

so the author should not be teaching/recommending it.

-----

Uses the dollar-digit variables without first testing
for a successful match.

book:
   $totalDue =~ /(\d*\.\d\d)/; 
   $truncatedValue = $1;

better:
   if ( $totalDue =~ /(\d*\.\d\d)/ ) {
      $truncatedValue = $1;
   }
 
(and he appears to not understand accuracy and precision issues
 of floating point numbers...
)

-----

Gak! Teaches symrefs to beginners!

Symrefs are for experts only.

   Listing 7.1: Symbolic References

-----

Errr, _which_ parenthesis?

book:
   #Note that the parentheses are REQUIRED 
   ($s, $st, $segmentComment) = split(' ',$line,3);

just as good:
   ($s, $st, $segmentComment) = split ' ', $line, 3;


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Wed, 11 Dec 2002 22:59:25 -0600
From: Bob Stutes <bstutes@eskimo.com>
Subject: Re: Why doesn't my array grow?
Message-Id: <at953l$37e$1@eskinews.eskimo.com>

Rob Richardson wrote:
> Greetings!
> 
> I am trying to generate a calendar.  Since a calendar can conceivably
> require 6 rows of 7 cells each, I am trying to create a 42-element
> array.  Those cells that represent valid dates will get the date in a
> string format.  Those that don't represent dates will get an empty
> string.  Here's the code:
> 
> sub calendar
> {
> <initialization code snipped>
> 
> # Create a 42-element array starting at the start index.
> # @calendar = ($startIndex .. $startIndex + 42);
> @calendar = ();
> # for ($i = $startIndex; $i < ($startIndex + 42); $i++)
> for ($i = 0; $i < 42; $i++)
> {
> 	$currentIndex = $startIndex + $i;
> 	if ($currentIndex < 1 || $currentIndex > $daysInThisMonth)
> 	{
> 		$calendar[currentIndex] = ""
> 	}
> 	else
> 	{
> 		$calendar[currentIndex] = "$actualMonth.$currentIndex.$actualYear"
> 	}
> 	print "Index: $currentIndex; contents: $calendar[currentIndex]! <BR>"
> }
> 
> $arraySize = @calendar;

make this line: $arraySize = $#calendar;
see perldata documentation.

> print "Before returning from subroutine, calendar has $arraySize
> elements. <BR>";
> return @calendar;
> }
> 
> I'm a newbie in Perl, but I understand that arrays are supposed to
> grow if you write to an element beyond the current end of the array. 
> The print statement that reports the contents of the cells shows that
> the cells are being populated as expected.  But the print statement
> that reports the size of the array says the array only has one
> element!  What don't I know yet?
> 
> Thanks!
> 
> Rob

-- 
Bob Stutes - St. Louis, Mo.
Unix Administrator and General Geek Wanna-Be
e-mail: bstutes@eskimo.com

The Wisdom of the ages may be found ... if you will only look up.
                                           Unknown.



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

Date: 11 Dec 2002 15:07:06 -0800
From: david.c.obrien@citigroup.com (Daveo)
Subject: Windows to Unix Net::SCP or SFTP, public key authentication question
Message-Id: <7b343fef.0212111507.b2f889f@posting.google.com>

I am trying to establish a SSH connection from Windows to a Unix host
via Net::SCP.  The module allows public key authentication.  I know
that I put the public key in the ~username/.ssh/authorized_keys file,
and I can get this to work with the Putty Windows SSH client (using
the puttygen.exe program to generate the private and public keys).

My question(s) is how do I generate a set of keys, for use with
Net::SCP/SFTP?
Once generated, where do I put them, so they can be used (on the
client side)?

I have done a pretty thorough google search for this, and read the
ssh-keygen man pages etc, but most of these assume you are doing a
Unix-Unix transfer.

A few people mention they have done this, but don't mention how they
managed the client side key generation/handling.

thanks

Dave


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

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


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