[7420] in Perl-Users-Digest
Perl-Users Digest, Issue: 1045 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 18 17:17:20 1997
Date: Thu, 18 Sep 97 14:00:34 -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, 18 Sep 1997 Volume: 8 Number: 1045
Today's topics:
Calculating the week number (Bjorn)
Does Perl have a "blank" regex character class code <Brett.W.Denner@lmtas.lmco.com>
Re: GNU sort & Perl <j.curzon-price@ic.ac.uk>
Re: Help with HTML embedded in Perl script <russ@mail.org.uk>
Help with indirect file handles (emd)
Re: Inserting \n in a string <russ@mail.org.uk>
Re: Is Perl for Win32 really as brain damaged as it see <russ@mail.org.uk>
Re: Learning perl <russ@mail.org.uk>
Nested subs and local vs my (Jim Turner )
Re: Newbie Question <tou@tou.com>
Re: Newbie Question: Passing parameters <jefpin@bergen.org>
NT: open2 or NET::rexec <kermit@ticnet.com>
Re: Perl equivalent to #ifdef in C? <usenet-tag@qz.little-neck.ny.us>
questions about perl embedded in shell scripts using -e txporter@mindspring.com
Ret Value from Opened Pipe <jadestar@rahul.net>
Re: Returning hashes of arrays from a subroutine r_a_m_l_i@csc.ti.com
Re: Rounding numbers problem <amit@csd.sgi.com>
Re: simple Sendmail Question (Newbie) <russ@mail.org.uk>
Sockets <plivi@toronto.cbc.ca>
Re: Sockets (Mike Heins)
strange behaviour of sort in perl 5.004.03 <andi@team-konzept.de>
What does this error message mean? (Joseph Scott Stuart)
Re: What does this error message mean? (Faust Gertz)
Re: Why don't my <<HERE documents work? Attempt #2! (Nick Callerame)
Re: Win32 Registry QueryValue - need example <dvpgg@landmark.com>
Re: Yknow, the thing about perl is.... <russ@mail.org.uk>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 18 Sep 1997 19:29:29 GMT
From: bjorn@earthcorp.nn.se (Bjorn)
Subject: Calculating the week number
Message-Id: <34238026.16133790@news.algonet.se>
I need a piece of code for calculating the current week. I checked the
perl FAQ, but the formula there doesn't work (unless you're on a year
that starts with monday and don't care about the last week being
correct). Any help would be greatly appreciated...
___
ANTI-SPDM: Please remove ".nn" from the address when
replying via e-mail
------------------------------
Date: Thu, 18 Sep 1997 13:04:28 -0500
From: Brett Denner <Brett.W.Denner@lmtas.lmco.com>
Subject: Does Perl have a "blank" regex character class code
Message-Id: <34216D2C.167E@lmtas.lmco.com>
I know that in a regex \s stands for the whitespace character class
[ \t\n\r\f\v]. Is there something similar for a "blankspace" character
class that only contains [ \t], for example? Typing [ \t]* in a regex
is so much uglier than \s*, but occasionally \s* grabs the newline
as well, which I don't always want.
Thanks,
Brett
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Brett W. Denner Lockheed Martin TAS
Brett.W.Denner@lmtas.lmco.com P.O. Box
748
(817) 935-1144 (voice) Fort Worth, TX 76101
(817) 935-1212 (fax) MZ 9333
------------------------------
Date: Thu, 18 Sep 1997 18:54:24 +0100
From: Tony Curzon Price <j.curzon-price@ic.ac.uk>
Subject: Re: GNU sort & Perl
Message-Id: <34216AD0.74EC3C04@ic.ac.uk>
Thanks, Tom. You're certainly right that it wasn't a problem with my
perl expression.
I got to the bottom of the problem, and it might be a slightly salutary
lesson for other perl beginners:
I eventually realised that the sort was writing the sorted file when
doing it from the shell, but it wasn't even writing the file from perl
(a permission problem). But I had just assumed that if it was getting to
the end of my script without crashing/squealing, it was actually
executing the instructions. I hadn't made it verbose enough, and wasn't
trapping errors...
Tony
--
Tony Curzon Price Imperial College
http://is.eunet.ch/Customers/curzon/index.html
(During GMT office hours, or so):
http://epgphd.et.ic.ac.uk/www/
------------------------------
Date: Thu, 18 Sep 1997 14:42:12 +0100
From: Russell Odom <russ@mail.org.uk>
To: paulb.musicp@zetnet.co.uk
Subject: Re: Help with HTML embedded in Perl script
Message-Id: <34212FB4.22BD6968@mail.org.uk>
Paul Bankier wrote:
>
> Can you help me with a problem with Perl as I am a new beginner in
> Perl.
> I recently took on the responsility to develop a website whilst on
> holiday from my studies and now I'm back at University, the job needs
> to be finished and I'm really struggling with some element within
> Perl.
> If you can help, please email me and if we can get it finshed and
> working, I will gladly give you a reward for helping.
Well, what's your problem(s)? Post to the group and your questions will
(probably) be answered, or you'll be pointed in the right direction.
HTH,
Russ
---------------------------------------------------------------------
--[ R u s s e l l O d o m ]---[ *NEW:* mailto:russ@mail.org.uk ]--
--[ University of York, UK ]---[ http://www.york.ac.uk/~rjo100/ ]--
---------------------------------------------------------------------
--[ FAQ maintainer, news:comp.os.ms-windows.win95.moderated ]--
---------------------------------------------------------------------
------------------------------
Date: Thu, 18 Sep 1997 15:35:46 -0400
From: "Ronald Sercely (emd) {xxxx}" <rzs@gbr.msd.ray.com>
Subject: Help with indirect file handles
Message-Id: <34218291.4E51@gbr.msd.ray.com>
I have a perl script:
#!/usr/bin/perl
if ($#ARGV < 0) {
print "You must input grep string\n" ;
exit;
}
foreach $string (@ARGV) { # open up one file per input string
open ($OUT{$string}, ">/tmp/$name[$#name].$string") ||
die "opening outputfile /tmp/$name[$#name].$string";
select ($OUT{$string}) || die;
$| = 1;
}
foreach $directory (grep(!/^\.\.?$/,readdir(GLOBALS) ) ) {
foreach $string (@ARGV) { # open up one file per input string
print $OUT{$string}; # works
print $OUT{$string} "xx"; # syntax error
}
}
What does the first print the inderect file work
but the second give a syntax error?
I am running on HP-UX, version 10.01,
perl -v
This is perl, version 4.0
$RCSfile: perl.c,v $$Revision: 4.0.1.8 $$Date: 1993/02/05 19:39:30 $
Patch level: 36
Copyright (c) 1989, 1990, 1991, Larry Wall
Perl may be copied only under the terms of either the Artistic License
or the
GNU General Public License, which may be found in the Perl 4.0 source
kit.
--
Thanks.
Ron Sercely
617.274.3481
HP Consultant to the Raytheon GBR Team
------------------------------
Date: Thu, 18 Sep 1997 11:44:27 +0100
From: Russell Odom <russ@mail.org.uk>
Subject: Re: Inserting \n in a string
Message-Id: <3421060A.7D760491@mail.org.uk>
Andrew M. Langmead wrote:
>
> Russell Odom <rjo100@york.ac.uk> writes:
>
> >Matt Weber wrote:
> >>
> >> I want to insert a new line (\n) every 75 charectors in a string...any
> >> suggestions? I just don't know what function to use.
>
> >$line =~ s/(.{0,75})/$1\n/gs;
>
> >You could also have a look at Text::Wrap.
>
> Text::Wrap didn't quite fit the spec. The original poster wanted a
> newline every 75 characters, implying breaking between characters in a
> word. (but lines exactly 75 characters long.) Text::Wrap will insert a
> newline at the last whitespace character before the line limit.
Yes, but I thought I'd mention it in case that was what the poster was
_really_ trying to do.
Actually, to change my solution a bit...
$line =~ s/(.{1,75})/$1\n/gs;
...doesn't add a newline right at the end if the string is exactly a
multiple of 75 chars long.
HTH,
Russ
---------------------------------------------------------------------
--[ R u s s e l l O d o m ]---[ *NEW:* mailto:russ@mail.org.uk ]--
--[ University of York, UK ]---[ http://www.york.ac.uk/~rjo100/ ]--
---------------------------------------------------------------------
--[ FAQ maintainer, news:comp.os.ms-windows.win95.moderated ]--
---------------------------------------------------------------------
------------------------------
Date: Wed, 17 Sep 1997 22:22:46 +0100
From: Russell Odom <russ@mail.org.uk>
To: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Is Perl for Win32 really as brain damaged as it seems?
Message-Id: <34204A26.32F65039@mail.org.uk>
Tom Phoenix wrote:
>
> On Tue, 16 Sep 1997, Russell Odom wrote:
>
> > Not necessarily: just run the registry editor (regedit.exe) and search for
> > all occurences of 'A:\'. Remove the ones that aren't absolutely necessary
> > (usually all of them).
>
> Since Perl can work directly with the registry, couldn't a simple script
> do this? I don't have a Windows machine or I'd try writing this script
> myself. But if anybody will write a good one, I'll do my best to get it
> enshrined in the FAQ.
This strikes me as a case of reinventing the wheel, there are already
(non-perl) programs out there to do this sort of thing, 'Registry Search
+ Replace' (http://www.iserv.net/~sjhswdev/) for one.
If a perl solution was used, it should definitely not just blindly delete
all references to 'A:\', it should ask for confirmation for each first.
Maybe it should also have an 'undo' option for changes made (and be able
to undo _individual_ changes at a later date)?
HTH,
Russ
---------------------------------------------------------------------
--[ R u s s e l l O d o m ]---[ *NEW:* mailto:russ@mail.org.uk ]--
--[ University of York, UK ]---[ http://www.york.ac.uk/~rjo100/ ]--
---------------------------------------------------------------------
--[ FAQ maintainer, news:comp.os.ms-windows.win95.moderated ]--
---------------------------------------------------------------------
------------------------------
Date: Thu, 18 Sep 1997 12:09:56 +0100
From: Russell Odom <russ@mail.org.uk>
Subject: Re: Learning perl
Message-Id: <34210C03.AF104242@mail.org.uk>
Jason wrote:
>
> Yeah, read 'Learing Perl', by Randal L. Schwartz, then get 'Programming
> Perl' by Larry Wall. These are the two Perl books, both by O'Reilly &
> Associates.
>
> However, as I have recently had to learn Perl, I found the best method is
> to simply get down and do it. Find a real problem and hack out a solution
> to it.
And it should be noted that a particularly good place to find real
problems is this very group! If you see a problem which you think you
could program a solution to, do so and post it. Usually someone will give
you feedback on your solution, and you can compare it with other people's.
Also, I second (third? fourth?) the recommendation for 'Learning Perl'.
Read it through a couple of times, do the excercises, you'll learn a lot.
> Erich Kreiselmaier <erich@flm.mw.tu-muenchen.de> wrote in article
> <340FA7C7.4A37@flm.mw.tu-muenchen.de>...
> >
> > I am new to perl programming. Does anyone have a recommendation for
> > free available documentation or a good book.
HTH,
Russ (who will buy the Camel book as soon as he's sure he'll have enough
money to be able to eat for the next few weeks)
---------------------------------------------------------------------
--[ R u s s e l l O d o m ]---[ *NEW:* mailto:russ@mail.org.uk ]--
--[ University of York, UK ]---[ http://www.york.ac.uk/~rjo100/ ]--
---------------------------------------------------------------------
--[ FAQ maintainer, news:comp.os.ms-windows.win95.moderated ]--
---------------------------------------------------------------------
------------------------------
Date: 18 Sep 1997 18:09:24 GMT
From: turnerj@cliffy.lmtas.lmco.com (Jim Turner )
Subject: Nested subs and local vs my
Message-Id: <5vrqok$d2n3@quest.lmtas.lmco.com>
Keywords: local my sub
Hello. This problem has caused me a lot of grief due to my apparant
ignorance of Perl's scoping. Can anyone tell me why the following
code:
#!/usr/bin/perl
for ($i=1;$i<4;$i++)
{
&outerfn($i);
}
sub outerfn
{
my ($b); #DEFINED WITHIN OUTERFN'S LEXICAL SCOPE.
sub innerfn
{
$b = $i;
print "--inner: b=$b=\n";
}
&innerfn;
print "--outer: b=$b=\n";
}
produces the following results:
--inner: b=1=
--outer: b=1=
--inner: b=2=
--outer: b== #SHOULDN'T THIS BE 2, WHY UNDEFINED?
--inner: b=3=
--outer: b== #SHOULDN'T THIS BE 3?
Changing "my" to "local" for "b" in "outter" seems to solve my problem,
but can lead to other problems associated with local, and I would prefer
to normally use my. I also just wonder why b is undefined on every call
but the first.
Thanks in advance!
Jim Turner
turnerj@mmc1001.lmtas.lmco.com
------------------------------
Date: Thu, 18 Sep 1997 11:35:42 -0700
From: Joel Shellman <tou@tou.com>
To: fischers@execpc.com
Subject: Re: Newbie Question
Message-Id: <3421747E.5AB2065B@tou.com>
fischers@execpc.com wrote:
>
> I am posting a form to a cgi perl script. I want to access a hidden
> field in the form. How do I access the variable?
The perl script does not distinguish between a type="hidden" and a
type="text" or a type=password or whatever. It is all there when you
parse it.
-joel
--
TaoTree Research and Development
Web Development/Design, Virtual Servers, hosting, Perl/CGI programming
http://www.tou.com/rd/
Revolutionary new clicks-based Banner Exchange Guarantees you traffic
http://www.tou.com/ite/
------------------------------
Date: Thu, 18 Sep 1997 15:22:06 -0400
From: TechMaster Pinyan <jefpin@bergen.org>
To: Jeff Motter <jmotter@fgi.net>
Subject: Re: Newbie Question: Passing parameters
Message-Id: <Pine.SGI.3.95.970918152011.14764C-100000@vangogh.bergen.org>
>I have a script named "me.pl" and I want to pass a filename to the script
>when it is started.
>Ex: c:\perl\me.pl data.txt".
>
>What would be the variable for the file "data.txt" in the script. I'm
>going to open the file in the script to parse it.
Correct me if I am wrong, but I believe it would be in the array @ARGV.
It is the first element, so you could retrieve it by the following two
methods:
1) $file = $ARGV[0];
2) $file = shift;
Hope it helps... and hope it's the same on the PC as it is on UNIX.
----------------
| "I don't contemplate it, I just sit and think about it."
| - Sonia Balsky
----------------
Jeff Pinyan | http://users.bergen.org/~jefpin | jefpin@bergen.org
webXS - the new eZine for WebProgrammers! TechMaster@bergen.org
Visit us @ http://users.bergen.org/~jefpin/webXS
** I can be found on #perl on irc.ais.net as jpinyan **
- geek code -
GCS/IT d- s>+: a--- C+>++ UAIS+>$ P+++$>++++ L E--->---- W++$
N++ !o K--? w>+ !O M>- V-- PS PE+ !Y !PGP t+ !5 X+ R tv+ b>+
DI+++ D+>++ G>++ e- h- r y?
------------------------------
Date: Thu, 18 Sep 1997 13:23:40 -0500
From: Kermit Tensmeyer <kermit@ticnet.com>
Subject: NT: open2 or NET::rexec
Message-Id: <342171AC.9C135D45@ticnet.com>
I've been trying a few things and I want to make sure that I'm
not reinventing the wheel.
first Net::Rexec does not yet exist?
I've tried to use the open(FILE, "rexec blah ... 2>&1 |") type of
call but rexec wants to ask for userid and password in an interactive
session. The userid can be passed in, but the passsword is still ask'd
(in the unix world, it would be simple to set up a netrc file)
(in the NT world, it doesn't yet exist).
I tried to use the open2 that gets delivered with the NT perl,
but it doesn't implement 'forks' but requires 'spawn'
before I try to either write NET::rexec or IPC::open2 for
the NT, what have other people done?
--
-------
Kermit Tensmeyer
Kermit@ticnet.com
------------------------------
Date: 18 Sep 1997 17:59:56 GMT
From: Eli the Bearded <usenet-tag@qz.little-neck.ny.us>
Subject: Re: Perl equivalent to #ifdef in C?
Message-Id: <eli$9709181345@qz.little-neck.ny.us>
In article <341FB593.4C7848C@absyss.fr>, Doug Seay <seay@absyss.fr> wrote:
> lynn kasdorf wrote:
> > What is an easy way to enable/disable blocks of code in perl. In C I
> > would go...
> > #ifdef THIS_WAY
> > // some c code done one way
> > #else
> > // the same code done another way
> > #endif
> Yes, there is an quivalent structure in Perl. It is "if". It would be
> used like
Not equivalent.
#define EFFICIENT_SHORTCUT 0
#ifdef EFFICIENT_SHORTCUT
At some point I will implement this function, but not yet.
if (can_do_efficiently())
do_something_efficiently();
else
#else
do_something();
#endif
> It is almost identical to the mechanism found in C and is functionally
> identical to what you had described.
Even barring that I don't bother using some sort of comment delimitor
in the ifdef'ed out code, note how the preprocessor cuts across the
c syntax.
> Someone has already pointed out the -P (capital) option. I would like
> to weigh in against it. I think it is ugly and a waste to launch a
> separate process when it doesn't gain you anything over what is already
> in Perl.
How about if you have a source file and a "compiled" file, with a makefile
that uses cpp as the compiler to produce "compiled" perl script?
Elijah
------
makefile enthusiast
------------------------------
Date: Thu, 18 Sep 1997 13:56:22 -0600
From: txporter@mindspring.com
Subject: questions about perl embedded in shell scripts using -e (LONG!)
Message-Id: <874608421.12326@dejanews.com>
Howdy perl experts!
A couple of questions relating to embedding perl run via the -e flag in
shell scripts. (SORRY for the l-o-n-g post, but I wanted to include
examples!
I am writing a script to read a mail folder and split it up into separate
files, based on the month and year in the FROM header. Its based on the
following script for purging messages older than a certain number of days.
The model script uses embedded perl so all active code can be seen in the
single shell script as so:
-----------------------------------
#!/bin/sh
#
umask 077
maxdays=28
maildir=/var/spool/mail
mailbox=${maildir}/$1
tempbox=${mailbox}.tmp
boxlock=${mailbox}.lock
if [ $# -ne 1 ]; then
echo "Usage: $0 mailbox" >&2
exit 1
fi
if [ ! -s ${mailbox} ]; then
echo "$0: ${mailbox}: No mail." >&2
exit 0
fi
if ! lockfile -r 10 ${boxlock}; then
echo "$0: ${mailbox}: Cannot lock." >&2
exit 1
fi
trap "rm -f ${tempbox} ${boxlock}; exit 1" 1 2 3 15
formail <${mailbox} >${tempbox} -s perl -e '
use Time::Local qw(timegm);
$maxage = 24 * 3600 * pop;
%months = (
Jan => 0, Feb => 1, Mar => 2, Apr => 3,
May => 4, Jun => 5, Jul => 6, Aug => 7,
Sep => 8, Oct => 9, Nov => 10, Dec => 11 );
chomp($from = <>); @from = split(" ", $from);
$year = pop @from; $time = pop @from;
$mday = pop @from; $mon = $months{pop @from};
($hour,$min,$sec) = split(/:/, $time);
$age = time - timegm($sec,$min,$hour,$mday,$mon,$year-1900);
if ($age > $maxage) {
while (<>) { ; }
} else {
print "$from\n";
while (<>) { print $_; }
}
' ${maxdays}
cat ${tempbox} >${mailbox}
rm -f ${tempbox} ${boxlock}
exit 0
-----------------------------------
My initial effort at a mail splitter shell script calls a separate perl
script, but I want to embed my perl script in the calling script like the
model does. In its final version the mail splitter will copy messages
older than a certain number of months to the separate month archives, to
be gzipped later, and write messages more recent than the limit to a temp
file to be copied over the real mailfolder, like the model program does.
I naturally want to use error checking like the model does to prevent
unfortunate accidents from wiping out my mail folders.
I had trouble getting my perl script to process the input from formail
properly when I passed an argument to the perl script (the name of the
mail folder) and so had to use <STDIN> as my data source as opposed to
simple <> like the model does.
>> My question is whether embedding my perl script in the calling shell
script will allow the passing of command line arguments (like the mail
folder name) into the perl script as I currently can do, or if I will need
another method. If so, how would I do it? This applies to the current
version of the maildate shell script and mdtxp.pl appended below.
>> Second question: If I am _not_ using an embedded perl script, but
calling my separate perl script, if the perl script fails and exits with
condition code = 1, will this cause the calling script to abort and not
perform the move of the temp file to the original mailfolder and the
gzips, as the model script appears to?
Thanks for your consideration, and any suggestions, flames, or pointers to
a better way to do this welcome. This came about since I have a 33 MEG
mail folder (on one topic!) that I need to manage a bit better than I am
currently doing!
Please cc: responses to email if possible,
Tom Porter
txporter@mindspring.com
maildate shell script follows:
--------------------------------------------------------
#!/bin/sh
#
# maildate
# version 0.1
# needs to pass monthskept parm to perl script
# and perl should write messages older than this to save files
# then write newer message to temp file to be copied over
# original mailbox file if process suceeds, similar
# to original purgemail does.
# 'mailbox' may be any mailbox-format file, not just the users
# /var/mail/{mailbox}
# this script assumes it is run in the directory of the
# target mail folder
umask 077
mailbox=$1
boxlock=${mailbox}.lock
tempbox=/tmp/${mailbox}.tmp
monthskept=2
if [ $# -ne 1 ]; then
echo "Usage: $0 mailfolder" >&2
exit 1
fi
if [ ! -s ${mailbox} ]; then
echo "$0: ${mailbox}: Folder not found." >&2
exit 0
fi
if ! lockfile -r 10 ${boxlock}; then
echo "$0: ${mailbox}: Cannot lock." >&2
exit 1
fi
trap "rm -f ${boxlock}; exit 1" 1 2 3 15
formail <${mailbox} -s mdtxp.pl $1
for z in `ls /tmp/${mailbox}*sav`
do
gzip $z
done
cat ${tempbox} >${mailbox}
rm -f ${tempbox} ${boxlock}
exit 0
--------------------------------------------------------
My perl script mdtxp.pl follows:
--------------------------------------------------------
#!/usr/bin/perl
#
# mdtxp.pl
# version 0.1
#
# needs to read monthskept argument passed in from maildate
# parm one is mailbox name, and parm two is number of months to
keep.
# should write messages older than this to save files
# then write newer message to temp file to be copied over
# original mailbox file if process suceeds, similar
# to what original purgemail does.
#
# >> needs code to capture monthskept argument and code to write to
# >> either the year-month.sav file or the temp file.
#
chomp($from = <STDIN>); @from = split(" ", $from);
$year = pop @from; $time = pop @from;
$mday = pop @from; $months = pop @from;
open(DATEFILE, ">>/tmp/$ARGV[0].${year}${months}.sav");
print DATEFILE "$from\n";
while (<STDIN>) { print DATEFILE $_; }
--------------------------------------------------------
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: 18 Sep 1997 18:12:46 GMT
From: Jim Dennis <jadestar@rahul.net>
Subject: Ret Value from Opened Pipe
Message-Id: <5vrquu$8of$1@samba.rahul.net>
How do I get the value returned by my open()'d process?
Given code like:
open (PROG, "|$myprog");
print PROG "some input";
print PROG "some more input";
#???
close(PROG);
print $?; #???
My program is supposed to take to lines of input --
and return one of several possible values. I want
my perl code to be able to distinguish between them,
and act accordingly.
What I currently get is either 0 or 256 -- where I program
is returning 0, 1, 255, 254, or 253 for various test
cases.
Why doesn't this work as one would expect?
------------------------------
Date: 18 Sep 1997 14:03:39 -0500
From: r_a_m_l_i@csc.ti.com
Subject: Re: Returning hashes of arrays from a subroutine
Message-Id: <fhlo0uh2b8.fsf@csc.ti.com>
I had earlier posted a query on how to return hashes of arrays
from a subroutine. I posted the qeury too soon; as the saying
goes, "When everything else fails, read the FAQ"... NOT!
Here is what I came up with, which seems to work:
sub process_file {
my %common, %non_common;
....
return (\%common, \%non_common);
}
In the main program:
#-----------------------
# calling the subroutine
#-----------------------
($cn_ref, $ncn_ref) = &process_file($hg_file);
#-----------------------
# printing the elements
#-----------------------
foreach $name (keys %$cn_ref) {
print "$name: @{ $cn_ref->{$name} }\n";
}
foreach $name (keys %$ncn_ref) {
print "$name: @{ $ncn_ref->{$name} }\n";
}
Even though %common and %non_common are "my" variables,
you can return a reference to them, as pointed out in
the PERL FAQ.
If there are any potential problems with the above, please
let me know. My apologies for wasting bandwith and your time.
------------------------------
Date: Thu, 18 Sep 1997 12:12:57 -0700
From: amit kothari <amit@csd.sgi.com>
To: david.nurse@ndcb.ox.ac.uk
Subject: Re: Rounding numbers problem
Message-Id: <34217D39.10C4691B@csd.sgi.com>
David R. Nurse wrote:
>
> I need to round some numbers to different numbers of decimal places and
> then to the nearest half, e.g.
>
> to 2 decimal places:
> 1.34456 becomes 1.35
> 2.57876 becomes 2.60
>
> to 1 decimal place:
>
> 1.34456 becomes 1.5
> 2.57876 becomes 2.5
>
> any of you Perl experts think of an easy way of doing this ?
>
> thanks in advance
>
> Dave Nurse
> Oxford Medical Informatics
> david.nurse@ndcb.ox.ac.uk
use this function -
$a = &round(1.34456,2);
################### sub round
############################################
#rounds off a float to any precision
sub round{
my($l_arg1,$l_scale)=@_;
return 0 if ($l_arg1 == 0);
my($l_num1,$l_num2) = 0;
$l_scale = 0 if (!$l_scale);
$l_num1 = 10**$l_scale * $l_arg1;
$l_num2 = int($l_num1);
$l_num2 = $l_num2 +1 if ($l_num1 - $l_num2 > 0.5);
$l_num1 = $l_num2/10**$l_scale;
return $l_num1;
}
################### end sub round
############################################
------------------------------
Date: Thu, 18 Sep 1997 11:55:33 +0100
From: Russell Odom <russ@mail.org.uk>
Subject: Re: simple Sendmail Question (Newbie)
Message-Id: <342108A5.1CA6632F@mail.org.uk>
Ronald Hritz wrote:
>
> I am attempting to send e-mail from an HTML form to a Fax gateway
> through Formmail.pl 1.6. I need to alter the From field to my
> personal e-mail address so the fax server will process the message.
> Currently, the e-mail header is "nobody@mimas.domain.com"
> I've alter the PRINT MAIL From: my email address command in Formmail
> but it doesn't work. Our webmaster says to change the Sendmail command
> using the -f parameter. What would be the correct syntax ?
>
> Currently the cammand is set as :
> OPEN(MAIL,"|$mailprog -t");
For a guess (I'm not on a UNIX system ATM), try...
OPEN(MAIL,"|$mailprog -f me@here.com -t");
where me@here.com is your address.
HTH,
Russ
PS What's wrong with 'man sendmail'?
PPS Just because you're using sendmail from a perl script doesn't make
this a perl question. Followups set accordingly.
---------------------------------------------------------------------
--[ R u s s e l l O d o m ]---[ *NEW:* mailto:russ@mail.org.uk ]--
--[ University of York, UK ]---[ http://www.york.ac.uk/~rjo100/ ]--
---------------------------------------------------------------------
--[ FAQ maintainer, news:comp.os.ms-windows.win95.moderated ]--
---------------------------------------------------------------------
------------------------------
Date: Thu, 18 Sep 1997 14:41:18 -0400
From: Paul Livi <plivi@toronto.cbc.ca>
Subject: Sockets
Message-Id: <342175CE.4277@toronto.cbc.ca>
Hi there,
Has anyone had experience with opening _and_ using sockets with PERL?
I'm able to open a socket to my destination and keep it open but am
unable to transmit data across it. I've tried using the send() and
recv() commands but have had no success. Any ideas or references?
Paul
------------------------------
Date: 18 Sep 1997 20:31:16 GMT
From: mheins@prairienet.org (Mike Heins)
Subject: Re: Sockets
Message-Id: <5vs32k$a04$2@vixen.cso.uiuc.edu>
Paul Livi (plivi@toronto.cbc.ca) wrote:
: Hi there,
:
: Has anyone had experience with opening _and_ using sockets with PERL?
: I'm able to open a socket to my destination and keep it open but am
: unable to transmit data across it. I've tried using the send() and
: recv() commands but have had no success. Any ideas or references?
:
I use them all of the time. The awsome thing about Perl sockets
is that you need not send() and recv(), you can do things like
'print SOCKET $var' and 'while (<SOCKET>) { do_something($_); }'.
'perldoc perlipc' will give you everything you need
to know.
--
Regards,
Mike Heins
This post reflects the
opinion of my employer.
------------------------------
Date: Thu, 18 Sep 1997 22:06:29 +0200
From: Andreas Schmidt <andi@team-konzept.de>
Subject: strange behaviour of sort in perl 5.004.03
Message-Id: <3421898E.1364@team-konzept.de>
I'm porting some perl-modules from perl 5.003 to 5.004.03. Most things
were easy, but there is a strange behaviour when using perl's sort
function with an anonymous function as argument:
In perl 5.003 I used quite often code like:
my @lala = sort { return &foo( $a, $b ); } @lolo;
I used stuff like this quite often, and it was always ok. But with perl
5.004.03 this did not work everywhere. It was quite strange: When I
tried to build a small script to isolate the problem, everything was
fine, but in my real world modules, none of my sort-calls worked
anymore. Sometimes I got a runtime error
Sort subroutine didn't return a numeric value at XXXX
But it did! And in other cases sort just did not sort.
After spending a long time with looking for errors, I realized that
everything is fine, if I remove the word return in the anonymous
function, or if i pass the result of &foo( $a, $b ) to a local variable
before returning it. But just return &foo( $a, $b ) did not work..
So for now, I have no more problems, and I hope this could help others
when having the same troubble. But I would be glad, if someone could
explain me this behaviour. Is this a bug or a feature?
Thanks,
Andi
------------------------------
Date: 18 Sep 1997 17:35:59 GMT
From: nospam@ll.mit.edu (Joseph Scott Stuart)
Subject: What does this error message mean?
Message-Id: <NOSPAM.97Sep18133600@pickering.ll.mit.edu>
I'm using this version of perl:
This is perl, version 5.003 with EMBED
built under irix at Jan 23 1997 16:55:47
on this OS:
IRIX64 rock 6.4 02121744 IP27
and I get the following error message at the end of my program:
Not a GLOB reference during global destruction (#1)
I do use the glob routine, and here is the relevant code:
# look for egse1done files
if ( (!scalar(@e1dfiles))) {
@e1dfiles = glob("$pam_in/*.$egse1_done");
}
if ( (scalar(@e1dfiles)) ) {
# parse the egse1_done file
$curr_e1d_filename = pop(@e1dfiles);
# use $curr_e1d_filename several times
}
That code snippet is within a loop that ends when certain file is
found. I'm just getting all files from the directory in $pam_in that
end with the extension $egse1_done and processing each file.
I don't have a clue what the error message means.
Thanks for your assistance. Note that my return address in the header
is fake. My real address is in my sig.
scott
--
Scott Stuart
stuart at ll mit edu
------------------------------
Date: Thu, 18 Sep 1997 20:14:46 GMT
From: faust@wwa.com (Faust Gertz)
Subject: Re: What does this error message mean?
Message-Id: <34218a67.7798196@news.wwa.com>
On 18 Sep 1997 17:35:59 GMT, nospam@ll.mit.edu (Joseph Scott Stuart)
wrote:
> I get the following error message at the end of my program:
>
>Not a GLOB reference during global destruction (#1)
>
>I don't have a clue what the error message means.
Here is a clue from the manpage:
:Not a GLOB reference
: (F) Perl was trying to evaluate a reference to a ``typeglob''
:(that is, a symbol table entry that looks like *foo), but found a
:reference to something else instead. You can use the ref
:function to find out what kind of ref it really was.
Also see perlref - Perl references and nested data structures at
ftp://ftp.digital.com/pub/plan/perl/CPAN/doc/manual/html/pod/perlref.html
HTH
Faust Gertz
Philosopher at Large
"You can neither bluff nor can you impress someone who isn't paying
attention." -- David Mamet
------------------------------
Date: Thu, 18 Sep 1997 19:02:03 GMT
From: ncallerame@looksmart.com (Nick Callerame)
Subject: Re: Why don't my <<HERE documents work? Attempt #2!
Message-Id: <5vrtrb$ku1$2@news.genuity.net>
In article <comdog-ya02408000R1209970107150001@news.panix.com>,
comdog@computerdog.com (brian d foy) wrote:
>
>In article <341aa433.14149064@news.wwa.com>, faust@wwa.com wrote:
>
>>Why don't my <<HERE documents work? Here is a sample of my code.
>
>>print <<EOF;
>>This is a test!
>>EOF
>
>>Can't find string terminator "EOF" anywhere before EOF at da.pl line 3.
>
>>1. There is no space after the << part.
>>2. There is a semicolon at the end.
>>3. There is no space in front of the tag.
>
>is there anything after the (supposedly) terminating EOF? it must be
>on a line by itself.
>
Keep in mind that even spaces on the line after the closing tag (after the EOF
in this case) can cause an error (at least on my machine). Make sure you have
a semicolon at the end of the print <<EOF; line _only_ and absolutely nothing
else on the same line as the terminating EOF (no spaces either before or after
the EOF).
Nick Callerame
ncallerame@looksmart.com
------------------------------
Date: Thu, 18 Sep 1997 12:54:17 -0400
From: Pat Garverick <dvpgg@landmark.com>
Subject: Re: Win32 Registry QueryValue - need example
Message-Id: <34215CB9.652A@landmark.com>
I'm posting my own answer here in case any one see's this and has
the same problem.
I found the solution in a new book,
Learning Perl on Win32 Systems
Randal L. Schwartz, Erik Olson & Tom Christiansen
O'Reilly & Associates, Inc.
Pat Garverick wrote:
>
> I'm trying to use Win32::Registry to read the Windows95 registry.
>
> I successfully use Open and GetKeys.
> However, I am unable to use QueryValue successfully.
> Can anyone give me an example using this?
>
> My goal is to get the value for the name I specify under
> a low-level key.
> For example, Using Open, I work my way down
> HKEY_LOCAL_MACHINE, SOFTWARE, ActiveWare, Perl5.
> Using the regular Registry Editor, I see there is, for example,
> the name BIN which has the value "D:\perl\bin".
> I want my perl script to let me query to get this same value
> when I specify the name of "BIN".
>
> fyi, perl -v indicates I'm on 5.003_07
>
> Thanks
> Pat
------------------------------
Date: Thu, 18 Sep 1997 13:10:40 +0100
From: Russell Odom <russ@mail.org.uk>
Subject: Re: Yknow, the thing about perl is....
Message-Id: <34211A40.7652C37B@mail.org.uk>
Doug Seay wrote:
>
> Randal Schwartz wrote:
> >
> > >>>>> "Jason" == Jason Hazzard <hazzard@usa.net> writes:
> >
> > Jason> But, geez the thing about perl is, I can write a script, that
> > Jason> is say, about 200 lines long (I am doing one right now). Then,
> > Jason> when I actually utilize the real power of this language I can
> > Jason> boil it down to about 50 lines!
> >
> > Or show it to me, and I can probably get it down to 10 lines firing off
> > three fewer processes. :-)
>
> Are you implying that he has three useless 'cat's in his code?
Somebody else wrote somewhere in this group that Randal is entitled to
$0.05 for each of these occurences, towards his legal costs.
Ho hum,
Russ
---------------------------------------------------------------------
--[ R u s s e l l O d o m ]---[ *NEW:* mailto:russ@mail.org.uk ]--
--[ University of York, UK ]---[ http://www.york.ac.uk/~rjo100/ ]--
---------------------------------------------------------------------
--[ FAQ maintainer, news:comp.os.ms-windows.win95.moderated ]--
---------------------------------------------------------------------
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.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 1045
**************************************