[10972] in Perl-Users-Digest
Perl-Users Digest, Issue: 4572 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 7 14:27:16 1999
Date: Thu, 7 Jan 99 11:00:20 -0800
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, 7 Jan 1999 Volume: 8 Number: 4572
Today's topics:
Re: $a = `$cmd` repost <shum@cig.mot.com>
[OT] How to use Netscape (Was: Re: Deleting Messages) <ludlow@us.ibm.com>
ActivePerl & IIS4.0 Permissions <ritche@san.rr.com>
Re: Arrays from File Handles Problem <estabroo@ispn.com>
Case Modification <andy@xsite.net>
Re: chmod in perl (brian d foy)
Re: chmod in perl (Greg Ward)
copying complex hashes (Lori Flynn )
Re: Deleting Messages <mtg82814@melsud.res.ray.com>
Re: Help - cookies; check if a browser is set to accept <dales@enhanced-performance.com>
Re: Help - cookies; check if a browser is set to accept <dgris@moiraine.dimensional.com>
Re: How do I create a unique (reproducible) identifier? <callahan@pmel.noaa.gov>
How do I split this...? (Rocky)
Re: How do I split this...? <ludlow@us.ibm.com>
How to send a snmp trap <stefan.hoenes@rwg.de>
HP-UX Install problem (J. T. Greenaway)
Re: If Larry Wall's listening out there.... <tripp.lilley@perspex.com>
Re: If Larry Wall's listening out there.... <tchrist@mox.perl.com>
Not Quite FAQ: perl for Win32 w/out console <tripp.lilley@perspex.com>
Passing hashes to a sub <jwarner@tivoli.com>
Re: Passing hashes to a sub <che@debian.org>
Re: Passing hashes to a sub (Matthew Bafford)
Perl Cookbook example on NT <stupakov@slac.stanford.edu>
Q on search & replace in larger strings <tavi367@ibm.net>
Re: Q on search & replace in larger strings <uri@home.sysarch.com>
Re: rsh and process management q <spicano@ptdcs2.intel.com>
Win32::net User Full Name? <soccer@all-soccer.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 07 Jan 1999 11:57:39 -0600
From: Edmond Shum <shum@cig.mot.com>
Subject: Re: $a = `$cmd` repost
Message-Id: <3694F593.D1159D1E@cig.mot.com>
Actually, I checked with perl5.004 and the problem still exists.
The perl4.036 was just a test version for me to do the change in
the source code.
The following is the segment of util.c in perl5.004:
1766 while ((pid = (doexec?vfork():fork())) < 0) {
1767 if (errno != EAGAIN) {
1768 close(p[this]);
1769 if (!doexec)
1770 croak("Can't fork");
1771 return Nullfp;
1772 }
I added:
close(p[that]) just under close(p[this])
in the similar segment of perl4.036.
p[this] and p[that] are both end of pipe which the function call
created.
I guess it would work for me in perl5.004, however, I am not going
to mess things up yet :)
--
Edmond Shum System and Network Administration
Motorola CIG email: shum@cig.mot.com
Arlington Heights, IL phone: 847-632-6702
------------------------------
Date: Thu, 07 Jan 1999 11:26:57 -0600
From: James Ludlow <ludlow@us.ibm.com>
Subject: [OT] How to use Netscape (Was: Re: Deleting Messages)
Message-Id: <3694EE61.CA6C18AE@us.ibm.com>
Mike Godfrey wrote:
> I'm kind of new to this whole newsgroup thing. Although it's been
> very helpful. I just can't seem to figure out how to delete messages
> I'v already read, or don't want to read. There are overseven hundred
> messages. I'm using Netscape 4.05 for Unix (SunOS).
There's nothing wrong with being new to newsgroups. But, one thing
you'll find out is that posting off-topic messages like this is
generally frowned upon.
Anyway, what you're trying to do has nothing to do with news (or perl
for that matter). You can't actually "delete" the messages. What you
can do, however, is set Netscape to not show you previously read
messages. When you're in a window displaying the threads of a
particular newsgroup, click the following...
View->Messages->New
--
James Ludlow (ludlow@us.ibm.com)
(Any opinions expressed are my own, not necessarily those of IBM)
------------------------------
Date: Thu, 7 Jan 1999 10:26:45 -0800
From: "Ritche Macalaguim" <ritche@san.rr.com>
Subject: ActivePerl & IIS4.0 Permissions
Message-Id: <w17l2.6064$XY6.131944@news.san.rr.com>
I have ActivePerl Build 509 running on NT4 IIS4. Everyone on the web is
being prompted for a username and password whenever a CGI script is
accessed. How do I remove this permissions prompt so that scripts will
execute for everyone?
Please help...
Ritche
ritche@san.rr.com
------------------------------
Date: Thu, 07 Jan 1999 12:16:29 -0600
From: Eric Estabrooks <estabroo@ispn.com>
Subject: Re: Arrays from File Handles Problem
Message-Id: <3694F9FD.918A304B@ispn.com>
Artoo wrote:
>
> Hi All
>
> When I make an array from a File Handle and then print something if the
> member of the array is not blank, it will still print it even if the line in
> the File Handle is blank.
>
> EG:
>
> open(FILE,"$path/file");
> @file=<FILE>;
> close(FILE);
>
> if ($file[1] ne ''){
> print "exists";
> }
>
> if you do this from a normal array then it works, but if the second line of
> the file is empty then it still prints it because it is reading a return in
> the file I imagine. How can I make it only print it is there is really
> something on the line?
>
> Thanks for any help
> Artoo
try
if (($file[1] ne '\n') && ($file[1] ne '\r\n')) then
print "exists\n";
}
or chomp the line before you if check for blank
Eric
estabroo@ispn.com
------------------------------
Date: Thu, 07 Jan 1999 12:30:55 -0600
From: Andy Biegel <andy@xsite.net>
Subject: Case Modification
Message-Id: <3694FD5F.8A789676@xsite.net>
Pardon me if this is too obvious...
How can I go about taking a string (for example):
"THIS IS A TEST"
and modifying it so that only the first letter of each word is
capitalized? Any help would be appreciated.
Andy B
andy@xsite.net
------------------------------
Date: Thu, 07 Jan 1999 12:15:54 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: chmod in perl
Message-Id: <comdog-ya02408000R0701991215540001@news.panix.com>
In article <772mir$bhk$1@plug.news.pipex.net>, "Artoo" <r2-d2@REMOVEbigfoot.com> posted:
> How can you chmod a directory that already exists from within perl? Also
> how do you chmod a file (the same way??)
perhaps you should familiarize yourself with the perlfunc manpage
or chapter 3 of the Camel. you'd get answers much quicker this
way.
perldoc -f chmod
--
brian d foy
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
------------------------------
Date: 7 Jan 1999 17:31:47 GMT
From: gward@thrak.cnri.reston.va.us (Greg Ward)
Subject: Re: chmod in perl
Message-Id: <772r23$708$1@news0-alterdial.uu.net>
Artoo <r2-d2@REMOVEbigfoot.com> wrote:
> How can you chmod a directory that already exists from within perl? Also
> how do you chmod a file (the same way??)
By using Perl's chmod function, of course! 'perldoc chmod' for details.
Greg
--
Greg Ward - software developer gward@cnri.reston.va.us
Corporation for National Research Initiatives
1895 Preston White Drive voice: +1-703-620-8990 x287
Reston, Virginia, USA 20191-5434 fax: +1-703-620-0913
------------------------------
Date: 7 Jan 1999 18:49:22 GMT
From: lori@cse.ucsc.edu (Lori Flynn )
Subject: copying complex hashes
Message-Id: <772vji$o40@darkstar.ucsc.edu>
Hi everyone,
I have some basic confusions about hashes that I'm hoping some of you may be able to clear
up.
1) The following code prints the value from the complex hash correctly in the first print
statement, and doesn't print any value at all in the second. Does anyone know how I can
correctly copy this hash?
print("value is $Hash->{sourceDestPairs}{first} \n");
%copiedInfo = ();
%copiedInfo = $Hash->{sourceDestPairs};
print("value is $copiedInfo->{sourceDestPairs}{first} \n");
2)I'm confused about the difference between using the arrow (as in above example) to
reference a hash field and other times in my Perl book where fields are referenced without
an arrow (ie something like $Hash{sourceDestPairs} ). Does this have something to do with
pointers?
Thanks in advance for all help!
-Lori
------------------------------
Date: Thu, 07 Jan 1999 11:32:32 -0500
From: Mike Godfrey <mtg82814@melsud.res.ray.com>
Subject: Re: Deleting Messages
Message-Id: <3694E1A0.2D50549C@melsud.res.ray.com>
Mike Godfrey wrote:
> Hi,
> I'm kind of new to this whole newsgroup thing. Although it's been
> very helpful. I just can't seem to figure out how to delete messages
> I'v already read, or don't want to read. There are overseven hundred
> messages. I'm using Netscape 4.05 for Unix (SunOS).
>
> Thanks,
>
> Mike Godfrey
------------------------------
Date: Thu, 07 Jan 1999 10:25:42 -0800
From: Dale Sutcliffe <dales@enhanced-performance.com>
Subject: Re: Help - cookies; check if a browser is set to accept cookies
Message-Id: <3694FC25.FD4ADAFB@enhanced-performance.com>
Actually, I was talking about perl. Thank you very much.
------------------------------
Date: 07 Jan 1999 11:34:20 -0700
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: Help - cookies; check if a browser is set to accept cookies
Message-Id: <m3iuejaq4z.fsf@moiraine.dimensional.com>
Dale Sutcliffe <dales@enhanced-performance.com> writes:
> Actually, I was talking about perl. Thank you very much.
Cookies and browsers have absolutely nothing to do with perl.
Thank you very much.
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, 07 Jan 1999 10:03:58 -0800
From: Jonathan Callahan <callahan@pmel.noaa.gov>
Subject: Re: How do I create a unique (reproducible) identifier?
Message-Id: <3694F70C.8E94F18@pmel.noaa.gov>
Thank you Staffan and all the rest for your input. I think I'm going to end up just tying the values together as I have been doing and as
Staffan suggested. For clarification I'll describe the types of name=value pairs I'm dealing with. Here are all the query parameters from
CGI.pm
output=gif
x_lo=70.0
y_lo=58.0S
t_hi=undefined
z_lo=undefined
variable=sst
dataset=coads_climatology
x_hi=320.0
y_hi=58.0N
z_hi=undefined
view=XY
t_lo=15-jan
My cgi script creates a graphic of sea surface temperature (sst) from the dataset described, over the range requested. Because generating the
graphic is time-consuming, I cache the results and want to be able to find them when the next person requests the same result. So my filenames
look like this:
coads_climatology_sst_0.0:360.0_-90:90.0_15-jan_gif.gif
But we're always adding more options so the file name will continue to grow. And there is no guarantee that we'll always have the same datasets
and variables, so converting the name into a selection index won't work. So I think I'll just stick with long filenames until it's wothwhile
setting up a database of some sort.
Thanks again.
-- Jon
Staffan Liljas wrote:
> In a private post to me, Jeffrey R. Drumm wrote:
>
> >>But how does this work if two processes access the same file at the >>same time (as might _very_ well be the case over the internet). Maybe
> >>this was a stupid question.
>
> >Poorly, unless you open the dbm read-only or take the (necessary)
> >precaution of locking it when opening with read/write access.
>
> So I guess the question remains... But then again the question is: What
> did you really want to do, Jonathan? My guess is that you want to create
> a file from something someone posted, and be able to get that
> information back from some script when someone sets the same values from
> some form.
>
> Now, honestly, there is no way to do this. X bytes of random information
> cannot be represented in less than X bytes. But then again - your
> information is hardly random. But how are we to be able to make
> something smart out of it, if we don't know how your input looks? Then
> it is all random strings to us.
>
> One thing i can tell you is: if all the name/value pairs come in the
> same order all the time, try removing the names.
> "field1=value1&field2=value2" could be written shorter "value1&value2".
> If the fields have fixed width, you can ommit the '&'. If you have a
> field that doesn't contain vital info, remove its value. If you have a
> long field, try using just a part of it.
>
> If your fields don't always come in the same order -- make sure they do.
>
> If you want to be really smart, and you only have character values, you
> could reduce the size of each caracter to 5 bits, and pack them tighter
> in that way. If it's all numbers, you can at least do better than ascii.
>
> I think this is all I can think of right now...
>
> Staffan
>
> PS: This problem reminds me of a story generating script. Is that what
> it is? You choose from a set of values what you would like should happen
> next, and if you don't like your choices, you add another choice...
> Anyone should be able to "walk through" the story in any way, and at any
> point they should be able to add anything... If this is the case, why
> not simply use numbers for each choice? This is also a good solution if
> every value in the form in the case above has a limited domain. Define
> the domain, use pulldown lists with values set to numbers, and then you
> get a rather short filename.
------------------------------
Date: 7 Jan 1999 17:51:24 GMT
From: rocky@blues.jpj.net (Rocky)
Subject: How do I split this...?
Message-Id: <772s6s$d6a$1@news.monad.net>
Perl gurus:
I am reading in a config file, of the format:
blocka|blockb|blockc can be long
where c is of indeterminate length... I am splitting it thus so far:
while (<FILE>) {
chop;
($foo, $bar, @baz) = split /\|/;
blocka and blockb always will be one word, while blockc's data will be
usually 3 to 5 words, separated by a space. I need the stuff in blockc
to be put into array @services, separated by commas, just as if I had
done this:
@baz=(firstthing,secondthing,thirdthing);
How can I do this? I'm stumped!
Thanks in advance,
Rocky.
--
I sync, therefore I nm.
<rocky@gnu.org>
------------------------------
Date: Thu, 07 Jan 1999 12:21:44 -0600
From: James Ludlow <ludlow@us.ibm.com>
Subject: Re: How do I split this...?
Message-Id: <3694FB38.25CDB5F7@us.ibm.com>
Rocky wrote:
> Perl gurus:
>
> I am reading in a config file, of the format:
>
> blocka|blockb|blockc can be long
>
> where c is of indeterminate length... I am splitting it thus so far:
>
> while (<FILE>) {
> chop;
> ($foo, $bar, @baz) = split /\|/;
>
> blocka and blockb always will be one word, while blockc's data will be
> usually 3 to 5 words, separated by a space. I need the stuff in blockc
> to be put into array @services, separated by commas, just as if I had
> done this:
>
> @baz=(firstthing,secondthing,thirdthing);
Just do it in two steps rather than 1.
($foo, $bar, $baz) = split /\|/;
@baz = split /\s+/, $baz;
Or, if you really want to do it in one step, you use something like
this...
($foo, $bar, @baz) = split /\s+|\|/;
In general, though, you're probably safer doing it in two steps. It's
easier to see what's going on in that case.
--
James Ludlow (ludlow@us.ibm.com)
(Any opinions expressed are my own, not necessarily those of IBM)
------------------------------
Date: Thu, 07 Jan 1999 18:38:08 +0100
From: Stefan Hoenes <stefan.hoenes@rwg.de>
Subject: How to send a snmp trap
Message-Id: <3694F100.4700@rwg.de>
Hy,
I want to send a snmp trap to a management station
What is the easiest way to do this ?
mfg Stefan Hoenes
------------------------------
Date: Thu, 07 Jan 1999 18:04:15 GMT
From: jgreenaway@zetron.com (J. T. Greenaway)
Subject: HP-UX Install problem
Message-Id: <3694f383.176418771@192.1.1.76>
I'm having trouble installing 5.004_04 under HP-UX. I've tried the
binary from the HP-UX Porting and Archive Center
(http://hpux.cae.wisc.edu/hppd/hpux/) as well as running Configure
from the source at the same site.
When running the "make depend" at the end of the script, I get a long
series of:
Finding dependencies for miniperlmain.o.
/usr/include/math.h: 366: too much defining - use -H option
/usr/include/math.h: 367: too much defining - use -H option
/usr/include/math.h: 368: too much defining - use -H option
/usr/include/math.h: 369: too much defining - use -H option
/usr/include/math.h: 370: too much defining - use -H option
./perl.h: 1254: too much defining - use -H option
./perl.h: 1259: too much defining - use -H option
./perl.h: 1260: too much defining - use -H option
./perl.h: 1265: too much defining - use -H option
./perl.h: 1266: too much defining - use -H option
./perl.h: 1278: too much defining - use -H option
./perl.h: 1279: too much defining - use -H option
./perl.h: 1280: too much defining - use -H option
./perl.h: 1288: too much defining - use -H option
./perl.h: 1580: no space
(for various .o names)
The output of myconfig is:
Summary of my perl5 (5.0 patchlevel 4 subversion 4) configuration:
Platform:
osname=hpux, osvers=9, archname=PA-RISC1.1
uname='hp-ux h50 a.09.04 d 9000887 1709675121 64-user license '
hint=recommended, useposix=true, d_sigaction=define
bincompat3=y useperlio=undef d_sfio=undef
Compiler:
cc='cc', optimize='-O', gccversion=
cppflags='-D_HPUX_SOURCE'
ccflags ='-D_HPUX_SOURCE'
stdchar='unsigned char', d_stdstdio=define, usevfork=false
voidflags=15, castflags=0, d_casti32=undef, d_castneg=define
intsize=4, alignbytes=8, usemymalloc=y, prototype=undef
Linker and Libraries:
ld='ld', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /usr/lib/pa1.1 /lib /usr/lib
libs=-lnet -lndbm -ldld -lm -lc -lndir -lcrypt
libc=/lib/libc.sl, so=sl
useshrplib=false, libperl=libperl.a
Dynamic Linking:
dlsrc=dl_none.xs, dlext=none, d_dlsymun=undef, ccdlflags=''
cccdlflags='', lddlflags=''
Does anyone know where I might find a binary for HP-UX 9.04, or what
I'm doing wrong?
Thanks in advance!
Jeff Greenaway
------------------------------
Date: Thu, 07 Jan 1999 13:06:53 -0500
From: Tripp Lilley <tripp.lilley@perspex.com>
Subject: Re: If Larry Wall's listening out there....
Message-Id: <3694F7BD.26F7F6D9@perspex.com>
Andrew Mayo wrote:
> but what I really meant when I talked about notepad was that it is standard
> kit on all DOS and Windows machines - just as vi is standard on all Unix
> boxes - and WordSmasher 3000 won't be. So ideally I'd like just to install
> Perl and go for it. Of course, on my own machine I can install my favourite
> editor.
I guess some more understanding of your typical development scenario would help.
However, for most of us, we're not actually doing much /development/ on virgin
machines. Pretty much any time I'm sitting at a virgin machine, I'm either
getting ready to install tested, deliverable code, or I'm getting ready to
install emacs so I can debug in a more realistic environment :-)
However, below is a Perlish answer to your problem. I'm sure it could be tweaked
and hacked into something much more concise and expressive. My only design
criteria was to not use any modules that aren't part of the Perl standard
distribution. Fixups welcomed.
#!perl -w
use strict;
use FileHandle;
use Getopt::Long;
$0 =~ s|^.*[/\\]||;
sub usage {
print "usage: $0 --file <filename> --line <line> (--context <context>)\n";
print "\t--file <filename>\tthe file from which to extract lines
[REQUIRED]\n";
print "\t--line <line>\t\tthe target line [REQUIRED]\n";
print "\t--context <context>\tthe number of lines of context [OPTIONAL]\n";
}
my $options = { };
my $options_clean = GetOptions $options, 'file=s', 'line=i', 'context=i';
usage and exit 1
unless defined $options->{file} and defined $options->{line} and
$options_clean;
my $fh = new FileHandle $options->{file}, 'r'
or die "ERROR opening '$options->{file}': $!\n";
my $line = 0;
my $context = $options->{context} || 0;
my $context_start = $options->{line} - $context;
my $context_end = $options->{line} + $context;
while( <$fh> ) {
$line++;
next unless $line >= $context_start;
last if $line > $context_end;
print "$line:\t";
print;
}
$fh->close;
------------------------------
Date: 7 Jan 1999 18:00:21 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: If Larry Wall's listening out there....
Message-Id: <772snl$df9$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, bart.lateur@skynet.be (Bart Lateur) writes:
:I have read that newer/future versions would tackle this, by reusing
:storage of hash keys. What's the status on that?
Done, quite some time ago, in fact.
--tom
--
"I discount everything Djikstra has to say because he doesn't actually
run his programs" --Rob Pike, On Djikstra's belief that bugs in your
program are a moral failure to prove your program mathematically correct.
------------------------------
Date: Thu, 07 Jan 1999 13:15:16 -0500
From: Tripp Lilley <tripp.lilley@perspex.com>
Subject: Not Quite FAQ: perl for Win32 w/out console
Message-Id: <3694F9B4.678A3BF7@perspex.com>
I realize that the "how do I get the console to go away when I'm running
a Perl/Tk script?" is a FAQ. And I realize that the answer is in the
Cookbook. No problem.
The Not Quite FAQ is this: has anyone built a /non/ console-mode perl
for Win32? I realize it's probably a nasty undertaking. Nevertheless,
anyone undertaken it? I tried dejanews on what I considered relevant
keywords.
The situation is simple: I have a couple of Perl scripts that are run as
pre- and post- processing actions in an automated job. Thus, they're
repeatedly invoked, and the console window repeatedly flashes onscreen.
I realize that I can get around this by using the Cookbook answer, only
writing it in C instead of Perl :-) And, yes, that's what I'm going to
do if no one has pointers to a non-console build of perl (or, even
better, one that allows a command line switch as to whether or not to
run in console mode. This would be a tricky but useful hack under Win32.
I don't even want to think about it. Nevermind :-)
Thanks for any help! If nothing comes if it, I'll post the C wrapper
when I get around to writing it (that's considered a "cosmetic
refinement" stage, and is therefore ultra-low priority).
------------------------------
Date: Thu, 07 Jan 1999 12:03:32 -0600
From: John Warner <jwarner@tivoli.com>
Subject: Passing hashes to a sub
Message-Id: <3694F6F4.2000E415@tivoli.com>
I've reading up on hashes in perlfaq4, perlref, _Programming Perl_, and
the _Perl Cookbook_. However, the one task I haven't found an
explanation/example of how to pass a hash to a function. Is this
possible? The reason I ask is that I am working on a program that, in
the course of it talking to a database, creates several hashes. To
verify the accuracy of these hashes (as well as log to a text file), I
need to be able to print these hashes. I suppose I could use a global
variable but I prefer to limit the scope of the hashes to only the
sections of code to which they apply.
Thanks in advance,
John Warner
------------------------------
Date: 07 Jan 1999 10:19:30 -0800
From: Ben Gertzfield <che@debian.org>
Subject: Re: Passing hashes to a sub
Message-Id: <yttbtkbymh9.fsf@gilgamesh.cse.ucsc.edu>
>>>>> "John" == John Warner <jwarner@tivoli.com> writes:
John> I've reading up on hashes in perlfaq4, perlref, _Programming
John> Perl_, and the _Perl Cookbook_. However, the one task I
John> haven't found an explanation/example of how to pass a hash
John> to a function. Is this possible? The reason I ask is that
John> I am working on a program that, in the course of it talking
John> to a database, creates several hashes. To verify the
John> accuracy of these hashes (as well as log to a text file), I
John> need to be able to print these hashes. I suppose I could
John> use a global variable but I prefer to limit the scope of the
John> hashes to only the sections of code to which they apply.
Try passing references to the hash.
my %hash = (key => value, key2 => value2);
my %otherhash = (key3 => value3, key4 => value4);
myfunction(\%hash, \%otherhash);
sub myfunction {
my $hashref = shift;
my $otherhashref = shift;
print ($hashref->{key}, $otherhash->{key4}, "\n");
print (sort (keys %{$otherhashref}), "\n");
}
Ben
--
Brought to you by the letters N and Z and the number 9.
"Ooh, don't touch him, HE'S got the wall sconses."
Debian GNU/Linux maintainer of Gimp and GTK+ -- http://www.debian.org/
I'm on FurryMUCK as Che, and EFNet/Open Projects IRC as Che_Fox.
------------------------------
Date: Thu, 7 Jan 1999 13:39:58 -0500
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: Passing hashes to a sub
Message-Id: <MPG.10fec98b70000ff989778@news.scescape.net>
In article <3694F6F4.2000E415@tivoli.com>, jwarner@tivoli.com pounded in
the following:
[snip asking how to pass hashes]
There are two common ways:
1) Pass by reference:
sub mysub1 {
my $hashref = shift;
# use $hashref like:
# keys %{$hashref}
# ${$hashref}{'key1'}
# @{$hashref}{'key1','key2'}
}
2) Take advantage of the fact hashes can be flattened into arrays and
reexpanded:
sub mysub2 {
# Get other args off the stack (@_)
my %hash = @_;
}
You then call them like this:
my %hash;
#init hash
mysub1(\%hash);
mysub2( %hash);
=> Thanks in advance,
HTH!
=> John Warner
--Matthew
------------------------------
Date: Thu, 07 Jan 1999 10:00:46 -0800
From: Gennady Stupakov <stupakov@slac.stanford.edu>
Subject: Perl Cookbook example on NT
Message-Id: <3694F64E.8C2232DB@slac.stanford.edu>
Hi,
I was trying to run an example code pmdesc from Chapter 12 of Perl
Cookbook.
I am using:
Binary build 507 provided by ActiveState Tool Corp.
http://www.ActiveState.com
Built 15:08:32 Nov 14 1998
on Windows NT machine.
This script is supposed to print a list of modules installed and their
description.
What actually happens, the code exits silently without any output. If I
run
it with -w flag, it does print a list of perl directories, but again no
descriptions of the
modules.
Does anybody tried this script on NT?
Thank you.
Gennady.
------------------------------
Date: Thu, 7 Jan 1999 11:26:04 -0600
From: "walter" <tavi367@ibm.net>
Subject: Q on search & replace in larger strings
Message-Id: <3694ee7b.0@news1.ibm.net>
Say I have a scalar '$fileContents', in which I slurped an entire text file
into.
Say I have a Hash '%spec_Chars', of 100 keys and mated values.
Now, I need to run through this scalar to see if any of these keys are in
this scalar and if so replace it with the value of that key.
Do I do this?
foreach (keys %spec_Chars)
{
$fileContents =~ s/$spec_Chars{$_}/$_/i;
}
Or am I missing something Perl-esque that would make this better?
Walter
====================================================================
The software required `Windows 95 or better', so I installed Mac OS.
-- Remember: Win 95 = Mac 84 = GS 80 = Xerox 72
------------------------------
Date: 07 Jan 1999 13:00:21 -0500
From: Uri Guttman <uri@home.sysarch.com>
Subject: Re: Q on search & replace in larger strings
Message-Id: <x74sq3kloq.fsf@home.sysarch.com>
>>>>> "w" == walter <tavi367@ibm.net> writes:
w> Say I have a scalar '$fileContents', in which I slurped an entire text file
w> into.
w> Say I have a Hash '%spec_Chars', of 100 keys and mated values.
w> Now, I need to run through this scalar to see if any of these keys are in
w> this scalar and if so replace it with the value of that key.
w> Do I do this?
w> foreach (keys %spec_Chars)
w> {
w> $fileContents =~ s/$spec_Chars{$_}/$_/i;
w> }
w> Or am I missing something Perl-esque that would make this better?
well it would help to get the above code correct before attempting any
tricks.
you have the 2 parts of s/// reversed. if you want to replace the key of
%spec_Chars with its value you should use:
$fileContents =~ s/$_/$spec_Chars{$_}/i;
if this is a one time thing per program run then there is not much
optimization you can do. but if this does this operation for multiple
files then you could precompile the regexes in several ways which will
save a lot of electrons from wasteful deaths.
the first way is to use qr// to create a list of precompiled regexes to
apply. do something like this only once (highly untested):
%regexes = map { ($_, qr/$_/ ) } keys %spec_Chars ;
then in the loop do similar code but use the precompiled regexes:
$fileContents =~ s/$regexes{$_}/$spec_Chars{$_}/i
foreach keys %spec_Chars;
the other method is to create a anon sub on the fly with the regex code
and eval it once and use the sub ref to convert the text. there are
examples of how to do this in the perl cookbook and in many postings in
this group. search dejanews for those.
hth,
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire ---------------------- Perl, Internet, UNIX Consulting
uri@sysarch.com ------------------------------------ http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Thu, 07 Jan 1999 09:12:08 -0800
From: Silvio Picano <spicano@ptdcs2.intel.com>
Subject: Re: rsh and process management q
Message-Id: <3694EAE7.FBDC0F16@ptdcs2.intel.com>
rotenm@ecs.csus.edu wrote:
> Greetings!
>
> I've got a tricky one that maybe somebody out there can help with.
>
> I'm attempting rsh command over a network, whereas some of the machines that
> are getting shelled to will not permit a rsh, and will not return any form
> of error message... they will just sit there and do nothing.
>
> This is a snippet of the core of what I'm trying to do... it works, but it's
> only *semi* reliable. Sometimes it won't timeout properly at all and just
> hangs up.
>
> $SIG{ALRM} = \&timeout;
> alarm(10);
> $pid = open ( RSH, "rsh -n $ipadd echo \'x\' |" );
> alarm(0);
> exit(0);
>
> sub timeout {
> print STDERR " *** TIMEOUT on $ipadd ***\n";
> print STDERR " *** KILLING $pid... ***\n";
> system "kill -9 $pid";
> print STDERR " *** $pid KILLED! ***\n";
> alarm(0);
> close RSH;
> return
> }
>
> Any advice as to how to increase the reliability of this would be greatly
> appreciated.
>
> Michael
> rotenm@ecs.csus.edu
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
For time-outs, I like to use open(..., "|-") which is results in a parent child
pair
(i.e., fork()). [Look in perlipc]. Let the child perform the rsh(), followed by
an exit; Put
the parent in a loop (having sleep() & waitpid() calls) ... when this loop
exits, the
parent can check how/if the child exit'ed, etc.
Silvio
------------------------------
Date: Thu, 07 Jan 1999 13:17:50 -0500
From: Geoffrey Hebert <soccer@all-soccer.com>
Subject: Win32::net User Full Name?
Message-Id: <3694FA4D.DAC6DF33@all-soccer.com>
Where can I get the NT Full Name of the user?
Win32::net User Full Name?
I am going to read the log and pick up items and I wish to convert the
user to full name.
Is there another way?
Thanks
Geoffrey Hebert
Please email return to soccer@all-soccer.com or
geof.hebert@capbluecross.com
--
FREE FREE FREE FREE
Free site for your Soccer League
http://www.all-soccer.com
All about soccer - what else is there!
------------------------------
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 4572
**************************************