[11858] in Perl-Users-Digest
Perl-Users Digest, Issue: 5458 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 22 17:07:41 1999
Date: Thu, 22 Apr 99 14:00:23 -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 Thu, 22 Apr 1999 Volume: 8 Number: 5458
Today's topics:
Ansi Characters in Perl <swolfington@home.com>
Any free CGI hosting allow running similar to UNIX ? <austin95002887@yahoo.com>
cookie being shown in browser <rgl34@hotmail.com>
Re: DJGPP Port for DOS (Was Re: for (my $i;;) doesn't w (Bart Lateur)
Re: DJGPP Port for DOS (Was Re: for (my $i;;) doesn't w <jhi@alpha.hut.fi>
Re: DJGPP Port for DOS (Was Re: for (my $i;;) doesn't w (Bart Lateur)
Extracting fields to scalar variables? <mmione@tns-inc.com>
Re: Extracting fields to scalar variables? <jglascoe@giss.nasa.gov>
Re: FAQ 4.15: How do I find yesterday's date? <dgris@moiraine.dimensional.com>
Re: Generating a unique string for order number (Benjamin Franz)
Re: help! file upload from web <cassell@mail.cor.epa.gov>
Help: Problem capturing cntl-c signal in perl script <ecastle@nuance.com>
Re: Help: Problem capturing cntl-c signal in perl scrip <ecastle@nuance.com>
how can i extract an attach file in a mail ? mikl_paris@my-dejanews.com
Re: how do you pass hashes to functions? <tchrist@mox.perl.com>
How to read a NT mapped driver from CGI ? <qsun@kitco.ca>
Re: Illegal seek (this makes no sense to me =) phukit@enteract.com
Re: Is there a shorter way? (Larry Rosler)
Re: Is there a shorter way? (Randal L. Schwartz)
Re: Is there a shorter way? <uri@sysarch.com>
Re: newbie with a "howto" question <cassell@mail.cor.epa.gov>
Re: Please, HELP with uninitialized value error <Michael.Cameron@no.spam.technologist.com>
postgreSQL and Perl (Stephane Jose)
Re: Reading C binary data from disk <uri@sysarch.com>
Re: Reading C binary data from disk <tchrist@mox.perl.com>
Reading files <aghaeim@genesis.co.nz>
Re: Reading in password from <STDIN> <t-armbruster@ti.com>
Re: Reading in password from <STDIN> <tonylabb@infonline.net>
Re: SNMP <gmarzot@baynetworks.com>
Re: The Future of Tk? (Kaz Kylheku)
Re: To trim right blanks from a field. (Larry Rosler)
Re: Unix files in MacPerl <jason.holland@dial.pipex.com>
Re: Verifying text in a string <jglascoe@giss.nasa.gov>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 22 Apr 1999 20:48:43 GMT
From: "Scott W" <swolfington@home.com>
Subject: Ansi Characters in Perl
Message-Id: <LWLT2.295$hl3.2029@news.rdc2.occa.home.com>
Hi!
How do I reference ANSI characters in Perl? For instance, the ANSI
character
for the letter C is 99. Thanks!
Scott
------------------------------
Date: 22 Apr 1999 20:01:36 GMT
From: "Austin Ming" <austin95002887@yahoo.com>
Subject: Any free CGI hosting allow running similar to UNIX ?
Message-Id: <7fnv70$2g5$48@newsread.f.de.uu.net>
Any free CGI hosting allow running similar to UNIX ?
I really don't want to run CGI using FTP uploading!
I want to run CGI and learn more it in UNIX environment.
------------------------------
Date: 22 Apr 1999 20:01:32 GMT
From: "Robert Long" <rgl34@hotmail.com>
Subject: cookie being shown in browser
Message-Id: <7fnv6s$2g5$45@newsread.f.de.uu.net>
I have a rather complicated CGI that uses "plug-ins", that is it passes the
parsed information from a form on to a small script. I have a "plug-in" that
delivers a cookie, however, the cookie is displayed in the browser window.
I am using CGI.pm to do this, but I'm afraid I am not using it
correctly....below is the code that is delivering the cookie.
use CGI qw(:standard);
$debug=0;
print header if $debug;
print "Testing<br>" if $debug;
$query = new CGI;
%destination = qw(RAuth
http://www.rlong.com/legal/trademarp/pusage_logo/download_instr.html
rlongDALAN http://support.rlong.com/nav/license.htm
rlongDADMI http://support.rlong.com/nav/license.htm
rlongDAMBA ftp://ftp.rlong.com/pub/nic/bw98util.exe
rlongDAMPC
http://www.rlong.com/client/mcd/technology/damobile/software.html
);
foreach $cookie (keys %destination) {
print "\$cookie is $cookie\n" if $debug;
$dest = param('Dest');
if ($cookie eq $dest){
if ($cookie = $query->cookie($cookie)) {
print "\$cookie is now $cookie\n" if $debug;
$gotit = $destination{$cookie};
print "<H1>got it $gotit</H1><H1>destination $destination{$cookie}</H1>"
if $debug;
}
}
}
if ($gotit ne "") {
print "Location: $gotit\n\n";
exit;
} else {
print "Error";
}
------------------------------
Date: 22 Apr 1999 20:01:37 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: DJGPP Port for DOS (Was Re: for (my $i;;) doesn't work like I think it should)
Message-Id: <7fnv71$2g5$49@newsread.f.de.uu.net>
Jonathan Stowe wrote:
>Yes 5.005.02 is the version that is currently available from the djgpp
>archives.
How bizarre. I paid a visit to CPAN. The only binary distribution there
is still 5.004. It does say, however:
> Starting from Perl 5.005 the MS-DOS support has been integrated to the
> Perl standard source code distribution.
So everybody has to build their own binary now? Even if they end up with
the SAME binary, all over the world?
Then I went to ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/ and
there it is: perl552b.zip (2448 kb). Oh, and the source code is there
too, if you want it: perl552s.zip, 3775 kb.
I thought CPAN was supposed to be the main distribution?
Bart.
------------------------------
Date: 22 Apr 1999 23:09:20 +0300
From: Jarkko Hietaniemi <jhi@alpha.hut.fi>
Subject: Re: DJGPP Port for DOS (Was Re: for (my $i;;) doesn't work like I think it should)
Message-Id: <oeen200ct8v.fsf@alpha.hut.fi>
bart.lateur@skynet.be (Bart Lateur) writes:
> Jonathan Stowe wrote:
>
> >Yes 5.005.02 is the version that is currently available from the djgpp
> >archives.
>
> How bizarre. I paid a visit to CPAN. The only binary distribution there
> is still 5.004. It does say, however:
>
> > Starting from Perl 5.005 the MS-DOS support has been integrated to the
> > Perl standard source code distribution.
>
> So everybody has to build their own binary now? Even if they end up with
> the SAME binary, all over the world?
>
> Then I went to ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/ and
> there it is: perl552b.zip (2448 kb). Oh, and the source code is there
> too, if you want it: perl552s.zip, 3775 kb.
>
> I thought CPAN was supposed to be the main distribution?
The djgpp-perl author hasn't yet uploaded 5.005_02 into CPAN.
I don't know why, but I'll ask right now.
> Bart.
--
$jhi++; # http://www.iki.fi/jhi/
# There is this special biologist word we use for 'stable'.
# It is 'dead'. -- Jack Cohen
------------------------------
Date: Thu, 22 Apr 1999 20:19:46 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: DJGPP Port for DOS (Was Re: for (my $i;;) doesn't work like I think it should)
Message-Id: <371f837e.539747@news.skynet.be>
I did NOT post this twice! You may check the headers:
>Message-ID: <371eca66.1759522@news.skynet.be>
which is normal, and
>Message-ID: <7fnv71$2g5$49@newsread.f.de.uu.net>
Say what? Some funny news server changed the message ID, and started
redistributing the post. How bizarre.
Bart.
------------------------------
Date: 22 Apr 1999 20:00:44 GMT
From: mike <mmione@tns-inc.com>
Subject: Extracting fields to scalar variables?
Message-Id: <7fnv5c$2g5$18@newsread.f.de.uu.net>
All,
I am looking for a way, using Perl, to perform line by line pattern matching
of fields from two different hosts files called "hosts.new" and
"hosts.current" - the purpose is to update the /etc/hosts file
(hosts.current) with newly added hosts from (hosts.new).
Both files were preformatted in the following manner:
hosts.new
field 1 field 2 field 3
line 1-> xxx.xxx.xxx.xxx <TAB> hostname
hosts.current
field 4 field 5 field 6
line 1-> xxx.xxx.xxx.xxx <TAB> hostname
What I need to do is perform a series of comparisons (line by line) testing
equality from field 1 and field 4, field 3 and field 6. There is more to it
but basically what I am looking for is a way to cut field 1,4,3,6 to a
pattern space, possibly a scalar variable and do a series of comparisons.
In a shell environment I would normally use awk '{print $1 or $2} but I have
not found this equivalent in Perl.
Can anyone help?
Mike-
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Thu, 22 Apr 1999 15:52:04 -0400
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: mike <mmione@tns-inc.com>
Subject: Re: Extracting fields to scalar variables?
Message-Id: <371F7DE4.9A84BC5B@giss.nasa.gov>
mike wrote:
>
> I am looking for a way, using Perl, to perform line by line pattern matching
> of fields from two different hosts files called "hosts.new" and
> "hosts.current" - the purpose is to update the /etc/hosts file
> (hosts.current) with newly added hosts from (hosts.new).
>
> Both files were preformatted in the following manner:
> hosts.new
> field 1 field 2 field 3
> line 1-> xxx.xxx.xxx.xxx <TAB> hostname
>
> hosts.current
> field 4 field 5 field 6
> line 1-> xxx.xxx.xxx.xxx <TAB> hostname
use IO::File;
my $fh_new = IO::File->new("< hosts.new") or die $!;
my $fh_cur = IO::File->new("< hosts.current") or die $!;
while (not $fh_new->eof) {
my @pair = ($fh_new->getline, $fh_cur->getline);
chomp @pair;
my @hashes = map { my %hash = ();
@hash{'xxx', 'hostname'} = split m/\t/, $_;
\%hash }
@pair;
use Data::Dumper;
print Dumper(\@hashes), "\n";
}
Jay Glascoe
--
"Don't be too proud of this technological
terror you've constructed."
-- Darth Vader
------------------------------
Date: 22 Apr 1999 20:01:27 GMT
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: FAQ 4.15: How do I find yesterday's date?
Message-Id: <7fnv6n$2g5$42@newsread.f.de.uu.net>
David Cassell <cassell@mail.cor.epa.gov> writes:
> Perhaps Larry Rosler would like to contribute his DST-safe version
> to the FAQ? I think he already sent a copy to Dan Grisinger's
> script archive...
I've got Russ Allbery's yesterday function.
http://moiraine.dimensional.com/~dgris/cgi-bin/pfr?func=yesterday&type=exact
dgris
--
Daniel Grisinger dgris@moiraine.dimensional.com
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'
------------------------------
Date: Thu, 22 Apr 1999 19:47:16 GMT
From: snowhare@long-lake.nihongo.org (Benjamin Franz)
Subject: Re: Generating a unique string for order number
Message-Id: <81LT2.3714$56.15727@typhoon-sf.pbi.net>
In article <371F5A57.FEB572C6@vpservices.com>,
Jeff Zucker <jeff@vpservices.com> wrote:
>Ronald J Kimball wrote:
>>
>> Greg McCann <gregm@well.com> wrote:
>>> $$ (process id) - May be good concatenated with time.
>>
>> Another bad idea. The numbers do repeat eventually. Process ids are
>> unique, but they have a temporary lifespan. Using them for
>> permanently unique numbers doesn't make sense.
>
>Yes, process ids repeat, but (except in science fiction and on horribly
>misconfigured machines) time doesn't. Two things may be submitted at
>the same time, but then their PID would be different. Two things may be
>submitted with the same PID, but then their time would be different. So
>concatenating time and process id would give a unique id wouldn't it?
Yes, with a caveat. If your machine is fast enough and busy enough to
cycle its complete PID space in less than one wall clock second and you
use a low resolution time source such as 'time', you could get the same
PID and time for two difference processes. But you are not likely to
encounter a situation like that in practice.
--
Benjamin Franz
------------------------------
Date: 22 Apr 1999 20:01:44 GMT
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: help! file upload from web
Message-Id: <7fnv78$2g5$56@newsread.f.de.uu.net>
[comp.lang.perl does not exist, and has been dead for years]
[newsgroup cross-post trimmed]
Chris Weiss wrote:
>
> hi all, i've been going at this all day and need help (code to follow). i'm
> sending a file up to the web, and the following is displayed (# denotes
> comments added here):
> [snip]
>
> what is happening is that when i write to the file which i am creating, i'm
> getting character added (\t, i suspect) that is fouling the file. the above
> example consists of a file with 9 lines, a single character on each (28
> bytes). when i save to my file, it becomes 37 bytes, with a blank line
> between each line. the temp file created by CGI does not have the extra
> values added, what i want. my two questions are these:
> [big snip]
Now let me see if I have this right. You're writing Perl code to
FTP a file from an NT box to another machine. Is that other
machine a unix box? And are you fixing the newlines?
In Win32, a newline is represented by a CR/LF combination, while in
unix it's a single character. So you have an 'extra' character at
the end of each line which is messing things up. And if your
file is now on a unix box, you can use 'od' to look at the file and
see what's going on. I think you'll find it's not a \t.
My suggestion is to use NET::FTP to do this, or else FTP it manually
making sure to transfer in ASCII mode rather than binary.
BTW, using the CGI.pm module gets you brownie points. But:
(1) use the -w flag on the shebang line.
(2) use strict; is A Good Thing.
(3) mkdir is looking for an octal mode [0777] instead of a decimal one.
(4) your way of checking the open() leads to extra indentation and
stuff. There are other approaches.
(5) the multiple print() statements can be done with a single here-doc.
(6) that's enough pestering for now... :-)
David
--
David Cassell, OAO
cassell@mail.cor.epa.gov
Senior Computing Specialist phone: (541)
754-4468
mathematical statistician fax: (541)
754-4716
------------------------------
Date: 22 Apr 1999 20:01:25 GMT
From: Eric Castle <ecastle@nuance.com>
Subject: Help: Problem capturing cntl-c signal in perl script
Message-Id: <7fnv6l$2g5$41@newsread.f.de.uu.net>
I'm trying to add a Control-C interrupt handler to my perl script. I've
looked at verious Perl books and web pages and have not found anything
that describes what I'm seeing.
My script runs a series of executables, some of which are servers and
need to run in the background and the rest are run in the foreground
using the open command.
So the script runs background processes by using the system command
like:
system("program >outfile 2>errfile &")
The script also runs foreground processes by using the open system call
like:
$write_to_child = new FileHandle;
if( open( $write_to_child, | "program >outfile 2>errfile") {
print $write_to_child +(join('\n', @input)) if @input;
close $write_to_child;
}
I send any stdin to the program being run if any input has been given.
So the script spends most of its time running the programs started by
using the open call like above.
I wanted to add a interrupt handler so that if the user presses Cntl-C
at the keyboard the script would then in the Cntl-C signal handler, stop
any background processes that have been started and then exit ( I keep
track of the background processes using ps and their pids and then issue
kill command and already have a subroutine that takes care of all that.
I want to call this subroutine from my signal handler.)
The problem seems to be that when the user hits Cntl-C, my signal
handler in the script doesn't see the Cntl-C, instead it appears the
program being run by the open call gets the signal instead. This causes
that program to exit, but then I don't end up in my signal handler at
all. So the script then goes and runs the next program. Each Cntl-C I
type just ends up killing the current program being run by the open
command. I've even seen the background process I had started earlier get
the Cntl-C's!!! I think in that case though, one of the client programs
is feeding the interrupt signal through to the server its connected to.
What I want to happen is for my script to catch the signal in the signal
handler FIRST, and then it would shut down any running servers and exit
(thereby hopefully ending the program being run by open). Is there some
way for my signal handler to get the Cntl-C signal first and not the
program being run by the open command? Why doesn't the signal go to my
signal handler first?
FYI my signal handler looks like:
sub handle_interrupt {
my $signame = shift;
print "\n received signal SIG$signame\n";
print "\n --- Control-C pressed, cleaning up before exit ------\n";
if( %bg_processes ) {
print "Shutting down background processes....\n";
&stop_all_servers;
}
exit;
}
And of course earlier in the script I have the line:
$SIG{INT} = \&handle_interrupt;
Thanks for any help.
Eric
------------------------------
Date: Thu, 22 Apr 1999 13:29:59 -0700
From: Eric Castle <ecastle@nuance.com>
Subject: Re: Help: Problem capturing cntl-c signal in perl script
Message-Id: <371F86C7.53731868@nuance.com>
Sorry for the multiple posting. I only posted once. Not sure why it is
showing up 3 times.
Eric
Eric Castle wrote:
>
> I'm trying to add a Control-C interrupt handler to my perl script. I've
> looked at verious Perl books and web pages and have not found anything
> that describes what I'm seeing.
>
> My script runs a series of executables, some of which are servers and
> need to run in the background and the rest are run in the foreground
> using the open command.
>
> So the script runs background processes by using the system command
> like:
>
> system("program >outfile 2>errfile &")
>
> The script also runs foreground processes by using the open system call
> like:
> $write_to_child = new FileHandle;
> if( open( $write_to_child, | "program >outfile 2>errfile") {
> print $write_to_child +(join('\n', @input)) if @input;
> close $write_to_child;
> }
>
> I send any stdin to the program being run if any input has been given.
>
> So the script spends most of its time running the programs started by
> using the open call like above.
>
> I wanted to add a interrupt handler so that if the user presses Cntl-C
> at the keyboard the script would then in the Cntl-C signal handler, stop
> any background processes that have been started and then exit ( I keep
> track of the background processes using ps and their pids and then issue
> kill command and already have a subroutine that takes care of all that.
> I want to call this subroutine from my signal handler.)
>
> The problem seems to be that when the user hits Cntl-C, my signal
> handler in the script doesn't see the Cntl-C, instead it appears the
> program being run by the open call gets the signal instead. This causes
> that program to exit, but then I don't end up in my signal handler at
> all. So the script then goes and runs the next program. Each Cntl-C I
> type just ends up killing the current program being run by the open
> command. I've even seen the background process I had started earlier get
> the Cntl-C's!!! I think in that case though, one of the client programs
> is feeding the interrupt signal through to the server its connected to.
>
> What I want to happen is for my script to catch the signal in the signal
> handler FIRST, and then it would shut down any running servers and exit
> (thereby hopefully ending the program being run by open). Is there some
> way for my signal handler to get the Cntl-C signal first and not the
> program being run by the open command? Why doesn't the signal go to my
> signal handler first?
>
> FYI my signal handler looks like:
>
> sub handle_interrupt {
> my $signame = shift;
> print "\n received signal SIG$signame\n";
> print "\n --- Control-C pressed, cleaning up before exit ------\n";
> if( %bg_processes ) {
> print "Shutting down background processes....\n";
> &stop_all_servers;
> }
> exit;
> }
> And of course earlier in the script I have the line:
> $SIG{INT} = \&handle_interrupt;
>
> Thanks for any help.
>
> Eric
------------------------------
Date: 22 Apr 1999 20:00:41 GMT
From: mikl_paris@my-dejanews.com
Subject: how can i extract an attach file in a mail ?
Message-Id: <7fnv59$2g5$16@newsread.f.de.uu.net>
use Mail::Sender;
($base=$0)=~ s/[A-z0-9,\.,\-]*$//;
chdir $base;
$sender = new Mail::Sender
{smtp => 'xxxx.thomson-csf.com', from => 'xxx@xxx.thomson-csf.com'};
$sender->MailFile({to => 'xxx.xxx@tfm.thomson-csf.com',
subject => 'test',
msg => "it's a test",
file => 'c:/mikl/mikl/resultat_mois.txt'});
print "mail sent";
i want to extract this file in order to move in a directory
thanks
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 22 Apr 1999 20:00:39 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: how do you pass hashes to functions?
Message-Id: <7fnv57$2g5$14@newsread.f.de.uu.net>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
"Dunn One" <obinani@popd.ix.netcom.com> writes:
:I've been trying this and it just doesn't work. Can anyone please help?
I believe that you'll find that if you were to bother to read the fine
perlsub manpage included with every perl distribution, that your answer
is there waiting for you on your very own system.
--tom
--
Pretty printers mechanically produce pretty output that accentuates
irrelevant detail in the program, which is as sensible as putting all
the prepositions in English text in bold font. --Rob Pike
------------------------------
Date: 22 Apr 1999 20:01:38 GMT
From: qinqiang sun <qsun@kitco.ca>
Subject: How to read a NT mapped driver from CGI ?
Message-Id: <7fnv72$2g5$51@newsread.f.de.uu.net>
Hello, Everybody
I need to reading file from a mapped driver on our NT network in my
CGI (Perl/C++) script. The CGI script read files from a mapped drives
on windows95 machines successfully but failed to do the same thing from
any driver on any of my NT machines. The script did do the job from dos
window command. Does anybody know the reason ? Please help!
Thanks in advanced!
Jinbai
------------------------------
Date: 22 Apr 1999 20:38:12 GMT
From: phukit@enteract.com
Subject: Re: Illegal seek (this makes no sense to me =)
Message-Id: <7fo1bk$1em$1@eve.enteract.com>
Attitude aside, thank you. =) This helped me get the right answer. I was
looking in the camel book, but I evidently glossed over the relevant part.
Eric The Read <emschwar@rmi.net> wrote:
> But that's the wrong place to look. Haven't you read the documentation
> that comes with perl?
> perldoc perlipc, "Using open() for IPC"
------------------------------
Date: 22 Apr 1999 20:00:42 GMT
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Is there a shorter way?
Message-Id: <7fnv5a$2g5$17@newsread.f.de.uu.net>
[Posted and a courtesy copy mailed.]
In article <x7aew0d0mh.fsf@home.sysarch.com> on 22 Apr 1999 13:29:58 -
0400, Uri Guttman <uri@sysarch.com> says...
...
> echo '' | perl -pe '$_=sprintf"%-6s",$ENV{USER};y/ /x/'
That's the second answer with 'y'. I love to see 'y' coming into its
own compared with 'tr' -- saving one character!
Just Another sed Hacker (to whom 'y' seems as natural as anything, and
more natural than 'tr' :-).
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 22 Apr 1999 13:06:09 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Is there a shorter way?
Message-Id: <m1yajk4dzi.fsf@halfdome.holdit.com>
>>>>> "Larry" == Larry Rosler <lr@hpl.hp.com> writes:
Larry> [Posted and a courtesy copy mailed.]
Larry> In article <x7aew0d0mh.fsf@home.sysarch.com> on 22 Apr 1999 13:29:58 -
Larry> 0400, Uri Guttman <uri@sysarch.com> says...
Larry> ...
>> echo '' | perl -pe '$_=sprintf"%-6s",$ENV{USER};y/ /x/'
Larry> That's the second answer with 'y'. I love to see 'y' coming into its
Larry> own compared with 'tr' -- saving one character!
Larry> Just Another sed Hacker (to whom 'y' seems as natural as anything, and
Larry> more natural than 'tr' :-).
Fails, though, for any internal spaces in $ENV{whatever}. And that
was the original request, if I recall correctly.
print "Just another Perl hacker",
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: 22 Apr 1999 16:38:17 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Is there a shorter way?
Message-Id: <x74sm8crwm.fsf@home.sysarch.com>
>>>>> "RLS" == Randal L Schwartz <merlyn@stonehenge.com> writes:
>>>>> "Larry" == Larry Rosler <lr@hpl.hp.com> writes:
Larry> [Posted and a courtesy copy mailed.]
Larry> In article <x7aew0d0mh.fsf@home.sysarch.com> on 22 Apr 1999 13:29:58 -
Larry> 0400, Uri Guttman <uri@sysarch.com> says...
Larry> ...
>>> echo '' | perl -pe '$_=sprintf"%-6s",$ENV{USER};y/ /x/'
RLS> Fails, though, for any internal spaces in $ENV{whatever}. And that
RLS> was the original request, if I recall correctly.
if you read my post and not larry's followup you would have seen my
comments on that. not many user's have spaces in their names. it is a
cheat but who cares, it was a dumb shortest code contest and i sort
of won!
:-)
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: 22 Apr 1999 20:01:29 GMT
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: newbie with a "howto" question
Message-Id: <7fnv6p$2g5$43@newsread.f.de.uu.net>
derose@my-dejanews.com wrote:
>
> Hello,
>
> I'm new at Perl, and don't really have the patience's to find the answers in
> my books, so I thought I would ask some experts.
And how is it that your time is more valuable than an entire newsgroup
of experts? This doesn't sound very polite. Patience is a virtue,
especially for a programmer. When you hear that LArry Wall described
the three great virtues of a programmer as Laziness, Impatience, and
Hubris, be aware that this is not what he had in mind.
Actually, your questions have basically been answered in the Perl
documentation that cmae with your install. If you don't have the
time to read all 1200 pages of docs, learn to use the really nice
toys that come with the docs. Try the following commands, and
see what niftiness awaits you:
perldoc perldoc
perldoc perl
perldoc -q uniq [or perldoc -q unique]
perldoc -f split
> I have two questions really
> 1. Is there a comparable command or module to unix's uniq? I want to sort and
> uniq a simple text file. I've figured out how to sort it in Perl, but not how
> to uniq it. If I were to do this in shell I would say something like:
> cat $file1 | sort | uniq > $outfile
By now you have tried `perldoc -q uniq' and read the FAQ and found
that it is easy to do in Perl using a hash.
> 2. Is there a module or function that will parse a line in a text file? I
> have a file with four individual columns, and I want to read each line on at
> a time and have each word placed in an individual variable. If I were to do
> this in shell, I would have used awk to parse the lines.
By now you have tried `perldoc -f split' and found that there is at
least one way to do this in Perl. But there are lots of ways.
Read the perlrun manpage and find out about the command line options.
So you could try something like
perl -wane 'print pop(@F), "\n";' filename
and see how Perl does autosplit.
Or you could use the a2p program and see what sort of code you get
if you convert an awk script to a Perl program.
TMTOWTDI.
> If any one could point me in the correct direction, I would appreciate it.
>
> Thank you.
You're welcome.
And remember that in general posters to this newsgroup are expected
to have done their homework first, or else one of the `experts'
may flame them instead of spoon-feeding them. :-)
HTH,
David
--
David Cassell, OAO
cassell@mail.cor.epa.gov
Senior Computing Specialist phone: (541)
754-4468
mathematical statistician fax: (541)
754-4716
------------------------------
Date: 22 Apr 1999 20:00:47 GMT
From: Michael Cameron <Michael.Cameron@no.spam.technologist.com>
To: Pieter Brouwer <p.brouwer@prevalent.nl>
Subject: Re: Please, HELP with uninitialized value error
Message-Id: <7fnv5f$2g5$20@newsread.f.de.uu.net>
Pieter Brouwer wrote:
> open DEFILE, "$file" || do {
> print OUTFILE "kan file $file niet openen; skipping\n";
> return;
> };
>
I would suggest the following instead:
unless (open DEFILE, "$file") {
print OUTFILE "kan file $file niet openen; skipping\n";
return;
}
I think you were trying to open a file named ($file or the value of the do
block) which I suspect is not what you intended.
As for the rest I am still not sure what you are trying to achieve.
HTH
Michael
------------------------------
Date: Thu, 22 Apr 1999 16:50:05 -0400
From: sjose@mulmax.com (Stephane Jose)
Subject: postgreSQL and Perl
Message-Id: <sjose-2204991650050001@10.10.10.4>
I am looking for information about how to interface cgi scripts programmed
in Perl with PostgreSQL
I have an intermediate to advanced knowledge of cgi scripting in Perl and
no knowledge of SQL. Where should I start?
Any advice will be greatly appreciated.
Stephane
------------------------------
Date: 22 Apr 1999 20:01:34 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Reading C binary data from disk
Message-Id: <7fnv6u$2g5$46@newsread.f.de.uu.net>
>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:
LR> I wonder if there isn't a design flaw in the read() or sysread()
LR> functions implemented for the Evil Empire. Analogous to C's fread,
LR> shouldn't they automatically give back all the bytes as they exist on
LR> the external medium, instead of converting "\015\012" pairs to "\n"? An
LR> implicit binmode(), in effect, to help eliminate these recurrent bugs.
LR> The line-at-a-time input operators <> and readline() wouldn't be
LR> affected by this change.
i am no expert on the evil os (thank god!), but i believe perl's binmode
calls a winblows system call to affect its conversion of cr/lf to
\n. this is needed for c programs too as c uses the \n convention. so
having perl's read and sysread do an implicit bin mode makes little
sense. they don't know what the programmer is doing (and if the
programmer is using winblows, he doesn't know what he is doing either
:-), so they can't always turn on binmode.
just trying to help out those poor POB's,
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: 22 Apr 1999 20:01:38 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Reading C binary data from disk
Message-Id: <7fnv72$2g5$50@newsread.f.de.uu.net>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
lr@hpl.hp.com (Larry Rosler) writes:
:I wonder if there isn't a design flaw in the read() or sysread()
:functions implemented for the Evil Empire. Analogous to C's fread,
:shouldn't they automatically give back all the bytes as they exist on
:the external medium, instead of converting "\015\012" pairs to "\n"?
Yes, it's a bug, but it's a bug from the Evil One in their C code, and
one apparently we're not allowed to fix it. It's nestled deep down
in the bowels of their hideous run-time system.
I, too, long believed as you believed, so when the light of truth
finally shone upon their profound iniquity, a non-trivail clean-up
job was required to rescue the random documentation (like peropentut),
as well as the ensuing mess on my hardwood floors.
That is not dead which can fternal lie,
and in strange fons, even CP/M may die.
--Abdulw Al-Lhazard
--tom
--
When the dinosaurs are mating, climb a tree. --Steve Johnson
------------------------------
Date: Fri, 23 Apr 1999 08:25:33 +1200
From: Me <aghaeim@genesis.co.nz>
Subject: Reading files
Message-Id: <371F85BD.789FC515@genesis.co.nz>
Hi;
I'm running perl-cgi scripts on one machine and I want to read some
files from another machine ( needs username/password) is there any easy
way to do that? Thanks.
------------------------------
Date: Thu, 22 Apr 1999 15:20:07 -0500
From: "Tim Armbruster" <t-armbruster@ti.com>
Subject: Re: Reading in password from <STDIN>
Message-Id: <BzLT2.10$D21.1155@dfw-service1.ext.raytheon.com>
Save this with a *.html extension, and open it in your browser:
<HTML>
<head>
</head>
<body>
<form>
<input type=password></input>
</form>
</body>
</HTML>
Micah G. Cook wrote in message <371F9321.672C@ic.delcoelect.com>...
>I have looked through several man pages and dont see
>anything in my only "Learning Perl" book.
>I want to read in a users password from <STDIN> but
>want to display ****'s while they type it in.
>Right now it displays what they type. <-Bad
>
>Apologies if this has been posted before, where do the
>post go after they runoff? Is there an archive of post
>somewhere? -Micah
>
>I need some more books.
------------------------------
Date: Thu, 22 Apr 1999 16:56:33 -0400
From: Tony Labbiento <tonylabb@infonline.net>
Subject: Re: Reading in password from <STDIN>
Message-Id: <371F8D01.808A50ED@infonline.net>
If you are on a UNIX system, you can use this to hide the password.
print "Enter Password: ";
system('stty', '-echo');
chop($pwd = <STDIN>);
system('stty', 'echo');
print "\nYour password is: $pwd\n";
"Micah G. Cook" wrote:
>
> I have looked through several man pages and dont see
> anything in my only "Learning Perl" book.
> I want to read in a users password from <STDIN> but
> want to display ****'s while they type it in.
> Right now it displays what they type. <-Bad
>
> Apologies if this has been posted before, where do the
> post go after they runoff? Is there an archive of post
> somewhere? -Micah
>
> I need some more books.
--
****************************************
* Tony Labbiento *
* Infinity Online, Inc. *
****************************************
------------------------------
Date: 22 Apr 1999 16:04:33 -0400
From: Joe Marzot <gmarzot@baynetworks.com>
Subject: Re: SNMP
Message-Id: <pdg15smnfy.fsf@baynetworks.com>
"Philip Smeuninx" <philip.smeuninx@be.uunet.net> writes:
> Hello,
>
> How can I send SNMPGETS in perl???
>
> Philip
there are a couple SNMP packages available on CPAN
SNMP (also ftp://ftp-east.baynetworks.com/netman/snmp/perl5/SNMP-1.8.tar.gz)
Net::SNMP
-GSM
>
>
--
G.S. Marzot email: gmarzot@nortelnetworks.com
Nortel Networks voice: (978)916-3990
600 Tech Park M/S BL60-101 pager: (800)409-6080 (4096080@skytel.com)
Billerica, MA 01821 fax: (978)670-8145
------------------------------
Date: 22 Apr 1999 20:01:30 GMT
From: kaz@ashi.FootPrints.net (Kaz Kylheku)
Subject: Re: The Future of Tk?
Message-Id: <7fnv6q$2g5$44@newsread.f.de.uu.net>
On Thu, 22 Apr 1999 18:01:27 GMT, Barry Margolin <barmar@bbnplanet.com> wrote:
>In article <4fv$ECA+JyH3EwbN@jessikat.demon.co.uk>,
>Robin Becker <robin@jessikat.demon.co.uk> wrote:
>>I take this completely differently; least astonishment for me is if
>>program X looks and behaves the same way no matter what keyboard, mouse
>>and screen I'm using. As a 'user' of the program X it shouldn't matter
>>what OS/WM is executing the code. I certainly don't want vi or emacs to
>>be different on the mac why should I treat word or excel differently?
>
>I would be very surprised if Netscape on the Macintosh presented a
>Windows-like user interface, rather than adopting the standard Macintosh
I'd be very surprised if even 10% of, say, comp.lang.c gave a damn. The pitiful
dumbfuck who started this thread made a severe mistake in constructing the
Newsgroups: header line, the moment he put in the first comma.
I am setting Followup-to: to comp.lang.tcl.
------------------------------
Date: 22 Apr 1999 20:00:48 GMT
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: To trim right blanks from a field.
Message-Id: <7fnv5g$2g5$21@newsread.f.de.uu.net>
In article <371F6508.267D9F79@mail.cor.epa.gov> on Thu, 22 Apr 1999
11:06:00 -0700, David Cassell <cassell@mail.cor.epa.gov> says...
> kalash4334@my-dejanews.com wrote:
> > I am looking for a function to trim the right spaces from a field of one line.
...
> > Can someone suggest a solution.
>
> Yes. tr/// will do this for you very nicely. This could also be
> done using a regex, but that will likely be a lot slower than the
> tr solution. tr works like the unix tr(1), only better.
Well, finally. You have resolved the debate about whether 'tr' stands
for 'translate' or 'transliterate'. None of the above. It stands for
'trim'.
:-)
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 22 Apr 1999 21:14:43 +0000
From: Jason Holland <jason.holland@dial.pipex.com>
Subject: Re: Unix files in MacPerl
Message-Id: <371F9143.ED49585B@dial.pipex.com>
To all the perlers who answered my simple question, thanks!
A couple of points though, the reason why I need to do the shuffle is
because I regularly work on a Linux box at home, put the stuff on a tar
floppy and bring it to work, un-tar it on the Mac, work a little in
BBedit and then tar it up to take back home.
I *suppose* I could use e-mail, but my company does not allow
non-essential staff such luxuries as internet access. Incidentally, I
maintain my company's web site using telepathy; I believe I am the only
webmaster in the world to upload his files that way.
Thanks again, looks like I'll have to put aside some of the laziness and
actually write a script to do it for me!
Bye!
--
Jason Holland - < It's not my fault! >
email: jason.holland@dial.pipex.com
web: http://dspace.dial.pipex.com/jason.holland/
------------------------------
Date: 22 Apr 1999 20:00:45 GMT
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Verifying text in a string
Message-Id: <7fnv5d$2g5$19@newsread.f.de.uu.net>
[posted and cc'd]
Larry Rosler wrote:
>
> my $Count0a = sub { my $x = () = $rand =~ /[^A-Za-z0-9]/g };
you might find this one interesting:
my $Count0b = sub { my $x = map /[^A-Za-z0-9]/g, $rand };
I'm not sure why, but supplying a list context via map
seems to be more efficient than the "() =" trick.
> I am really surprised that for the 'look at every character but don't do
> anything' cases (the ones with the '1' in their names), the regex is
> noticeably faster than the tr(): about 0.5 sec compared to 0.8 sec.
on my box, I get:
Bool0: 0 wallclock secs ( 0.01 usr + 0.00 sys = 0.01 CPU)
(warning: too few iterations for a reliable count)
Bool1: 1 wallclock secs ( 0.84 usr + 0.00 sys = 0.84 CPU)
Count0: 42 wallclock secs (41.10 usr + 0.00 sys = 41.10 CPU)
Count0a: 87 wallclock secs (83.47 usr + 0.01 sys = 83.48 CPU)
Count0b: 68 wallclock secs (65.71 usr + 0.01 sys = 65.72 CPU)
Count1: 1 wallclock secs ( 0.84 usr + 0.00 sys = 0.84 CPU)
Count1a: 2 wallclock secs ( 0.82 usr + 0.00 sys = 0.82 CPU)
Count1b: 1 wallclock secs ( 0.83 usr + 0.00 sys = 0.83 CPU)
Del0: 19 wallclock secs (17.61 usr + 0.01 sys = 17.62 CPU)
Del1: 1 wallclock secs ( 0.85 usr + 0.00 sys = 0.85 CPU)
Tr0: 1 wallclock secs ( 0.78 usr + 0.00 sys = 0.78 CPU)
Tr0_d: 1 wallclock secs ( 0.70 usr + 0.00 sys = 0.70 CPU)
Tr1: 0 wallclock secs ( 0.64 usr + 0.00 sys = 0.64 CPU)
Tr1_d: 1 wallclock secs ( 0.66 usr + 0.00 sys = 0.66 CPU)
thus showing that the speed of tr// is system dependent, ;^)
Jay Glascoe
------------------------------
Date: 12 Dec 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 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 5458
**************************************