[17088] in Perl-Users-Digest
Perl-Users Digest, Issue: 4500 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 2 21:15:35 2000
Date: Mon, 2 Oct 2000 18:15:20 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <970535720-v9-i4500@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 2 Oct 2000 Volume: 9 Number: 4500
Today's topics:
Re: starting with perl. (Martien Verbruggen)
Re: Strange behaviour with @{...} <ren.maddox@tivoli.com>
Re: Strange behaviour with @{...} (Martien Verbruggen)
substitution in multiple files? <valerie.dodson@searhc.org>
Re: substitution in multiple files? <valerie.dodson@searhc.org>
Testing for numeric integer <gdaniell@wt.com.au>
Re: Testing for numeric integer <tony_curtis32@yahoo.com>
Re: Testing for numeric integer (Richard J. Rauenzahn)
Re: Testing for numeric integer <lr@hpl.hp.com>
Re: Testing for numeric integer <tony_curtis32@yahoo.com>
Testing for undef in XS (Richard J. Rauenzahn)
This post should be a bit easier to answer <jbengard@chaincast.com>
Re: use Perl instead (was: Need sed or awk solution for <smooth1@iclway.co.uk>
Re: using PGP on a linux server via perl <bwalton@rochester.rr.com>
Re: using PGP on a linux server via perl <lr@hpl.hp.com>
Re: why it's called a "hash" (and a whole lot more) <dtweed@acm.org>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 3 Oct 2000 09:39:41 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: starting with perl.
Message-Id: <slrn8ti3lc.jr6.mgjv@martien.heliotrope.home>
On Mon, 02 Oct 2000 17:40:25 GMT,
Steve A. <sarbayo@telis.org> wrote:
> >> The correct name of the language is Perl.
>
> Joe, ignore this Elite-ist Bullshit !
> It doesn't matter !
> You can call it Perl, PERL, perl, purr'l, what ever you want !!!
> It's only the Elite-ists who care.
Is that so, Harry? You don't mind me calling you Harry, do you? After
all, it's only elitists that insist on using the correct name.
> >> > trying to get my scrips to save a data file. Are there any perl
>
> This must be added to the open command:
> "
> open (Handle, ">>guest_book.txt";
> print Handle $Data;
> close(Handle);
> "
> This code will append whatever information is in $Data to the
> "guest_book.txt" file.
You should always, always check the return value of an open() or any
system call for that matter. The convention in Perl is to use all
uppercase names for file handles.
open(GBOOK, '>>guest_book.txt') or
die "Cannot open guest_book.txt for append: $!";
> Also very simple:
> "
> open (Handle, "<guest_book.txt";
The < isn't necessary, and again, you should check for errors.
open(GBOOK, 'guest_book.txt') or
die "Cannot open guest_book.txt for read: $!";
> while(<Handle>) {
> print;
> $Data .= $_;
> }
> close(Handle);
Euhmm... Why are you printing each line to STDOUT, as well as appending
it to $Data? If you want all this stuff in $Data, then you could do
something much more efficient than what you're doing: Read all of it in
one do, and then print $Data.
{
local $/;
$data = <GBOOK>;
}
print $data;
> these lines of code will read in the entire "guest_book.txt" file,
Euhmm, that's slightly sloppily phrased. Your lines of code will read
the file line by line. As already noted, not the best thing to do if you
want to store the whole thing in a variable anyway.
> print it to screen/browser and put it in the string "$Data ", so that
> you can do whatever you want with it.
>
> > I tried to use www.annuna.com/cgi-bin/logs/logfile.txt.
>
> Ordinarily, if your perl.pl script is in /cgi-bin/ you dont need to
> use the entire URL.
> Only the " /logs/logfile.txt " should be required.
Huh? That makes hardly any sense. I think you are confused about what
you can pass to open(), which should be a real path, and what you can
tell the browser as part of a URL.
> So the above examples would read:
>
> ">/logs/logfile.txt" and "</logs/logfile.txt"
Oh really? Do you think you have the permissions to write in that
directory? Do you think it exists already? I doubt it. I personally have
seen very few systems that have directory named logs right under the
root directory. And even fewer that would allow CGI programs to write
there.
> Try these, they should work.
I would be very surprised if they did.
You do need to use the full path, because you don't even know what your
working directory will be, and you need to use the path as the SYSTEM
knows it. Not URLs or stuff like that.
Besides all that: If you have a program that can have multiple instance
running (and programs run via the CGI certainly qualify for that) and
that need to read and write the same file, you should use a locking
mechanism, unless you don't care about losing your data.
# perldoc -f flock
So, Harry, it looks that for someone who knows so much about perl and
Perl that he can decide how it is allowed to be spelled, you know
remarkably little about Perl, or general programming. Maybe you should
consider being a litttle less vocal until you've got some more practice,
and maybe a little more experience.
Martien
--
Martien Verbruggen |
Interactive Media Division | If at first you don't succeed, try
Commercial Dynamics Pty. Ltd. | again. Then quit; there's no use
NSW, Australia | being a damn fool about it.
------------------------------
Date: 02 Oct 2000 15:58:50 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Strange behaviour with @{...}
Message-Id: <m3ya07nenp.fsf@dhcp11-177.support.tivoli.com>
Volker Moell <moell@ID-PRO.de> writes:
> Thanks for your quick answer. But isn't it a little bit inconsequent,
> that
> foreach (@$a) {};
> shows this behaviour, but not
> my @b = @$a;
> ?
perl -we 'my $a; my @b = @$a'
Use of uninitialized value in array dereference at -e line 1.
How exactly does this not show the same behavior?
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Tue, 3 Oct 2000 10:47:18 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Strange behaviour with @{...}
Message-Id: <slrn8ti7k6.jr6.mgjv@martien.heliotrope.home>
On Mon, 02 Oct 2000 13:27:36 GMT,
Jim Mauldin <mauldin@netstorm.net> wrote:
>
> This behavior is expected, not strange. The construct @{$a} (which
> could be stated as @$a in this context) is not an operator. It is an
> anonymous array whose referenece is contained in $a. Merely using @{$a}
> in a statement causes the reference to spring into existence, even if
> the array is empty (Perl tries to be helpful).
Are you sure about that?
$ perl -wl
my $a;
my @foo = @{$a};
print $a;
__END__
Use of uninitialized value in array dereference at - line 2.
Use of uninitialized value in print at - line 3.
$
The autovivification only happens in certain cases. Not merely on the
use of a variable in a context where it _may_ contain an array
reference. It's probably only in spots where it must contain one. Which
spots they are is harder to identify easily.
I'd hardly call it intuitive or even expected. I'd expect it with push
and unshift, but not really with for.
Martien
--
Martien Verbruggen |
Interactive Media Division | That's not a lie, it's a
Commercial Dynamics Pty. Ltd. | terminological inexactitude.
NSW, Australia |
------------------------------
Date: Mon, 02 Oct 2000 16:48:36 -0800
From: Valerie Dodson <valerie.dodson@searhc.org>
Subject: substitution in multiple files?
Message-Id: <39D92CE4.6AB8DBAD@searhc.org>
I have multiple perl scripts that contain $name!@emailaddress within,
and I would like to replace @emailaddressdomain with
@newemailaddressdomain. Can someone please help me figure out how to do
this without having to edit each individual file seperately? Any help
is very much appreciated!
p.s. I tried this and it didn't seem to work:
perl -pi.bak -e `s/emailaddressdomain/newemailaddressdomain/g`
all files are in the same directory.
------------------------------
Date: Mon, 02 Oct 2000 16:50:59 -0800
From: Valerie Dodson <valerie.dodson@searhc.org>
Subject: Re: substitution in multiple files?
Message-Id: <39D92D73.D4C26947@searhc.org>
Valerie Dodson wrote:
> I have multiple perl scripts that contain $name!@emailaddress within,
> and I would like to replace @emailaddressdomain with
> @newemailaddressdomain. Can someone please help me figure out how to do
> this without having to edit each individual file seperately? Any help
> is very much appreciated!
>
> p.s. I tried this and it didn't seem to work:
>
> perl -pi.bak -e `s/emailaddressdomain/newemailaddressdomain/g`
>
> all files are in the same directory.
p.s. Please excuse my typo's in the first paragraph of my first message!
($name!@emailaddress should have been $name@emailaddressdomain).
------------------------------
Date: Tue, 03 Oct 2000 06:19:52 +0800
From: Graham Daniell <gdaniell@wt.com.au>
Subject: Testing for numeric integer
Message-Id: <39D90A08.74E2FA74@wt.com.au>
Can anyone tell me how I test that a field contains ONLY a number,
without any decimal point in it? ie: a number like 1 or 2 or 199? Or
where to look to find the answer?
It is for a web product ordering application and I want to ensure that
the user has entered a valid number of products, so I can multiply by
the unit price to get the total price.
Any help appreciated,
Graham Daniell
Perth, Western Australia
gdaniell@wt.com.au
------------------------------
Date: 02 Oct 2000 17:29:28 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Testing for numeric integer
Message-Id: <87puli7u7r.fsf@limey.hpcc.uh.edu>
>> On Tue, 03 Oct 2000 06:19:52 +0800,
>> Graham Daniell <gdaniell@wt.com.au> said:
> Can anyone tell me how I test that a field contains ONLY
> a number, without any decimal point in it? ie: a number
> like 1 or 2 or 199? Or where to look to find the
> answer?
Turn the problem around:
a number = a string of all digits
= a string not containing a non-digit.
if ($potential_num !~ /\D/) {
# it's a number
} else {
# fail
}
(perldoc perlre if \D isn't obvious)
hth
t
--
Namaste!
And an "oogabooga" to you too!
-- Homer Simpson
------------------------------
Date: 2 Oct 2000 22:31:46 GMT
From: nospam@hairball.cup.hp.com (Richard J. Rauenzahn)
Subject: Re: Testing for numeric integer
Message-Id: <970525906.81645@hpvablab.cup.hp.com>
Have you read the perl FAQ recently?
$ perldoc -q number
Rich
gdaniell@wt.com.au writes:
>Can anyone tell me how I test that a field contains ONLY a number,
>without any decimal point in it? ie: a number like 1 or 2 or 199? Or
>where to look to find the answer?
>
>It is for a web product ordering application and I want to ensure that
>the user has entered a valid number of products, so I can multiply by
>the unit price to get the total price.
>
>Any help appreciated,
>Graham Daniell
>Perth, Western Australia
>gdaniell@wt.com.au
--
Rich Rauenzahn ----------+xrrauenza@cup.hp.comx+ Hewlett-Packard Company
Technical Consultant | I speak for me, | 19055 Pruneridge Ave.
Development Alliances Lab| *not* HP | MS 46TU2
ESPD / E-Serv. Partner Division +--------------+---- Cupertino, CA 95014
------------------------------
Date: Mon, 2 Oct 2000 16:24:55 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Testing for numeric integer
Message-Id: <MPG.1442b91db01a457798adf5@nntp.hpl.hp.com>
In article <87puli7u7r.fsf@limey.hpcc.uh.edu> on 02 Oct 2000 17:29:28 -
0500, Tony Curtis <tony_curtis32@yahoo.com> says...
> >> On Tue, 03 Oct 2000 06:19:52 +0800,
> >> Graham Daniell <gdaniell@wt.com.au> said:
>
> > Can anyone tell me how I test that a field contains ONLY
> > a number, without any decimal point in it? ie: a number
> > like 1 or 2 or 199? Or where to look to find the
> > answer?
>
> Turn the problem around:
>
> a number = a string of all digits
> = a string not containing a non-digit.
>
> if ($potential_num !~ /\D/) {
> # it's a number
> } else {
> # fail
> }
Is the null string ("") indeed a number? :-)
I think for this particular problem the simple positive assertion is
better:
/^\d+\z/
or, perhaps,
/^\s*\d+\s*\z/
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 02 Oct 2000 18:44:02 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Testing for numeric integer
Message-Id: <87n1gm7qrh.fsf@limey.hpcc.uh.edu>
>> On Mon, 2 Oct 2000 16:24:55 -0700,
>> Larry Rosler <lr@hpl.hp.com> said:
> Is the null string ("") indeed a number? :-)
Debatable :-)
OTOH I'm not convinced that the null string is either a
number or not-a-number. Clearly I've lost my CS roots, as
I no longer automatically consider the 0/1 case for string
lengths. What's the correct penanace for this?
Installing Pascal? :-)
--
Namaste!
And an "oogabooga" to you too!
-- Homer Simpson
------------------------------
Date: 2 Oct 2000 21:57:23 GMT
From: nospam@hairball.cup.hp.com (Richard J. Rauenzahn)
Subject: Testing for undef in XS
Message-Id: <970523843.116197@hpvablab.cup.hp.com>
I'd like to test an SV * parameter in my XSUB for undefinedness.
I can't find this documented in perlguts or perlxs, and sv.h doesn't
make it clearer either.
I've found example code[1] that compares the SV *arg against
&PL_sv_undef, but that seems wrong (I tried it anyway, and my testing
confirms it.)
So -- what is the best way of testing an SV for undefinedness?
Thanks,
Rich
[1] 'find . -name \*.xs | xargs grep PL_sv_undef | grep ==' turns up a
few of these in some xs modules that ship with Perl v5.6.0
--
Rich Rauenzahn ----------+xrrauenza@cup.hp.comx+ Hewlett-Packard Company
Technical Consultant | I speak for me, | 19055 Pruneridge Ave.
Development Alliances Lab| *not* HP | MS 46TU2
ESPD / E-Serv. Partner Division +--------------+---- Cupertino, CA 95014
------------------------------
Date: Mon, 2 Oct 2000 16:35:49 -0700
From: "James Bengard" <jbengard@chaincast.com>
Subject: This post should be a bit easier to answer
Message-Id: <yY8C5.7542$Q66.4510624@nnrp5-w.sbc.net>
I posted a question last night which I figured out how to do, I am now left
with a problem that I can solve:
I am loading the following information into an array:
<chain chainid="19-2" broadcasting="yes" streamwidth="3645">
<transmitter numchildren="15" numpending="0" maxchildren="26"
numfailures="0" nodeid="130.191.77.177:80">
<repeater numchildren="0" numpending="0" maxchildren="54" numfailures="0"
nodeid="216.104.230.124:8002">
<repeater numchildren="0" numpending="0" maxchildren="54" numfailures="0"
nodeid="216.104.230.126:8002">
<repeater numchildren="0" numpending="0" maxchildren="54" numfailures="0"
nodeid="216.104.230.125:8004">
<repeater numchildren="0" numpending="0" maxchildren="54" numfailures="0"
nodeid="216.104.230.119:8005">
<chain chainid="9-1" broadcasting="yes" streamwidth="3645">
<transmitter numchildren="11" numpending="0" maxchildren="27"
numfailures="0" nodeid="206.169.185.32:80">
<chain chainid="25-4" broadcasting="yes" streamwidth="3645">
<transmitter numchildren="8" numpending="0" maxchildren="52" numfailures="0"
nodeid="128.197.245.45:80">
<chain chainid="7-2" broadcasting="yes" streamwidth="3645">
<transmitter numchildren="10" numpending="0" maxchildren="26"
numfailures="0" nodeid="206.14.3.202:80">
<repeater numchildren="0" numpending="0" maxchildren="54" numfailures="0"
nodeid="216.104.230.125:8008">
<repeater numchildren="0" numpending="0" maxchildren="54" numfailures="0"
nodeid="216.104.230.119:8000">
<repeater numchildren="0" numpending="0" maxchildren="54" numfailures="0"
nodeid="216.104.230.124:8000">
<repeater numchildren="0" numpending="0" maxchildren="54" numfailures="0"
nodeid="216.104.230.126:8005">
I need to get the IP and port off of this information
Ultimatly I would like to accomplish the following:
put all IP address in a file
and output the following data for output on a webpage
example output for web
chainid="19-2
IPAddress and port of all transmitters and repeaters for particular chain.
Thank you in advance.
------------------------------
Date: Mon, 2 Oct 2000 23:48:27 +0100
From: "smooth1" <smooth1@iclway.co.uk>
Subject: Re: use Perl instead (was: Need sed or awk solution for recursive html site.)
Message-Id: <39d910c2$1_3@news2.vip.uk.com>
Reinier Post wrote in message <8r9ogo$k71$1@news.tue.nl>...
>>
>> sed 1,/Total/d sizes | awk '{ total += $6 } END { print total }'
>
> perl -nle '1../Total/ or $total += (split)[5]; END {print $total}' sizes
>
??? This is why I prefer sed + awk
sed(+grep) = clean up the lines + pick the lines you want
awk = print the bits you want to print
(split)[5] but I want to print the 6th word not the fifth!
>[Followups set to comp.lang.perl.misc]
>
>>Russ Allbery (rra@stanford.edu) <http://www.eyrie.org/~eagle/>
>
>--
>Reinier Post reinpost@win.tue.nl
------------------------------
Date: Mon, 02 Oct 2000 23:34:41 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: using PGP on a linux server via perl
Message-Id: <39D91B9A.C48F6DA3@rochester.rr.com>
Jim Wright wrote:
...
> open(PH, "pgps -u me@mydomain.net -taf -z mypassphrase preSign.txt|");
Just guessing: might the difference actually be that the @ attempts an
interpolation of variable @mydomain which probably substitutes null.
Since the user is then different, pgp will probably make the whole
encoding different. You may have attributed that to the wrong cause.
The solution would be to escape the @ with a \, as in ...me\@mydomain...
HTH.
...
> Jim
...
--
Bob Walton
------------------------------
Date: Mon, 2 Oct 2000 17:04:57 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: using PGP on a linux server via perl
Message-Id: <MPG.1442c28814383f9d98adf7@nntp.hpl.hp.com>
In article <39D91B9A.C48F6DA3@rochester.rr.com> on Mon, 02 Oct 2000
23:34:41 GMT, Bob Walton <bwalton@rochester.rr.com> says...
> Jim Wright wrote:
> ...
> > open(PH, "pgps -u me@mydomain.net -taf -z mypassphrase preSign.txt|");
>
> Just guessing: might the difference actually be that the @ attempts an
> interpolation of variable @mydomain which probably substitutes null.
> Since the user is then different, pgp will probably make the whole
> encoding different. You may have attributed that to the wrong cause.
> The solution would be to escape the @ with a \, as in ...me\@mydomain...
The better solution would be to use single-quotes for strings that
contain neither interpolations nor escape sequences.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 02 Oct 2000 14:25:11 -0400
From: Dave Tweed <dtweed@acm.org>
Subject: Re: why it's called a "hash" (and a whole lot more)
Message-Id: <39D8D307.57AA84A3@acm.org>
Ilya Zakharevich wrote:
> (BTW, this + is a misprint. I wanted it to be |, but it was late, and
> my fingers slipped... With | it is a one-to-one mapping - so gives
> less surprises in the "quality of hashing" arguments.)
>
> Here is how I want to change it. Why hash | (hash >> 5) is performed?
> To increase "randomness" of low-order bits (those bits which are used
> for actual bucket number!) Let increase randomness of high-order bits
> instead:
>
> hash |= (hash << 5);
> hash |= (hash << 11);
> hash |= (hash << 29);
Why | and not ^ (or +, which is nearly the same)? It seems to me
that | would create a bias towards buckets that have more ones in
their indices.
-- Dave Tweed
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 4500
**************************************