[9749] in Perl-Users-Digest
Perl-Users Digest, Issue: 3344 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 4 16:06:38 1998
Date: Tue, 4 Aug 98 13:01:31 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 4 Aug 1998 Volume: 8 Number: 3344
Today's topics:
Re: parsing of here-docs (Craig Berry)
Re: passwords and DOS/Win <dnp@ams.org>
Problem with $/ and \x0D on Win32 (Bob Lanteigne)
Re: Problem with $/ and \x0D on Win32 <jim.michael@gecm.com>
Processing on email recv <knguyen@ab.bluecross.ca>
Re: Putting \r\n at end of lines using format and write (Ilya Zakharevich)
Re: Reading in one file and writing to another <aqumsieh@matrox.com>
Re: Reading in one file and writing to another <mpgromm@sandia.gov>
Socket timeout problem. azqaz@my-dejanews.com
subroutine name <bjlockie@nortel.ca>
system( ) commands in CGI script (Brian Day)
Re: system( ) commands in CGI script (Steve Linberg)
Re: system( ) commands in CGI script (Nem W Schlecht)
Which Version of perl should I use? <rjk@fprsdev3.fmr.com>
Re: Which Version of perl should I use? (Steve Linberg)
Win32: creating standalone perl.exe and interp.exe (no (Sitaram Chamarty)
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 4 Aug 1998 18:19:49 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: parsing of here-docs
Message-Id: <6q7jc5$nkh$1@marina.cinenet.net>
justin_lloyd@my-dejanews.com wrote:
: I've run into an interesting parsing issue when it comes to here-docs. I have
: some code that boils down to this:
:
: $email_address = "bob@nowhere.com";
In recent Perl versions, you need to either \ the @ or use ''.
: send_message($email_address, <<END_OF_MSG) if $email_address;
: Hi there, Bob!
: END_OF_MSG
:
: However, the actual line of code is pretty long so I wrapped it:
:
: $email_address = "bob@nowhere.com";
: send_message($email_address, <<END_OF_MSG)
: if $email_address;
: Hi there, Bob!
: END_OF_MSG
:
: The line
:
: if bob@nowhere.com;
:
: appears as the first line of the message. It seems that the parsing of the
: conditional statement should precede that of the here-doc. Is this exhibited
: behavior correct, or should it do as I expected?
Nope, it's doing the right thing. The here doc starts after the next
newline following the here-doc <<HERE tag. This allows weird stuff like:
$a = <<END .
This is some text
END
' followed by some more';
print $a;
which prints out
This is some text
followed by some more
If Perl tried to finish parsing the expression (grab the right side of the
. operator, in this case) before processing the here doc, this wouldn't
work.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: Tue, 04 Aug 1998 15:18:50 -0400
From: Dan Pelton <dnp@ams.org>
To: b_redeker@my-dejanews.com
Subject: Re: passwords and DOS/Win
Message-Id: <35C75E9A.C4177071@ams.org>
Here is an alternative to system ('stty -echo'). I am not sure if this will work
in dos but give it a try.
Get the Term::ReadKey module by dowloading TermReadKey-2_12.tar.gz
from http://www.perl.com/CPAN-local/modules/by-module/Term/
This code fragment reads in a string without echoing what's been type.
use Term::ReadKey; # use to read in a password
print "Enter a password: ";
ReadMode 2; # Turn echo off
$password = ReadLine 0; # read in the password
chomp ($password);
ReadMode 0; # Reset tty mode
Hope this helps,
Dan
b_redeker@my-dejanews.com wrote:
>
> does anyone know how you can read a password from STDIN and not show that
> password on screen?
>
> with UNIX you would use
> system ('stty -echo');
> but under DOS/Win
> system ('@echo off');
>
> doesnt work
> thanx if you have the answer
>
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Tue, 04 Aug 1998 18:48:11 GMT
From: bob.p.lanteigne@mcdermott.com (Bob Lanteigne)
Subject: Problem with $/ and \x0D on Win32
Message-Id: <35c75562.21178625@trakker>
I'm using Perl on Win32 to process a file which has a line delimiter
of 0x0D, but I can't get it to work. This is what I've tried:
$/ = "\x0d";
while (<>) {
...
}
but all I ever get is one long line. I've also tried:
undef $/;
while (<>) {
...
}
and I get one long line w/out any 0xOD's:
$cnt = tr/\x0d//;
print $cnt;
gives me 0. I'm wondering if this is a bug in the Win32 port?
Perl particulars:
Summary of my perl5 (5.0 patchlevel 4 subversion 02) configuration:
Platform:
osname=MSWin32, osvers=4.0, archname=MSWin32
uname=''
hint=recommended, useposix=true, d_sigaction=undef
bincompat3=undef useperlio=undef d_sfio=undef
Compiler:
cc='cl', optimize='-O', gccversion=
cppflags='-DWIN32'
ccflags ='-MD -DWIN32'
stdchar='unsigned char', d_stdstdio=define, usevfork=false
voidflags=15, castflags=0, d_casti32=define, d_castneg=define
intsize=4, alignbytes=8, usemymalloc=n, randbits=15
Linker and Libraries:
ld='link', ldflags ='-nologo -subsystem:windows'
libpth=c:\msdev\lib
libs=oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib
netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib version.lib
odbc32.lib odbccp32.lib
libc=msvcrt.lib, so=dll
useshrplib=undef, libperl=undef
Dynamic Linking:
dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
cccdlflags='', lddlflags='-dll'
Characteristics of this binary (from libperl):
Compile-time options: DEBUGGING
Built under MSWin32
Compiled at Aug 9 1997 21:42:37
@INC:
C:\ETC\PERL\lib\site
C:\ETC\PERL\lib
c:\perl\lib
c:\perl\lib\site
c:\perl\lib\site
.
-----
Bob Lanteigne
------------------------------
Date: Tue, 04 Aug 1998 15:21:17 -0400
From: Jim Michael <jim.michael@gecm.com>
Subject: Re: Problem with $/ and \x0D on Win32
Message-Id: <35C75F2D.4A24@gecm.com>
Bob Lanteigne wrote:
>
> I'm using Perl on Win32 to process a file which has a line delimiter
> of 0x0D, but I can't get it to work. This is what I've tried:
Have you binmode the file?
perldoc -f binmode
------------------------------
Date: Tue, 04 Aug 1998 12:13:54 -0600
From: Ky Nguyen <knguyen@ab.bluecross.ca>
Subject: Processing on email recv
Message-Id: <35C74F61.98E4BF26@ab.bluecross.ca>
Hi all,
I seen sites using email to process request using keywords in Subject or
Body.
Could someone pls point out how this can happen?
Thanks
PS: I realize this is not a perl question but I believe that many
adminstrators
must deal with this issue using perl as backend tool. If I am asking the
wrong
group, pls point out where is the right group.
------------------------------
Date: 4 Aug 1998 19:56:12 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Putting \r\n at end of lines using format and write
Message-Id: <6q7p0s$q5u$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Russ Allbery
<rra@stanford.edu>],
who wrote in article <m34svtym1b.fsf@windlord.Stanford.EDU>:
> stefan@consilia.aland.fi writes:
>
> > Do I use ^M as is or should I embed it using some sort of CRLF code?
>
> To get the effect that you're looking for, you'd have to put in a literal
> Control-M. That *should* work currently, although I'm not sure how well
> it will continue to work with Perl's style of reading scripts.
> Alternately, you could do something like assigning "\r" to a variable and
> printing that variable out at the end of every format line....
Literal \r do not work with newest Perl.
Ilya
------------------------------
Date: Tue, 04 Aug 1998 13:41:24 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Reading in one file and writing to another
Message-Id: <35C747C4.B9AD2682@matrox.com>
Matt Grommes wrote:
>
> The script reads in $message then adds $message to the text in $line. It
> then goes through the external file until it finds <--NewsText--> and it
> is supposed to insert $line into that space. It does that fine except
> that is overwrites the next text in the file. I need to make it so it
> doesn't overwrite the text following the <--NewsText--> string. Any help
> that anyone can offer would be greatly appreciated. Thanks in advance.
>
Another FAQ question. See Perlfaq5:
How do I change one line in a file/delete a line in a
file/insert a line in the middle of a file/append to the
beginning of a file?
Basically, you have to read your file line by line, modifying the lines
(if needed) and printing them into another file. Then you can rename
your new file into the old one.
--
Ala Qumsieh | No .. not Just Another
ASIC Design Engineer | Perl Hacker!!!!!
Matrox Graphics Inc. |
Montreal, Quebec | (Not yet!)
------------------------------
Date: Tue, 04 Aug 1998 13:33:51 -0600
From: Matt Grommes <mpgromm@sandia.gov>
Subject: Re: Reading in one file and writing to another
Message-Id: <35C7621F.F376441A@sandia.gov>
Man, I'm an idiot. I never even thought of writing to another file. doh.
Thanks alot.
Ala Qumsieh wrote:
> Matt Grommes wrote:
> >
> > The script reads in $message then adds $message to the text in $line. It
> > then goes through the external file until it finds <--NewsText--> and it
> > is supposed to insert $line into that space. It does that fine except
> > that is overwrites the next text in the file. I need to make it so it
> > doesn't overwrite the text following the <--NewsText--> string. Any help
> > that anyone can offer would be greatly appreciated. Thanks in advance.
> >
>
> Another FAQ question. See Perlfaq5:
>
> How do I change one line in a file/delete a line in a
> file/insert a line in the middle of a file/append to the
> beginning of a file?
>
> Basically, you have to read your file line by line, modifying the lines
> (if needed) and printing them into another file. Then you can rename
> your new file into the old one.
>
> --
> Ala Qumsieh | No .. not Just Another
> ASIC Design Engineer | Perl Hacker!!!!!
> Matrox Graphics Inc. |
> Montreal, Quebec | (Not yet!)
>
------------------------------
Date: Tue, 04 Aug 1998 18:55:50 GMT
From: azqaz@my-dejanews.com
Subject: Socket timeout problem.
Message-Id: <6q7lfm$dk0$1@nnrp1.dejanews.com>
I am trying to learn socket programming and put together the following
piece of code to read the /etc/hosts file and then connect to the systems and
get the time in time format not date/time format. It then formats the data
and prints it out. The problem I am having is that when an attempt is made
to read from a system that is not responding the timeout doesn't seem to work
and the read will sit for minutes before it finally times out. I looked at
the perlipc man page and at the perldoc entries for IO::Socket and
IO::Socket::INET and it looks to me like it should work. I even checked the
timeout value after the socket is created and it says that the timeout value
is set. If someone could let me know what I am doing wrong, besides learning
to program, I would appreciate it.
#!/usr/local/bin/perl
use Socket;
use strict;
use IO::Socket;
my ($machine, $name, $altnames ,$addrtype ,$len, @addrlist, $nam1, $altname1);
my ($q, $w, $protonum, $a, $b, $c, $d, $oops, $socket1);
my ($addressserver, $i, $data1 ,$timeserver ,$servertime);
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $ydat, $isdst);
my ($firstword, $secondword, @hosts, @wordlist, $packmask);
open (zxcv,"/etc/hosts");
@hosts = <zxcv>;
close (zxcv);
foreach (@hosts) {
s/^\s+//;
s/\s+/ /g;
@wordlist = split(/ /, $_);
($firstword, $secondword) = @wordlist;
if ($firstword == "#" || $firstword == "" ) {
next;
}
$socket1 = IO::Socket::INET->new(
PeerAddr => $secondword,
PeerPort => 37,
Proto => 'tcp',
Timeout => '3'
);
# $a = $socket1->timeout();
# print ("timeout is $a\n");
while (<$socket1>) {$data1 = $_}
$socket1->close;
$timeserver = unpack ("N",$data1);
($sec, $min, $hour, $mday, $mon, $year, $wday, $ydat, $isdst) =
localtime($timeserver - 2208988800);
printf ("The date and time on the %s system is %d:%d:%d
%d/%d/%d\n",$secondword,$hour,$min,$sec,$mon++,$mday,$year);
}
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Tue, 04 Aug 1998 15:29:39 -0400
From: Bob Lockie <bjlockie@nortel.ca>
Subject: subroutine name
Message-Id: <35C76123.87C45F55@nortel.ca>
How can I get the name of the currently running subroutine?
I can use the function "caller" to get the package, file, line.
I want to log the executing subroutine.
------------------------------
Date: 4 Aug 1998 18:16:05 GMT
From: bday@cbr.eng.sun.com (Brian Day)
Subject: system( ) commands in CGI script
Message-Id: <6q7j55$pan$1@engnews2.Eng.Sun.COM>
Keywords: CGI perl system
Does anybody know why the following will not return two values that I can compare:
$test = `ls -d $path`; #-d returns dir name not it's contents
$test2 = `ls -d $path2`; # $path,$path2 are legal UNIX paths
if ($test ne $test2)
{ print "File doesn't exist for both records";
}
I have also tried:
$test = system("ls -d $path"); #-d returns dir name not it's contents
$test2 = system("ls -d $path2"); # $path,$path2 are legal UNIX paths
if ($test ne $test2)
{ print "File doesn't exist for both records";
}
Neither example works. If I use one system() call with one backslash call, it works but the system call returns an integer, and the backlsash call returns a string. The
comparison works then, but I don't think this is good practice.
Any information would be greatly appreciated.
Thank You,
Brian
---
Brian T. Day
email: bday@Eng.sun.COM
voice: (650) 336-1331
Sun Microsystems, Inc.
mailstop: UMTV03-02
901 San Antonio Rd
Palo Alto, CA 94303-4900
------------------------------
Date: Tue, 04 Aug 1998 14:43:44 -0400
From: linberg@literacy.upenn.edu (Steve Linberg)
Subject: Re: system( ) commands in CGI script
Message-Id: <linberg-0408981443440001@projdirc.literacy.upenn.edu>
In article <6q7j55$pan$1@engnews2.Eng.Sun.COM>, bday@cbr.eng.sun.com wrote:
> Does anybody know why the following will not return two values that I
can compare:
>
> $test = `ls -d $path`; #-d returns dir name not it's contents
> $test2 = `ls -d $path2`; # $path,$path2 are legal UNIX paths
That should work. Backticks capture output. What are $path and $path2?
_____________________________________________________________________
Steve Linberg National Center on Adult Literacy
Systems Programmer &c. University of Pennsylvania
linberg@literacy.upenn.edu http://www.literacyonline.org
------------------------------
Date: 4 Aug 1998 13:40:45 -0500
From: nem@abattoir.cc.ndsu.nodak.edu (Nem W Schlecht)
Subject: Re: system( ) commands in CGI script
Message-Id: <6q7kjd$boi@abattoir.cc.ndsu.nodak.edu>
Keywords: CGI perl system
[courtesy copy e-mailed to author(s)]
In comp.lang.perl.misc, Brian Day <bday@cbr.eng.sun.com> wrote:
>Does anybody know why the following will not return two values that I can compare:
>
> $test = `ls -d $path`; #-d returns dir name not it's contents
> $test2 = `ls -d $path2`; # $path,$path2 are legal UNIX paths
>
> $test = system("ls -d $path"); #-d returns dir name not it's contents
> $test2 = system("ls -d $path2"); # $path,$path2 are legal UNIX paths
>
>Neither example works. If I use one system() call with one backslash call,
>it works but the system call returns an integer, and the backlsash call
>returns a string. The comparison works then, but I don't think this is
>good practice.
Of course system() returns a number, just like most unix commands do. Just
because they output something to the tty has nothing to do with what they
return ('grep' returns some very useful numbers!). The backtick one is
okay, but you'll want to write them like this:
chomp($test = `ls -d $path`);
....
To get rid of the trailing newline. The "correct" (note: as long as works,
it's good perl code) way of doing this is to do an open() call for each one
with a pipe, like this:
open(FIRST, "ls -d $path |") || die "Could not do first ls";
open(SECOND, "ls -d $path2 |") || die "Could not do second ls";
Then do a while(<FIRST>) { yadda yadda yadda.... read input from both
listings, compare input, close filehandles.
--
Nem W Schlecht nem@plains.nodak.edu
NDUS UNIX SysAdmin http://www.nodak.edu/~nem/
"Perl did the magic. I just waved the wand."
------------------------------
Date: Tue, 04 Aug 1998 18:13:04 GMT
From: Rick Meldrum <rjk@fprsdev3.fmr.com>
Subject: Which Version of perl should I use?
Message-Id: <35C74FA0.13F1@fprsdev3.fmr.com>
I am *not* having any problems with 5.003, but have recently heard that
a later revision would be better.
Are there problems with 5.003? If so, like what?
Should I bother to update 20+ machine with 5.004? ...Or is 5.005 just
around the corner? (I'm aware it's currently available)
Suggestions would be most appreciated?
Thanks,
Rick
------------------------------
Date: Tue, 04 Aug 1998 14:40:04 -0400
From: linberg@literacy.upenn.edu (Steve Linberg)
Subject: Re: Which Version of perl should I use?
Message-Id: <linberg-0408981440040001@projdirc.literacy.upenn.edu>
In article <35C74FA0.13F1@fprsdev3.fmr.com>, Rick Meldrum
<rjk@fprsdev3.fmr.com> wrote:
> I am *not* having any problems with 5.003, but have recently heard that
> a later revision would be better.
>
> Are there problems with 5.003? If so, like what?
>
> Should I bother to update 20+ machine with 5.004? ...Or is 5.005 just
> around the corner? (I'm aware it's currently available)
Unless you have a specific reason not to, it's always best to use the
latest available. 5.005 fixes some serious security holes in earlier
versions. 5.005_02 should be ready shortly, I think.
US$0.02.
_____________________________________________________________________
Steve Linberg National Center on Adult Literacy
Systems Programmer &c. University of Pennsylvania
linberg@literacy.upenn.edu http://www.literacyonline.org
------------------------------
Date: 4 Aug 1998 19:08:56 GMT
From: sitaram@diac.com (Sitaram Chamarty)
Subject: Win32: creating standalone perl.exe and interp.exe (no DLLs)
Message-Id: <slrn6sen01.5l8.sitaram@diac.com>
I'm totally new to the Win32 environment, and need some help with
this. Needless to say, I have tried all the FAQs etc., even tried
to munge the various makefiles and so on, (like naively removing
-DPERLDLL!) but no luck.
I would like to create an embedded perl (using the example
interp.c in "man perlembed") on Windows NT but *without* needing a
perl.dll. I don't care how big the executable gets, all I need is
for the whole thing to be standalone.
I don't need this for the main perl.exe, just for the interp.exe
that will be built later! But I have tried building a standalone
perl.exe and even that doesn't work...
Can anyone help? Is it even possible under NT? (Gurusamy?)
Thanks much.
Sitaram
------------------------------
Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 3344
**************************************