[10267] in Perl-Users-Digest
Perl-Users Digest, Issue: 3860 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 30 17:27:24 1998
Date: Wed, 30 Sep 98 14:00:17 -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 Wed, 30 Sep 1998 Volume: 8 Number: 3860
Today's topics:
Clarification of $_ please <jason.holland@dial.pipex.com>
Re: Clarification of $_ please (Greg Bacon)
Re: Clarification of $_ please <jdporter@min.net>
Re: Coding Standards? (Stefan Scholl)
Re: Coding Standards? <uri@camel.fastserv.com>
elements of an array passed as args to embedded expect. mmurphy@infomedics.com
Hangs - Netscape Enterprise Server 3.51 / Sybase web.sq <scott@mtnlake.com>
Re: Hangs - Netscape Enterprise Server 3.51 / Sybase we <eashton@bbnplanet.com>
Re: lightweight date checker NOT DATE::MANIP droby@copyright.com
Re: Need IP Address Sort Subroutine (Kevin Reid)
Re: Need IP Address Sort Subroutine <jdporter@min.net>
Re: Need method to round real number to two decimal pla (Yuri Ralchenko)
Re: Need method to round real number to two decimal pla <uri@camel.fastserv.com>
Perl for PC & select. (Wayne C. McCullough)
Re: Probably an easy Image vs Test question (Bart Lateur)
Re: restricting script execution? <eashton@bbnplanet.com>
Re: SRC: encrypt your Perl scripts! :-) (Kevin Reid)
Re: SRC: encrypt your Perl scripts! :-) (Greg Bacon)
Re: Substitution-Problem (Kevin Reid)
Re: URL & strings searches droby@copyright.com
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 30 Sep 1998 20:58:28 +0000
From: Jason Holland <jason.holland@dial.pipex.com>
Subject: Clarification of $_ please
Message-Id: <36129B74.3E4AD440@dial.pipex.com>
Hello all,
Not really urgent, but could someone give me a minor clarification of
the scope of the $_ variable?
For instance, if I do this:
my $string = "hello world!";
m/world/i; # $_ hopefully now contains
"world"
BLOCK: foreach ( "one", "two", "three" ) {
print "$_\n"; # Pollute $_
}
print "$_\n"; # Previous "world", or
"three" from BLOCK?
Do you get my point? Does the $_ variable within the BLOCK mask the
outer $_ variable, or does it wipe it out. Are there multiple $_
variables within subsequent nested blocks, or just one?
I've wanted to do this a couple of times now, mainly because I could not
be bothered to define a new scratch variable. Wasn't sure of the outcome
though, so I erred on the safe side.
Just interested...
Thanks, bye!
--
sub jasonHolland {
my %hash = ( website =>
'http://dspace.dial.pipex.com/jason.holland/',
email => 'jason.holland@dial.pipex.com' );
}
------------------------------
Date: 30 Sep 1998 20:25:24 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
Subject: Re: Clarification of $_ please
Message-Id: <6uu43k$564$2@info.uah.edu>
In article <36129B74.3E4AD440@dial.pipex.com>,
Jason Holland <jason.holland@dial.pipex.com> writes:
: For instance, if I do this:
:
: my $string = "hello world!";
: m/world/i; # $_ hopefully now contains "world"
No, certainly not. $_ (the default operand of m//) is undefined.
Turning on -w would have emitted a warning here.
You want to bind the match to $string like
$string =~ m/world/i;
Reading the perlre manpage or the Camel or the Llama (have you read any
of these?) would tell you that $& would contain world (or some casewise
variation) after this statement executed.
: BLOCK: foreach ( "one", "two", "three" ) {
: print "$_\n"; # Pollute $_
: }
No, this would not pollute $_. This is in the perlsyn manpage, under
the Foreach Loops section:
The foreach loop iterates over a normal list value and sets the
variable VAR to be each element of the list in turn. If the
variable is preceded with the keyword my, then it is lexically
scoped, and is therefore visible only within the loop. Otherwise,
the variable is implicitly local to the loop and regains its former
value upon exiting the loop.
: print "$_\n"; # Previous "world", or "three" from BLOCK?
Assuming your program began with `my $string...', $_ would be undefined
at this point.
: Do you get my point? Does the $_ variable within the BLOCK mask the
: outer $_ variable, or does it wipe it out. Are there multiple $_
: variables within subsequent nested blocks, or just one?
The perlsyn manpage talks about this.
: I've wanted to do this a couple of times now, mainly because I could not
: be bothered to define a new scratch variable.
Couldn't be bothered? I'm not sure I understand that.
: Wasn't sure of the outcome
: though, so I erred on the safe side.
Before you mentioned that your problem isn't urgent, but if you want to
continue using Perl, it is urgent that you go out and read a copy of
the Llama book (Learning Perl by Schwartz and Christiansen).
Greg
--
If crime fighters fight crime, and firefighters fight fire, what do freedom
fighters fight? They never mention that part to us, do they?
-- George Carlin
------------------------------
Date: Wed, 30 Sep 1998 16:41:32 -0400
From: John Porter <jdporter@min.net>
Subject: Re: Clarification of $_ please
Message-Id: <3612977C.A8C9CA2D@min.net>
Jason Holland wrote:
>
> could someone give me a minor clarification of
> the scope of the $_ variable?
>
> For instance, if I do this:
>
> my $string = "hello world!";
> m/world/i; # $_ hopefully now contains "world"
>From the context, I'm guessing you meant to say
my $_ = "hello world!";
And if you then say
m/world/i;
you're testing $_, but throwing away the result...
> BLOCK: foreach ( "one", "two", "three" ) {
> print "$_\n"; # Pollute $_
> }
> print "$_\n"; # Previous "world", or "three" from BLOCK?
Did you try it? That would be a pretty easy way to find
out the answer! :-)
> Do you get my point? Does the $_ variable within the BLOCK mask the
> outer $_ variable, or does it wipe it out.
$_ is a global variable.
A foreach loop, if it uses $_ as its iteration variable,
"localizes" the value of $_; that is, it saves the existing
value, so that it can be restored at the end of the loop.
That is the same as the effect of the "local" operator.
> Are there multiple $_
> variables within subsequent nested blocks, or just one?
There's only one $_, it's global; but through value
"localization", it can serve a different purpose temporarily,
then return to its previous value.
> I've wanted to do this a couple of times now, mainly because I
> could not be bothered to define a new scratch variable.
Laziness is one of the three cardinal virtues...
> Wasn't sure of the outcome though, so I erred on the safe side.
Try it out and see what happens. Then RTFM! That's how you learn.
hth
--
John "Many Jars" Porter
------------------------------
Date: 30 Sep 1998 18:05:31 GMT
From: stesch@parsec.rhein-neckar.de (Stefan Scholl)
Subject: Re: Coding Standards?
Message-Id: <slrn714snb.vtq.stesch@parsec.rhein-neckar.de>
On 29 Sep 1998 12:48:40 GMT, Ken Rich <kenr@troi.cc.rochester.edu> wrote:
> In comp.lang.perl.misc, lemull@unx.sas.com writes:
> :Can anyone point me to a set of Coding Standards developed
> :specifically for Perl?
>
> Not perl specific, but Steve McConnell's (?) book __Code Complete__
> from Microsoft Press has really great recommendations on coding
^^^^^^^^^
> standards, that bear a striking resemblance to man perlstyle, but
> goes further in the good directions.
Yeah, right. :-)
------------------------------
Date: 30 Sep 1998 16:58:48 -0400
From: Uri Guttman <uri@camel.fastserv.com>
Subject: Re: Coding Standards?
Message-Id: <sar67e5tj07.fsf@camel.fastserv.com>
>>>>> "SS" == Stefan Scholl <stesch@parsec.rhein-neckar.de> writes:
SS> On 29 Sep 1998 12:48:40 GMT, Ken Rich <kenr@troi.cc.rochester.edu>
SS> wrote:
>> In comp.lang.perl.misc, lemull@unx.sas.com writes: :Can anyone
>> point me to a set of Coding Standards developed :specifically for
>> Perl?
>>
>> Not perl specific, but Steve McConnell's (?) book __Code Complete__
>> from Microsoft Press has really great recommendations on coding
SS> ^^^^^^^^^
>> standards, that bear a striking resemblance to man perlstyle, but
>> goes further in the good directions.
SS> Yeah, right. :-)
it is actually a good book and i hate u$hit as much as anyone. but i
didn't make uncle bill any more profits as i acquired it from a previous
employer some time ago. :-)
uri
--
Uri Guttman Fast Engines -- The Leader in Fast CGI Technology
uri@fastengines.com http://www.fastengines.com
------------------------------
Date: Wed, 30 Sep 1998 19:53:38 GMT
From: mmurphy@infomedics.com
Subject: elements of an array passed as args to embedded expect.
Message-Id: <6uu282$7t7$1@nnrp1.dejanews.com>
Hi, I'm able to set the contents
of a given file into an array.
I can then print each line separately
to stdout.
How do I pass each element of a given line
as an argument to another (embedded) script.
So I'd have multiple lines like this:
cust,job1,job2,dat1,dat2,dat3,dat4
And I want to pull one line, split on /,/
set $var1
$var2
$var3
(etc...)
and pass them to an embedded expect script.
(it works if hardcoded...)
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 29 Sep 1998 14:55:47 -0400
From: Scott McIntosh <scott@mtnlake.com>
Subject: Hangs - Netscape Enterprise Server 3.51 / Sybase web.sql 1.2 / Solaris 2.6
Message-Id: <36112D33.8D282585@mtnlake.com>
We're having a problem with a production deployment of Sybase
web.sql on Solaris.
Here are the versions of the pieces involved:
Solaris 2.6 (patch list at bottom)
Netscape Enterprise Server 3.51, patch level G
Sybase Web.sql v1.2 (with OpenClient 11.1.0, Perl 5.001m, NSAPI)
Sybase SQL Server 11.0.1
Using Solaris 2.6 is -not- one of the Sybase recommended configurations
for web.sql:
http://www.sybase.com/websql/docs/sol12GA/docs/release.htm#MARKER-9-32
...but we've been forced down this road for other Y2K reasons.
Our problem is that the Netscape web server hangs in an unpredictable
way. It doesn't seem to be related to a given page request, and doesn't
happen at predictable intervals. SQL Server is generally behaving
quite well. The one similarity, is that the pstack for ns-httpd looks
about the same each time it hangs (see below). Perl_sv_grow() attempts
to resize a string, and then blocks while trying to allocate more
memory. After this, the web server won't respond to any more requests.
We're not sure whether a web.sql thread is dead-locking with one of its
own, or with something else. Perhaps we have a bad combination of
Solaris patches and ns-httpd revs? We're stuck.
Of course our big problem is that we don't have the source code for Sybase's
web.sql product in order to debug the problem. Has anyone encountered similar
problems or have any suggestions?
-Scott
>>>>>>>>>>>>stopping https-green at Tue Sep 8 20:29:18 EDT 1998<<<<<<<<<<<<<<
Server https-green restarted successfully at Tue Sep 8 20:29:24 EDT
1998: UID PID PPID C STIME TTY TIME CMD
nobody 15054 1 0 20:29:22 ? 0:00 ./uxwdog -d
/opt/suitespot/https-green/config
>>>>>>>>>>>>stopping https-secure at Tue Sep 8 20:29:24 EDT 1998<<<<<<<<<<<<<<
======
UID PID PPID C STIME TTY TIME CMD
nobody 8208 1 0 15:14:43 ? 0:00 ns-httpd -d
/opt/suitespot/https-secure/config
killing 8208...
PID TTY TIME CMD
8208 ? 0:00 ns-httpd
Resisting TERM, getting pstack dump...
8208: ns-httpd -d /opt/suitespot/https-secure/config
lwp#1 ----------
ef1362ac sigtimedwait (ebdee894, 0, 0)
ef1362ac _libc_sigtimedwait (ebdee894, 0, 0, ebdee827, 81010100, ff00) + 4
ef3499b8 _panic (ef366048, ef366214, ef365250, 7efefeff, 81010100, ff00) +
10c
ef351d4c sigacthandler (b, ebdeee78, ebdf3de0, ef365250, ebdeebc0, 0) + 15c
ef348714 _mutex_adaptive_lock (ef1a72d0, 4c00, ef365250, 1, 4d58, fffeffff)
+ 84
ef3484f8 _ti_pthread_mutex_lock (ef1a72d0, ef365250, 0, 0, 0, 0) + 3c
ef1459f0 malloc (29, 0, 200000, ee31a2a8, 0, 0) + 18
ee31ad38 Perl_sv_grow (12b628, 29, 0, 0, 0, 0) + 80
ee31d604 Perl_sv_setpvn (12b628, 2b2898, 28, 7efefeff, 81010100, ff0000) +
1a4
ee320278 Perl_newSVpv (2b2898, 28, 0, 0, 0, 0) + 58
ee2e2b44 perl_call_argv (ee7f94d0, 6, ebdf3c20, 0, 0, ee7c94e8) + a4
ee7e2a04 ws__service_main (ebdf3c20, 28dbb0, 2ee100, aadd0, 0, 0) + 22c
ee7e359c ws_service (aadd0, 2ee100, 28dbb0, ffffffff, 0, 0) + a4
ef70a680 __0Fcfunc_native_pool_thread_mainPv (0, 0, a, ef365250, 8, 0) + 88
ef5a7a94 _PR_NativeRunThread (293938, 8, 2, 293988, 293988, ef5ad800) + 104
ef354bdc _thread_start (293938, 0, 0, 0, 0, 0) + 3c
lwp#2 ----------
ef14da1c sigvalid (f, ef1a94e4, ef1a2e8c, 0, 0, 0) + 2c
ef14db00 _sigaddset (ef36e2c4, f, 0, 0, 0, 0) + 4
ef34b06c _sigredirect (f, ef3663b8, ef36e2c4, ef365250, 0, 0) + 38
ef34b4b4 _dynamiclwps (ef365250, 0, 0, 10fd50, 2abb38, 2b30b8) + 104
ef34e0ec _ti_thr_yield (0, 0, 0, 0, 0, 0) + 8c
lwp#3 ----------
ef1396a0 lwp_sema_p (e930de80)
ef1396a0 __lwp_sema_wait (e930de80, 1d640, 0, 0, 0, 0) + 8
ef34776c _park (e930dde0, e930de80, 0, 1, ef3661d8, 0) + a0
ef347524 _swtch (e930ddf0, e930dfe0, e930de60, e930de5c, e930de58,
e930de54) + 2cc
ef34a75c _reap_wait (ef366d68, 1ad98, 0, 0, 0, 0) + 34
ef34a4e8 _reaper (ef365250, ef366d68, ef366228, ef36dea0, 0, fe400000) + 34
ef354bdc _thread_start (0, 0, 0, 0, 0, 0) + 3c
=finished pstack
getting pflags dump...
8208: ns-httpd -d /opt/suitespot/https-secure/config
flags = PR_ORPHAN
sigpend = 0x00004000,0x00000000
/1: flags = PR_PCINVAL|PR_ASLEEP [ sigtimedwait(0xebdee894,0x0,0x0) ]
sigmask = 0x00400102,0xffffe000
/2: flags = PR_PCINVAL|PR_ASLWP|PR_ASLEEP [ lwp_mutex_lock(0xef3698b8) ]
sigmask = 0xffbffeff,0x00001fff
/3: flags = PR_PCINVAL|PR_ASLEEP [ lwp_sema_p(0xe930de80) ]
=finished pflags
getting pfiles dump...
8208: ns-httpd -d /opt/suitespot/https-secure/config
Current rlimit: 1024 file descriptors
0: S_IFIFO mode:0000 dev:185,0 ino:402082 uid:0 gid:1 size:0
O_RDWR
1: S_IFIFO mode:0000 dev:185,0 ino:404392 uid:60001 gid:60001 size:0
O_RDWR
2: S_IFIFO mode:0000 dev:185,0 ino:404392 uid:60001 gid:60001 size:0
O_RDWR
3: S_IFIFO mode:0000 dev:185,0 ino:402083 uid:60001 gid:60001 size:0
O_RDWR
4: S_IFCHR mode:0666 dev:85,10 ino:48885 uid:0 gid:3 rdev:13,12
O_RDWR
5: S_IFREG mode:0644 dev:0,1 ino:201556776 uid:60001 gid:60001 size:0
O_RDWR|O_NONBLOCK
6: S_IFIFO mode:0000 dev:185,0 ino:402084 uid:60001 gid:60001 size:0
O_RDWR
7: S_IFREG mode:0644 dev:85,32 ino:253986 uid:60001 gid:60001 size:103356
O_RDWR|O_NONBLOCK|O_APPEND
8: S_IFREG mode:0644 dev:85,32 ino:476176 uid:0 gid:1 size:131072
O_RDONLY FD_CLOEXEC
9: S_IFREG mode:0644 dev:85,32 ino:254075 uid:60001 gid:60001 size:3173452
O_RDWR|O_NONBLOCK|O_APPEND FD_CLOEXEC
10: S_IFSOCK mode:0666 dev:186,0 ino:33232 uid:0 gid:0 size:0
O_RDWR FD_CLOEXEC
11: S_IFREG mode:0666 dev:0,1 ino:202902262 uid:60001 gid:60001 size:229412
O_RDWR|O_NONBLOCK
12: S_IFREG mode:0640 dev:85,32 ino:79424 uid:60001 gid:60001 size:65536
O_RDONLY FD_CLOEXEC
13: S_IFREG mode:0600 dev:0,1 ino:202901560 uid:60001 gid:60001
size:1280000
O_RDWR
14: S_IFREG mode:0600 dev:0,1 ino:202901612 uid:60001 gid:60001
size:1024000
O_RDWR
15: S_IFREG mode:0444 dev:85,10 ino:89536 uid:0 gid:3 size:680
O_RDONLY
16: S_IFREG mode:0644 dev:0,1 ino:202901898 uid:60001 gid:60001 size:0
O_RDWR|O_NONBLOCK
29: S_IFSOCK mode:0666 dev:186,0 ino:37072 uid:0 gid:0 size:0
O_RDWR|O_NONBLOCK FD_CLOEXEC
47: S_IFSOCK mode:0666 dev:186,0 ino:34768 uid:0 gid:0 size:0
O_RDWR|O_NONBLOCK
65: S_IFIFO mode:0000 dev:185,0 ino:402093 uid:60001 gid:60001 size:0
O_RDWR|O_NDELAY
66: S_IFIFO mode:0000 dev:185,0 ino:402093 uid:60001 gid:60001 size:0
O_RDWR|O_NDELAY
67: S_IFCHR mode:0000 dev:85,10 ino:61152 uid:0 gid:0 rdev:42,6202
O_RDWR|O_NDELAY
68: S_IFCHR mode:0000 dev:85,10 ino:3128 uid:0 gid:0 rdev:42,6207
O_RDWR|O_NDELAY
69: S_IFCHR mode:0000 dev:85,10 ino:5440 uid:0 gid:0 rdev:42,6212
O_RDWR|O_NDELAY
pfiles finished. sending KILL...done
=========================================================================
Solaris 2.5 Patches Applied
=========================================================================
105181-05: SunOS 5.6: kernel update patch
105210-06: SunOS 5.6: libc & watchmalloc patch
105216-03: SunOS 5.6: /usr/sbin/rpcbind patch
105379-04: SunOS 5.6: /kernel/misc/nfssrv patch
105393-03: SunOS 5.6: /usr/bin/at patch
105401-11: SunOS 5.6: libnsl and NIS+ commands patch
105490-04: SunOS 5.6: linker patch
105529-04: SunOS 5.6: /kernel/drv/tcp patch
105615-03: SunOS 5.6: /usr/lib/nfs/mountd patch
105654-03: SunOS 5.6: driver_aliases/driver_classes/name_to_major patch
105665-01: SunOS 5.6: /usr/bin/login patch
105667-01: SunOS 5.6: /usr/bin/rdist patch
105720-03: SunOS 5.6: /kernel/fs/nfs patch
105755-05: SunOS 5.6: in.named & libresolv patch
105786-05: SunOS 5.6: /kernel/drv/ip patch
106033-01: SunOS 5.6: /usr/sbin/cron patch
106049-01: SunOS 5.6: /usr/sbin/in.telnetd patch
106125-02: SunOS 5.6: Patch for patchadd and patchrm
106271-02: SunOS 5.6: /usr/lib/security/pam_unix.so.1 patch
106301-01: SunOS 5.6: /usr/sbin/in.ftpd patch
------------------------------
Date: Wed, 30 Sep 1998 19:30:09 GMT
From: Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com>
Subject: Re: Hangs - Netscape Enterprise Server 3.51 / Sybase web.sql 1.2 / Solaris 2.6
Message-Id: <3612844F.945CE85E@bbnplanet.com>
Scott McIntosh wrote:
> Of course our big problem is that we don't have the source code for Sybase's
> web.sql product in order to debug the problem. Has anyone encountered similar
> problems or have any suggestions?
We have a client that has been wanting to use the web.sql application
and we are having much the same problem as you are with it. Currently
Sybase has one or two engineers trying to debug the problem for us. This
may be totally unrelated to your problem but I would recommend calling
technical support and send them that stack dump.
P.S. How did Sybase and Solaris equal comp.lang.perl.misc?
e.
"All of us, all of us, all of us trying to save our immortal souls, some
ways seemingly more round-about and mysterious than others. We're having
a good time here. But hope all will be revealed soon." R. Carver
------------------------------
Date: Wed, 30 Sep 1998 19:25:37 GMT
From: droby@copyright.com
Subject: Re: lightweight date checker NOT DATE::MANIP
Message-Id: <6uu0jh$5rv$1@nnrp1.dejanews.com>
In article <6urrai$g6g$1@nnrp1.dejanews.com>,
mizpoon@my-dejanews.com wrote:
> hi there. I'm looking for a very quick function to confirm whether a date is a
> valid one. basically I want to check if '2/31/1998' is a valid date or not.
>
Checking date validity is highly dependent on your calendar system. It's much
easier if you just use Abigail's calendar. The Roman numerals get a little
confusing, but there you go.
> currently I'm using Date::Manip to do this, but this module is HUGE and takes
> a considerable amount of time to return.
>
> does anyone else know a cheap alternative to this?
>
Yes. I think I did something like this for a class assignment in Fortran as a
freshman eons before the eternal September began lo these many years ago...
Actually, I think that one had to compute days of the week so it could print a
pretty calendar with a Snoopy picture, but we can leave those out. It was Y2K
compliant too! And a quarter century before Y2K was needed (compute that as a
Reesian approximation, to coin another new terminology).
I've mislaid the deck, but I'm sure I can do it again in Perl, and my rates
are quite reasonable.
It's really not hard, and if you're an aspiring programmer, you really should
try to do it yourself. If you're not an aspiring programmer, well perhaps you
should hire one...
> please reply to pouneh@wired.com as I don't read this newsgroup that often...
>
*plonk*
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 30 Sep 1998 15:16:55 -0400
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: Need IP Address Sort Subroutine
Message-Id: <1dg4v3a.1cjfe981237ytoN@slip166-72-108-178.ny.us.ibm.net>
Joe Williams <willliams@clark.net> wrote:
> Does anyone have, or can anyone me toward a routine that will sort IP
> addresses? Many thanks.
#!perl -w
@ips = qw(
213.135.67.36
192.45.120.4
192.46.240.45
14.30.16.0
108.162.155.80
213.53.67.242
108.162.33.65
14.150.47.46
);
@sips =
map {join '.', unpack 'C4', $_}
sort
map {pack 'C4', split /\./, $_}
@ips;
print join "\n", @sips, '';
__END__
Doesn't handle all cases, but pretty fast.
BTW, I didn't use inet_ntoa() because when I tried it, it started my PPP
connection (probably because it wanted to talk to a DNS).
--
Kevin Reid. | Macintosh.
"I'm me." | Think different.
------------------------------
Date: Wed, 30 Sep 1998 16:14:29 -0400
From: John Porter <jdporter@min.net>
Subject: Re: Need IP Address Sort Subroutine
Message-Id: <36129125.3CC3034F@min.net>
Uri Guttman wrote:
>
> i wasn't trying to speed things up. but i wonder what is slow about
> it. if inet_aton is about the same speed as pack/split, then inet_ntoa
> must be a pig. maybe an unpack/join would be much faster. john could
> you benchmark that and post all the results?
Here are the functions; benchmarks follow.
sub ntoa_aton {
my @args = @_;
map{ inet_ntoa($_) }
sort
map{ inet_aton($_) }
@args;
}
sub ntoa_pack {
my @args = @_;
map{ inet_ntoa($_) }
sort
map{ pack("C4",split(/\./,$_)) }
@args;
}
sub unpk_aton {
my @args = @_;
map{ join '.',unpack("C4",$_) }
sort
map{ inet_aton($_) }
@args;
}
sub unpk_pack {
my @args = @_;
map{ join '.',unpack("C4",$_) }
sort
map{ pack("C4",split(/\./,$_)) }
@args;
}
sub sort_aton {
my @args = @_;
sort {
inet_aton($a)
cmp
inet_aton($b)
} @args
}
sub sort_pack {
my @args = @_;
sort {
pack("C4",split(/\./,$a))
cmp
pack("C4",split(/\./,$b))
} @args
}
(4 iterations, sorting a list of 10,000 addresses:)
aton pack
unpk_ 22 32
ntoa_ 16 25
sort_ 1 1
>From this we can see that inet_aton() is faster than pack(split()),
in these cases, and that inet_ntoa() is faster than join(unpack()).
But we also see that doing a map/sort/map is MUCH slower than doing
a sort with an appropriate comparison inside... probably because of
the temporary lists that have to be created -- among other reasons.
(400 iterations:)
sort_aton: 103
sort_pack: 96
Interestingly, pack(split()) appears to be faster than inet_aton()
in this situation.
--
John "Many Jars" Porter
------------------------------
Date: 30 Sep 1998 20:18:39 GMT
From: fnralch@plasma-gate.weizmann.ac.il (Yuri Ralchenko)
Subject: Re: Need method to round real number to two decimal places
Message-Id: <6uu3mv$b77$1@news.huji.ac.il>
In article <MPG.107ac88dfa70552d9897cb@nntp.hpl.hp.com>,
lr@hpl.hp.com (Larry Rosler) writes:
> [Posted to comp.lang.perl.misc and a copy mailed.]
>
.......
> Why is using sprintf _not_ an option, to get the rounded value into a
> variable that can then used for further calculations?
>
> However, if the value is not negative, you can use:
>
> $rounded = int(100 * $number + 0.5) / 100;
>
> but why bother? Use:
>
> $rounded = sprintf '%.2f', $number;
>
Doesn't necessarily work. How about this problem:
perl -e '$a=0.705;printf "ans=%.2f",$a' gives ans=0.70
perl -e '$a=0.805;printf "ans=%.2f",$a' gives ans=0.81
Quite misteriously (at least for me), 0.105, 0.205, 0.305 and 0.605 behave like
0.705, while 0.005, 0.405, 0.505 and 0.905 follow 0.805. This unpredictable
behavior was checked on both v.5.004 (Linux) and v.5.000 (HP). Any ideas why
this happens?
--
Yuri Ralchenko
--------------
http://plasma-gate.weizmann.ac.il/~fnralch/
Department of Particle Physics phone: +972-8-9343610
Weizmann Institute of Science fax: +972-8-9343491
Rehovot 76100 ISRAEL home: +972-8-9466761
------------------------------
Date: 30 Sep 1998 16:56:01 -0400
From: Uri Guttman <uri@camel.fastserv.com>
To: fnralch@plasma-gate.weizmann.ac.il (Yuri Ralchenko)
Subject: Re: Need method to round real number to two decimal places
Message-Id: <sar90j1tj4u.fsf@camel.fastserv.com>
>>>>> "YR" == Yuri Ralchenko <fnralch@plasma-gate.weizmann.ac.il> writes:
YR> Doesn't necessarily work. How about this problem:
YR> perl -e '$a=0.705;printf "ans=%.2f",$a' gives ans=0.70
YR> perl -e '$a=0.805;printf "ans=%.2f",$a' gives ans=0.81
YR> Quite misteriously (at least for me), 0.105, 0.205, 0.305 and
YR> 0.605 behave like 0.705, while 0.005, 0.405, 0.505 and 0.905
YR> follow 0.805. This unpredictable behavior was checked on both
YR> v.5.004 (Linux) and v.5.000 (HP). Any ideas why this happens?
this is because of the internal format of floats. your numbers are not
what is actually stored inside the computer. read perlfaq4 for more
about this.
hth,
uri
--
Uri Guttman Fast Engines -- The Leader in Fast CGI Technology
uri@fastengines.com http://www.fastengines.com
------------------------------
Date: 30 Sep 1998 20:45:02 GMT
From: wayne@Glue.umd.edu (Wayne C. McCullough)
Subject: Perl for PC & select.
Message-Id: <6uu58e$q48$1@hecate.umd.edu>
Does anyone have good information regarding the use of redirected
output and select on the pc?
my piece of code:
#!/usr/local/bin/perl -w
use IO::Select;
use IO::File;
my $fh = new IO::File "prog |";
my $sel = IO::Select->new($fh);
while (@ready = $sel->can_read(10))
{
foreach $foo (@ready)
{
$l = <$foo>;
if (defined ($l))
{print $l;}
else
{$foo->close;
die "Prog died!\n"}
}
}
print "Timeout\n";
$fh->close
----------
Which will have it's expected result on a UNIX box. It prints out
the output from the 'prog' until prog finishes, unless prog has a
10 second delay in output.
On a PC, it goes immedeately to 'Timeout' and then waits on
the close until 'prog' dies. It doesn't even wait 10
seconds.
Now, is this a problem with the IO::Select package, or
what? Strangely, the select package seems to work just
great on network apps.
This is perl version 5.004_02 for win32
Am I missing something in the docs?
Thanks for your help.
W
------------------------------
Date: Wed, 30 Sep 1998 20:14:18 GMT
From: bart.mediamind@ping.be (Bart Lateur)
Subject: Re: Probably an easy Image vs Test question
Message-Id: <36148f2f.19529078@news.ping.be>
Steve wrote:
>- Can I include Script #2 (Content Type = Image) in Script #1 (Content
>Type = Text) as a subroutine? If so how?
No. You need two URL's, one for the HTML file, one for the image.
Usually, each URL points to a script. This COULD be the same script,
with different "command line parameters" (by which I mean the stuff
after the "?" in the URL). The script will then in fact run twice.
What you could do, is generate the image in a temporary file (be careful
not to overwrite the same file if you have two clients at the same
time!), and pass the URL to this temporary image in your HTML file.
Of course, you then have to do some householding, such as generating
temporary image files, and deleting them after some time. Preferabvly a
long time. You could remove old image files (of, say, over one hour old)
every time the script runs.
This seems like a lot of work for a newbie. :-)
Bart.
------------------------------
Date: Wed, 30 Sep 1998 19:36:16 GMT
From: Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com>
Subject: Re: restricting script execution?
Message-Id: <361285BE.AE16B826@bbnplanet.com>
droby@copyright.com wrote:
> I suspect you could probably find it the same place Larry (or some other
> implementor) did - "The Lord of the Rings" by J.R.R. Tolkien.
Well, duh. :)
> The use of such quotes in context with source code is also an art though.
Indeed.
e.
"All of us, all of us, all of us trying to save our immortal souls, some
ways seemingly more round-about and mysterious than others. We're having
a good time here. But hope all will be revealed soon." R. Carver
------------------------------
Date: Wed, 30 Sep 1998 15:17:00 -0400
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: SRC: encrypt your Perl scripts! :-)
Message-Id: <1dg64fl.xp0h87fj3qb2N@slip166-72-108-178.ny.us.ibm.net>
<droby@copyright.com> wrote:
> $_ = ''; # Why do I need this? It's silly to need this!
> $_ = <FILE> until (/my \$key/);
do {$_ = <FILE>} until /my \$key/;
>From perlsyn:
The while and until modifiers also have the usual "while loop" semantics
(conditional evaluated first), except when applied to a do-BLOCK (or to
the now-deprecated do-SUBROUTINE statement), in which case the block
executes once before the conditional is evaluated. This is so that you
can write loops like:
do {
$line = <STDIN>;
...
} until $line eq ".\n";
--
Kevin Reid. | Macintosh.
"I'm me." | Think different.
------------------------------
Date: 30 Sep 1998 20:14:39 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
Subject: Re: SRC: encrypt your Perl scripts! :-)
Message-Id: <6uu3ff$564$1@info.uah.edu>
In article <6utjqq$lki$1@nnrp1.dejanews.com>,
droby@copyright.com writes:
: Where's Tom? Isn't he reading this thread? Flames! I want flames!
Tom is tall enough to ride this roller coaster. By your participation
in this thread, you and Elaine have shown that you aren't. :-)
Greg
--
Cop: I can put you in Queens on the night of the hijacking.
Hockney: Really? I live in Queens. Did you put that together yourself?
------------------------------
Date: Wed, 30 Sep 1998 15:16:57 -0400
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: Substitution-Problem
Message-Id: <1dg5xcx.10lgykj4ge6uuN@slip166-72-108-178.ny.us.ibm.net>
<guelkev@de.polygram.com> wrote:
> Hello everybody,
> I have a problem with substitution in perl. I want to cut the
> "http://serveradress" Part from an URL to become a local URL.
>
> I tried the following statement:
> $url =~ s@http://*/@/@;
> which should replace the http://..../ with a single /.
>
> The result is, that it replace the part of the string I wrote directly but
> not that part which is included in the "*".
>
> Can anybody tell me what my mistake is and how I can fix this problem?
That should be:
$url =~ s@http://.*/@/@;
The * means "zero or more of the preceding thing (character)".
The . means "match any character".
You should read Perl's documentation on regular expressions.
--
Kevin Reid. | Macintosh.
"I'm me." | Think different.
------------------------------
Date: Wed, 30 Sep 1998 20:26:18 GMT
From: droby@copyright.com
Subject: Re: URL & strings searches
Message-Id: <6uu45a$af1$1@nnrp1.dejanews.com>
In article <la1zotzxoo.fsf@erh.ericsson.se>,
Michal Rutka <erhmiru@erh.ericsson.se> wrote:
> "meyrick" <meyricklouiseNOJUNK@btinternet.com> writes:
>
> > I start by admitting I am a complete newbie as far as Perl is
> > concerned - apologies to all gurus :-)
> >
> > Can anyone help with the following challenge?
> >
> > I want a script that will:
> [...]
>
> I can write this script for you for a appriotiate fee, i.e. I am taking $150
> per hour. Mimimum fee is for one hour. Writing of this script
> will not exceed one hour.
>
Don't forget "payment in advance". ;-)
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 3860
**************************************