[25110] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 7360 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 5 03:05:41 2004

Date: Fri, 5 Nov 2004 00:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 5 Nov 2004     Volume: 10 Number: 7360

Today's topics:
    Re: Best way to handle using a report template for non- <bmb@ginger.libs.uga.edu>
    Re: DEFINEs in Perl? <nospam@nospam.com>
    Re: DEFINEs in Perl? <william@wilbur.25thandClement.com>
    Re: DEFINEs in Perl? <tadmc@augustmail.com>
    Re: DEFINEs in Perl? <tassilo.von.parseval@rwth-aachen.de>
    Re: DEFINEs in Perl? <chbarts+usenet@gmail.com>
        FAQ 3.3: Is there a Perl shell? <comdog@panix.com>
        Global symbol requires explicit package name (snowdog)
    Re: Grep -v option <tadmc@augustmail.com>
    Re: Grep -v option <jurgenex@hotmail.com>
    Re: Load information in Solaris (Perl Script.) <tadmc@augustmail.com>
        not logical (Anonymous)
    Re: not logical <ahamm@mail.com>
    Re: not logical <tassilo.von.parseval@rwth-aachen.de>
    Re: Output of tar to a filehandle <tadmc@augustmail.com>
    Re: Q: re Inline and Benchmark <kalinaubears@iinet.net.au>
    Re: Solaris taking over Perl ownership <matthew.garrish@sympatico.ca>
    Re: Solaris taking over Perl ownership <ahamm@mail.com>
    Re: Solaris taking over Perl ownership (David Efflandt)
    Re: Solaris taking over Perl ownership <ahamm@mail.com>
    Re: Solaris taking over Perl ownership <abigail@abigail.nl>
    Re: Spurious "Use of uninitialized value" messages with <tadmc@augustmail.com>
    Re: Spurious "Use of uninitialized value" with -w, redu <tadmc@augustmail.com>
        Using libwww to retrieve a UTF-8 webpage <bogusasdfasdf@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 4 Nov 2004 22:47:24 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Best way to handle using a report template for non-programmers..
Message-Id: <Pine.A41.4.58.0411042230530.36036@ginger.libs.uga.edu>

On Thu, 4 Nov 2004, James Willmore wrote:

>    my($desc, $form) = (split);

>    my @fields = (split /:/);

Small nit to pick: you do know that the parens around split aren't needed?
They would be if you wanted to slice things up, but not otherwise.

      1 #!/usr/bin/perl
      2 use warnings;
      3 use strict;
      4
      5 $_ = "ABC 123 UME";
      6 my($desc, $form) = split;
      7 print "($desc, $form)\n";
      8
      9 tr/ /:/;
     10 my @fields = split /:/;
     11 print "@fields\n";
     12
     13 @fields = (split /:/)[0,1];  # parens needed here
     14 print "@fields\n";
     15
     16 __END__
     17 (ABC, 123)
     18 ABC 123 UME
     19 ABC 123

Regards,

Brad


------------------------------

Date: Thu, 4 Nov 2004 21:35:41 -0500
From: "daniel kaplan" <nospam@nospam.com>
Subject: Re: DEFINEs in Perl?
Message-Id: <1099622199.53859@nntp.acecape.com>

"Tony Curtis" <tony_curtis32@yahoo.com> wrote in message
news:87fz3p2gwb.fsf@limey.hpcc.uh.edu...
> perldoc constant

thanks tony,

unfortunatly it leads me to a deeper question where i need to make a
choice..

using the "use CONSTANT =>"  syntax is what I was looking for....HOWEVER, I
now need to add a deeper question because of my being new to Perl.  It seems
that using the syntax you pointed me to causes another function to be called
(within another module) and am just wondering:

Since this is about being on a web server hoping to get lots of hits, and
everythign gets compiled at runtime, we're talking much more processor work
(which since this is about a web server) would get multiplied depending how
many simultanous hits.

So I probably know that the answer (effecincy wise) is don't use "use
CONSTANT =>"...and stick with 1, 2, 3, etc...but in case I am
misunderstanmding something, I figured I would ask...you never know.

thanks again,

daniel






------------------------------

Date: Thu, 4 Nov 2004 20:16:44 -0800
From: William Ahern <william@wilbur.25thandClement.com>
Subject: Re: DEFINEs in Perl?
Message-Id: <cebr52-k91.ln1@wilbur.25thandClement.com>

daniel kaplan <nospam@nospam.com> wrote:
> "Tony Curtis" <tony_curtis32@yahoo.com> wrote in message
> news:87fz3p2gwb.fsf@limey.hpcc.uh.edu...
> > perldoc constant
>
> thanks tony,
>
> unfortunatly it leads me to a deeper question where i need to make a
> choice..
>
> using the "use CONSTANT =>"  syntax is what I was looking for....HOWEVER, I
> now need to add a deeper question because of my being new to Perl.  It seems
> that using the syntax you pointed me to causes another function to be called
> (within another module) and am just wondering:
>
> Since this is about being on a web server hoping to get lots of hits, and
> everythign gets compiled at runtime, we're talking much more processor work
> (which since this is about a web server) would get multiplied depending how
> many simultanous hits.
>
> So I probably know that the answer (effecincy wise) is don't use "use
> CONSTANT =>"...and stick with 1, 2, 3, etc...but in case I am
> misunderstanmding something, I figured I would ask...you never know.
>

I'd still `use constant NAME => VALUE;`. Worry about efficieny later, and
then first attack it by going down the list of computational complexity
issues, resource utilization, etc. `use constant` should be the least of
your worries, no matter how it's implemented or utilized.

You'll more effectively be able to address the bigger efficiency/performance
issues by having clear and concise code.

Indeed, AFAIK constants might be just as fast as literals. I seem to
remember constants being called like subroutines, however perldoc constant
doesn't leave me that impression at all.



------------------------------

Date: Thu, 4 Nov 2004 22:31:13 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: DEFINEs in Perl?
Message-Id: <slrncom0gh.f08.tadmc@magna.augustmail.com>

daniel kaplan <nospam@nospam.com> wrote:


> Sorry for the long explination, but didn't know how to call DEFINE for those
> who don't know C, 


#define is not really in the C language proper, it is 
in the C preprocessor (cpp).


> but might know the equivalent in Perl.


The most usual language-agnostic name for it is "macro".

But a "constant" would be even better than a macro in many situations,
and Perl has constants:

   perldoc constant


If you really do require a macro, then check out the Filter::cpp
module and use #define.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Fri, 5 Nov 2004 06:52:10 +0100
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: DEFINEs in Perl?
Message-Id: <slrncom58a.pp.tassilo.von.parseval@localhost.localdomain>

Also sprach daniel kaplan:

> "Tony Curtis" <tony_curtis32@yahoo.com> wrote in message
> news:87fz3p2gwb.fsf@limey.hpcc.uh.edu...
>> perldoc constant
>
> thanks tony,
>
> unfortunatly it leads me to a deeper question where i need to make a
> choice..
>
> using the "use CONSTANT =>"  syntax is what I was looking for....HOWEVER, I
> now need to add a deeper question because of my being new to Perl.  It seems
> that using the syntax you pointed me to causes another function to be called
> (within another module) and am just wondering:

This function is constant::import().

> Since this is about being on a web server hoping to get lots of hits, and
> everythign gets compiled at runtime, we're talking much more processor work
> (which since this is about a web server) would get multiplied depending how
> many simultanous hits.

There's the first misconception. Compilation at runtime, well, that's
almost a contradiction in itself. Just like any compiled language (think
C), perl has a compiletime phase, too. When you run a script, perl will
not interpret it line-by-line (which happens with shell scripts). It
will first compile it to an optree. After that, it runs a so called
peephole optimizer on this thusly generated optree. The optimizer visits
the nodes of the tree in the order they are to be executed and
rearranges them in a way that hopefully improves runtime. Some nodes are
nulled out, others are replaced with other ops.

Incidentally, there are currently ideas to make this optimizer optional.
You can see the effect of it when using B::Terse or B::Concise on a
script to dump it's optree. With the optimizer:

ethan@ethan:~/Projects/perl-p-5.8.0@23466$ ./perl -I. -MO=Terse,-exec
print for reverse 1..10;
__END__
OP (0x819e378) enter
COP (0x819e798) nextstate
COP (0x819e740) nextstate
OP (0x8279580) pushmark
SVOP (0x820f450) const  AV (0x818de48)
UNOP (0x8202db0) rv2av
SVOP (0x81cadc8) gv  GV (0x818dd34) *_
LOOP (0x8214410) enteriter
OP (0x8214440) iter
LOGOP (0x819e358) and
REDO =>
    OP (0x819dd28) pushmark
    SVOP (0x81a1fe0) gvsv  GV (0x818dd34) *_
    LISTOP (0x819d550) print
NEXT =>
    OP (0x819e340) unstack
    goto OP (0x8214440)
LAST =>
BINOP (0x8275d00) leaveloop
LISTOP (0x819e778) leave [1]

And with the optimizer turned off:

ethan@ethan:~/Projects/perl-p-5.8.0@23466$ PERL_NO_PEEPHOLE=1 ./perl -I. -MO=Terse,-exec
print for reverse 1..10;
__END__
OP (0x819e7c0) enter
COP (0x81a6b78) nextstate
COP (0x8276608) nextstate
OP (0x819e3e0) null [3]
OP (0x8247290) pushmark
OP (0x821e518) pushmark
SVOP (0x819e3c0) const  AV (0x818de48)
UNOP (0x821d250) rv2av
LISTOP (0x821e4f8) reverse [3]
UNOP (0x8194ea0) null [141]
SVOP (0x821d230) gv  GV (0x818dd34) *_
LOOP (0x8270428) enteriter
OP (0x819e3f8) iter
LOGOP (0x8202e70) and
REDO =>
    OP (0x819e5c8) pushmark
    SVOP (0x81a2478) gv  GV (0x818dd34) *_
    UNOP (0x819e578) rv2sv
    LISTOP (0x819d5d0) print
NEXT =>
    OP (0x8270458) unstack
    goto OP (0x819e3f8)
UNOP (0x821dba8) null
LAST =>
BINOP (0x82765e8) leaveloop
LISTOP (0x81a6b58) leave [1]

You see that the second optree has more ops than the first one. In the
first optree, there's no longer a reverse op showing up. Perl does it
implicitely by generating the reversed list in the first place. In the
second one, it will first create the list 1..10 and then reverse it. 
Also, the optimized version turned a gv/rv2sv combination into one op
gvsv and deleted all occurances of null ops.

The above is all still compiletime. Runtime doesn't start until the
optree has been constructed and optimized. If your script doesn't
contain any eval(), require() or do() statements (and possibly some
others), there wont be any more compilation happening at runtime. For
the lifetime of the script, perl keeps the operator tree in memory and
executes the script (that is: it walks through the optree). 

As for constant.pm, this module will turn a literal value into a
subroutine. So:

    use constant FOO => 1;

becomes

    sub FOO () { 1 }

Note the empty prototype which tells perl that this function will never
ever receive an argument. This happens at compiletime. Because it
happens so early, perl can then replace the occurance of every FOO in
your script with the return value of FOO() just because it knows that
this function can only have one outcome. This process is called
inlining.

Observe what happens with a prototype:

ethan@ethan:~$ perl -MO=Terse,-exec -e 'sub FOO () { 1 } print FOO;'
OP (0x8164d00) enter 
COP (0x8164d68) nextstate 
OP (0x8164ef8) pushmark 
SVOP (0x8164fe0) const [1] IV (0x8160bb4) 1 
LISTOP (0x8165038) print 
LISTOP (0x8164ec0) leave [1] 
-e syntax OK

And without:

ethan@ethan:~$ perl -MO=Terse,-exec -e 'sub FOO { 1 } print FOO;'
OP (0x81649f0) enter
COP (0x8164990) nextstate
OP (0x81648f8) pushmark
OP (0x8150898) pushmark
PADOP (0x8164aa8) gv  GV (0x8160b90) *FOO
UNOP (0x81644b8) entersub [2]
LISTOP (0x8164968) print
LISTOP (0x81648d0) leave [1]
-e syntax OK

In the first one, FOO isn't called at all. It has been optimized away
and replaced by 'SVOP (0x8164fe0) const [1] IV (0x8160bb4) 1'. In the
second case, perl will call FOO.

> So I probably know that the answer (effecincy wise) is don't use "use
> CONSTANT =>"...and stick with 1, 2, 3, etc...but in case I am
> misunderstanmding something, I figured I would ask...you never know.

For the runtime of your script, using a true constant or the literal
value will make exactly no difference. It will however affect compile
time as perl needs a bit of time to create the constant and inline it.

If you are using mod_perl on your webserver, this additional compiletime
is tolerable as your script will be cached in compiled form and as we've
seen, the optree is identical irregardless of whether you use a constant
or its literal value.

For a true CGI script (which is compiled on each incoming request) on
the other hand, it's desirable to reduce compiletime, too. However,
additional constants will only add a couple of milliseconds. This is not
much in relation to the overhead of creating a new process and starting
the Perl interpreter.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


------------------------------

Date: Fri, 05 Nov 2004 01:03:09 -0700
From: Chris Barts <chbarts+usenet@gmail.com>
Subject: Re: DEFINEs in Perl?
Message-Id: <35udnaWvIvhMrhbcRVn-2w@onewest.net>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

Tad McClellan wrote:
| daniel kaplan <nospam@nospam.com> wrote:
|
|>Sorry for the long explination, but didn't know how to call DEFINE for
those
|>who don't know C,
|
| #define is not really in the C language proper, it is
| in the C preprocessor (cpp).

The syntax and semantics of the preprocessor are defined by the C
standards (ANSI and ISO), and there's nothing saying it has to be a
separate program anyway. For any reasonable definition of the term `in',
the preprocessor is in the language proper.


-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFBizO9KxatjOtX+j0RAmPlAJ9rM+3aEhMiAJbs+SmIYXfNVCWsUQCeIefv
MQVZi3vfMBUeLTSYNrmiuWg=
=o/Sc
-----END PGP SIGNATURE-----


------------------------------

Date: Fri, 5 Nov 2004 05:03:00 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 3.3: Is there a Perl shell?
Message-Id: <cmf1i4$3ib$1@reader1.panix.com>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.

--------------------------------------------------------------------

3.3: Is there a Perl shell?

    The psh (Perl sh) is currently at version 1.8. The Perl Shell is a shell
    that combines the interactive nature of a Unix shell with the power of
    Perl. The goal is a full featured shell that behaves as expected for
    normal shell activity and uses Perl syntax and functionality for
    control-flow statements and other things. You can get psh at
    http://www.focusresearch.com/gregor/psh/ .

    Zoidberg is a similar project and provides a shell written in perl,
    configured in perl and operated in perl. It is intended as a login shell
    and development environment. It can be found at http://zoidberg.sf.net/
    or your local CPAN mirror.

    The Shell.pm module (distributed with Perl) makes Perl try commands
    which aren't part of the Perl language as shell commands. perlsh from
    the source distribution is simplistic and uninteresting, but may still
    be what you want.



--------------------------------------------------------------------

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. All rights 
    reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.


------------------------------

Date: 4 Nov 2004 20:46:01 -0800
From: snowdogdb@yahoo.com (snowdog)
Subject: Global symbol requires explicit package name
Message-Id: <736264ea.0411042046.1b8742f0@posting.google.com>

Can someone please help me.  I've got a perl script I've written to
send notifications to another application.  The following lines are in
the same sub under the same package (line#'s included for reference). 
The line 255 clearly defined the $action variable.  Line 341 tries to
use it in a method for $notificationObj.  Perl is telling me that
global symbol $action requires explicit package name on line 341. 
Why, it IS defined on line 255.
Funny thing is, I didn't have this problem until I moved the entire
code block under a package main; statement (I'm trying to get this
thing to run as a service).

255: my $action = "notify";
341: my $notificationResult = $notificationObj->invoke($action,
                          "HowIs_Adapter",
                          $main::configRef->{'Config.howisServer'},
                          "HowIs Alarm",   
                          ); 


I appreciate your help!


------------------------------

Date: Thu, 4 Nov 2004 19:41:30 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Grep -v option
Message-Id: <slrncolmia.ep6.tadmc@magna.augustmail.com>

Mark Lockett <mlockett@alfains.com> wrote:

> Subject: Grep -v option


grep(1) is not Perl.

Did you have a Perl question?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Fri, 05 Nov 2004 02:49:26 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Grep -v option
Message-Id: <WSBid.3086$_e.935@trnddc05>

Mark Lockett wrote:
> I am trying to parse lines out of a txt file. Instead of running the
> command three times, how can I add all the parameters together for the
> -v option.

Which -v option are you talking about? "perldoc -f grep" doesn't mention it.

jue 




------------------------------

Date: Thu, 4 Nov 2004 22:07:21 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Load information in Solaris (Perl Script.)
Message-Id: <slrncolv3p.f08.tadmc@magna.augustmail.com>

Alice Stamp <alstamp@gmail.com> wrote:


> open (DATA, "/proc/stat");

> close PSF;


One of those things is not like the other, one of those things 
just doesn't belong...



> Is there another
> utility I can call to pull out this data, 

comp.unix.solaris is over that-a-way  ---->

:-)


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: 4 Nov 2004 22:19:57 -0800
From: contact79@yahoo.com (Anonymous)
Subject: not logical
Message-Id: <adc3a315.0411042219.273e67bf@posting.google.com>

Why doesn't ([^\s]) not produce the same result as (\S)?

TIA


------------------------------

Date: Fri, 5 Nov 2004 17:41:32 +1100
From: "Andrew Hamm" <ahamm@mail.com>
Subject: Re: not logical
Message-Id: <2v0lkuF2gr7fiU1@uni-berlin.de>

Anonymous wrote:
> Why doesn't ([^\s]) not produce the same result as (\S)?

Because \s is not special inside [ ] so you are litterally saying not \
and not s

only \n \t \b \cX \NNN and the new-fangled \N{NAME} are meaningful
backslashers inside [ ]




------------------------------

Date: Fri, 5 Nov 2004 08:38:25 +0100
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: not logical
Message-Id: <slrncombfh.4ou.tassilo.von.parseval@localhost.localdomain>

Also sprach Andrew Hamm:

> Anonymous wrote:
>> Why doesn't ([^\s]) not produce the same result as (\S)?
>
> Because \s is not special inside [ ] so you are litterally saying not \
> and not s
>
> only \n \t \b \cX \NNN and the new-fangled \N{NAME} are meaningful
> backslashers inside [ ]

I am afraid that's entirely untrue. From perlre:

   [...]            You may use "\w", "\W", "\s", "\S", "\d", and "\D"
   within character classes, but if you try to use them as endpoints of a
   range, that's not a range, the "-" is understood literally.  

To the OP: Under most circumstances \S and [^\s] should be equivalent. I
am not quite sure however how negated character classes behave when
unicode or locales are in effect. But then, I don't know much about
unicode anyway.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


------------------------------

Date: Thu, 4 Nov 2004 19:38:29 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Output of tar to a filehandle
Message-Id: <slrncolmcl.ep6.tadmc@magna.augustmail.com>

Whitey Johnson <whitey@newmail.net> wrote:

> Question 2: Would I be able to use the:
>  open TAR, "tar -cvzf $bkfile $dir" or die "Tar failed: $!\n";
> with scalars? 


What happened when you tried it?

You _do_ read the documentation for the functions that you use, don't you?


   perldoc -f open


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Fri, 05 Nov 2004 02:14:19 +0000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: Q: re Inline and Benchmark
Message-Id: <418ae34b$0$6557$5a62ac22@per-qv1-newsreader-01.iinet.net.au>

Michele Dondi wrote:
> On Thu, 04 Nov 2004 10:40:41 +0000, Sisyphus
> <kalinaubears@iinet.net.au> wrote:
> 
> 
>>fact that it leaks. What I'm now wondering is whether the leak was not 
>>mentioned because:
>>a) no-one noticed it;
>>or because:
>>b) code that leaks is of little concern, and generally not considered 
>>worth mentioning.
> 
> 
> Certainly *for me* and *in this case* it's not necessarily worth
> mentioning that it leaks. However since I could understand Abigail's
> code[1], but I can't follow your discussion anymore and yet I'd like
> to include the non-leaking code in the comparison too (for
> completeness) once you all agree on "the best/correct way to do it",
> for some reasonably sensible meaning of "best/correct", may you supply
> a complete, working, function? You can write me privately at
> <ti tod nfni tod im tod mcl ta razalb> if needed.
> 
> 
> [1] I've not written a line in C in ten years or so, but I conserve
> some reminiscence of it.  ;-)
> 
> 
> Michele

use warnings;

use Inline C => Config =>
     BUILD_NOISY => 1;

use Inline C => <<'EOC';

         char * abigail () {
             char * str;
             int    i;
             int    l;

             l = 20;
             srand (time ((time_t) NULL));
             if ((str = (char *) malloc (l * sizeof (char))) == (char *) 
NULL) {
                 perror (malloc);
                 exit (-1);
             }
             for (i = 0; i < l; i ++) {
                 str [i] = rand () % 255;
             }
             return (str);
         }

          SV * sisyphus () {
              char * str;
              SV * outsv;
              int    i;
              int    l;

              l = 20;
              srand (time ((time_t) NULL));
              New(1, str, l * sizeof(char), char);
              if(str == NULL)
                croak("Failed to allocate memory in r_string()");
              for (i = 0; i < l; i ++) {
                  str [i] = rand () % 255;
              }
              outsv = newSVpv(str, l);
              Safefree(str);
              return outsv;
          }

          SV * sisyphus2 () {
              SV * outsv;
	     char c;
              int    i;
              int    l = 20;

	     outsv = NEWSV(0, l);
              srand (time ((time_t) NULL));

	     for (i = 0; i < l; i ++) {
                   c = rand () % 255;
		  sv_insert(outsv, i, 1, &c, 1);
              }
	     SvPOK_on(outsv);
	     SvCUR_set(outsv, l);
              return outsv;
          }

EOC

$s = abigail();
print $s, " ", length($s), "\n";

$s = sisyphus();
print $s, " ", length($s), "\n";

$s = sisyphus2();
print $s, " ", length($s), "\n";

__END__

'abigail()' is the function as he originally wrote it. The only 
complaint I originally had about it is that it leaks memory.

'sisyphus()' is the version that I posted in my first post (with a typo 
or two fixed). It doesn't leak memory - but it's a little wasteful in 
that it uses 2 memory buffers, whereas one would suffice.

'sisyphus2()' is the same as 'sisyphus()' except that it attends to the 
"wastefulness" issue (hopefully :-). You can probably convert the 2 
lines inside the for loop into a single line, and thus dispense with any 
need for declaring a 'char' .... I'm not going to worry about *that* 
wastefulness right now :-) What does puzzle me a little is that it 
produces a "Use of uninitialized value in subroutine entry" warning and 
I haven't yet worked out why. What on earth is perl on about there ??

The above has been tested, but not benchmarked. I don't think you'll 
detect any difference in speed of the 3 subs, but it's not hard to find out.

Note that (for the purposes of my test) I changed the length of the 
random string from 20000 to 20.

For some reason the length returned by 'abigail()' is usually 21. I 
suspect you're also getting the trailing NULL character in strings that 
it returns. However, on Linux, that 21st character often shows up as a 
'1'. I can't explain that. On a couple of occasions it returned a string 
that was less than 20 characters long - perhaps because of an embedded 
NULL character in the string, so it probably pays to check that you get 
the full quota returned.

Cheers,
Rob

-- 
To reply by email u have to take out the u in kalinaubears.



------------------------------

Date: Thu, 4 Nov 2004 21:31:19 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Solaris taking over Perl ownership
Message-Id: <VBBid.22478$dj2.1445187@news20.bellglobal.com>


"Andrew Hamm" <ahamm@mail.com> wrote in message 
news:2v0342F2g737sU1@uni-berlin.de...
> Hi folks
>
> I have recently built a Perl 5.8.5 binary for a new customer. I have made
> it install in /usr/bin, /usr/lib etc
>
> As many of you are probably aware, Solaris are supplying and obsolete
> version of Perl in /usr/bin/perl etc. As you are may also be aware, it is
> an old version - for Solaris 9 you are happily supplied 5.6.1, and for
> Solaris 8 you are supplied (I think) approx 5.005.
>
> Now the customer, who self-admittedly has very little UNIX experience, is
> saying that Solaris is making threats of withdrawn support if we install a
> "non-Sun" version of Perl in the same location; overriding the obsolete
> version of Perl supplied by Sun. They are threatening total withdrawal of
> support for Solaris, not just "support" of Perl [if the story is to be
> believed]
>

You probably should take a look at the following:

http://search.cpan.org/dist/perl/README.solaris

If you take out their version of Perl, you can cause irreperable harm, so 
it's very likely that they won't support it. But as the docs say, just 
install the newer version somewhere else.

Matt 




------------------------------

Date: Fri, 5 Nov 2004 14:03:41 +1100
From: "Andrew Hamm" <ahamm@mail.com>
Subject: Re: Solaris taking over Perl ownership
Message-Id: <2v08shF2g0k7rU1@uni-berlin.de>

Matt Garrish wrote:
>
> You probably should take a look at the following:
>
> http://search.cpan.org/dist/perl/README.solaris
>

Excellent - thanks for pointing that out. Sadly I do not have access to a
Solaris right now for a rebuild of Perl. I took an opportunity to make a
STANDARD Perl with a few of our standard modules pre-installed and then
grab a tarball. I am pissed at Solaris for trying to way-lay the
/usr/bin/perl, but I see that

[QUOTE]
You may wish to put your version of perl in the PATH of all users by
changing the link /usr/bin/perl. This is OK, as all perl scripts shipped
with Solaris use an explicit path.
[/QUOTE]

So this is a solution. We supply many customers on many different
platforms, and the need for a standard without obscurity is essential. If
Solaris uses Perl internally, I would expect /they/ should take
responsibility for protecting it with a non-standard install location.
However, the symlink and explicit paths mentioned above does give a
workable solution.

It's ludicrous that an O/S can ham-string individuals who need an
up-to-date version of Perl, or one with certain config options. HP at
least has the grace to supply their ancient 4.036 in
/usr/contrib/obsolete/rubbish or whatever that exact path is :-)

Changing #! lines is a pain in the proverbial when there are many sites.
This is the first time I've heard of the O/S trying to impose rules, but
at least there's a suitable workaround.

> If you take out their version of Perl, you can cause irreperable
> harm, so it's very likely that they won't support it. But as the docs
> say, just install the newer version somewhere else.

Yes. They put into /usr/perl5 when my builds go into /usr/bin and
/usr/lib/perl* so I'm happy. Their precious /usr/perl5 is safe from me.

Thanks again for the pointer. I can use this page of the document in the
power-meeting I'm about to go through ;-)  Worst case is to play
chinese-whispers on a phone line to teach them the entire process of
creating Perls - of course they don't allow any kind of dial-in or ssh
access. Oh no. If this document can convince them of the safety of the
install then I have saved a few hours of time that is not free anyway.




------------------------------

Date: Fri, 5 Nov 2004 04:14:54 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Solaris taking over Perl ownership
Message-Id: <slrncolvhu.q5o.efflandt@typhoon.xnet.com>

On Fri, 5 Nov 2004 12:25:12 +1100, Andrew Hamm <ahamm@mail.com> wrote:
> I have recently built a Perl 5.8.5 binary for a new customer. I have made
> it install in /usr/bin, /usr/lib etc
> 
> As many of you are probably aware, Solaris are supplying and obsolete
> version of Perl in /usr/bin/perl etc. As you are may also be aware, it is
> an old version - for Solaris 9 you are happily supplied 5.6.1, and for
> Solaris 8 you are supplied (I think) approx 5.005.
> 
> Now the customer, who self-admittedly has very little UNIX experience, is
> saying that Solaris is making threats of withdrawn support if we install a
> "non-Sun" version of Perl in the same location; overriding the obsolete
> version of Perl supplied by Sun. They are threatening total withdrawal of
> support for Solaris, not just "support" of Perl [if the story is to be
> believed]

Not sure what Solaris version (uname -a says SunOS 5.9), but my old
Solaris ISP has 2 versions of Perl currently installed.  I have no idea if
the second one is from Sun or simply compiled on Sun.

% /usr/local/bin/perl -v

This is perl, version 5.005_03 built for sun4-solaris


% /usr/bin/perl -v

This is perl, v5.6.1 built for sun4-solaris-64int
(with 48 registered patches, see perl -V for more detail)


------------------------------

Date: Fri, 5 Nov 2004 15:30:10 +1100
From: "Andrew Hamm" <ahamm@mail.com>
Subject: Re: Solaris taking over Perl ownership
Message-Id: <2v0dulF2fjks0U1@uni-berlin.de>

David Efflandt wrote:
>
> Not sure what Solaris version (uname -a says SunOS 5.9), but my old
> Solaris ISP has 2 versions of Perl currently installed.  I have no
> idea if the second one is from Sun or simply compiled on Sun.
>
> % /usr/local/bin/perl -v
>
> This is perl, version 5.005_03 built for sun4-solaris
>
> % /usr/bin/perl -v
>
> This is perl, v5.6.1 built for sun4-solaris-64int
> (with 48 registered patches, see perl -V for more detail)

My understanding is that Solaris 8 (aka SunOS 5.8) gets 5.005_03, and
Solaris 9 (5.9) gets 5.6.1. From the document Matt suggested, they will
only hang on to the old ones for 1 or 2 new versions of solaris.

Anyway, I've had an amazing surprise - someone at the site has worked out
how to download and build Perl. Customers can achieve this? If they have
got it right then I'm happy as larry. All I'm waiting for is the output of
perl -V to be sure they made the correct config choices; I want it to be
all default except for one leeetle thing.

Anyway, problem solved it seems, but I'll still hurl a boiled egg at the
Sun offices next time I'm in the area.




------------------------------

Date: 05 Nov 2004 07:56:31 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Solaris taking over Perl ownership
Message-Id: <slrncomchf.mg8.abigail@alexandra.abigail.nl>

Andrew Hamm (ahamm@mail.com) wrote on MMMMLXXXIV September MCMXCIII in
<URL:news:2v0342F2g737sU1@uni-berlin.de>:
''  Hi folks
''  
''  I have recently built a Perl 5.8.5 binary for a new customer. I have made
''  it install in /usr/bin, /usr/lib etc
''  
''  As many of you are probably aware, Solaris are supplying and obsolete
''  version of Perl in /usr/bin/perl etc. As you are may also be aware, it is
''  an old version - for Solaris 9 you are happily supplied 5.6.1, and for
''  Solaris 8 you are supplied (I think) approx 5.005.
''  
''  Now the customer, who self-admittedly has very little UNIX experience, is
''  saying that Solaris is making threats of withdrawn support if we install a
''  "non-Sun" version of Perl in the same location; overriding the obsolete
''  version of Perl supplied by Sun. They are threatening total withdrawal of
''  support for Solaris, not just "support" of Perl [if the story is to be
''  believed]

Yes, and rightly so. Some important Solaris tools are Perl scripts.
If you change the perl they are using, you break the system. Would
your car dealer give you warrenty if you replaced important engine
parts?

However, IIRC (I don't have a box I can check at the moment) on Solaris,
the "system" perl isn't /usr/bin/perl - instead, /usr/bin/perl is a link
to the "system" perl. You're free to replace the /usr/bin/perl link with
something of your choice, as the Solaris tools will use the real path
to the "system" perl. As long as you keep that perl (and it's libraries)
in place, you should be fine.

I think SUN did a better job of dealing with perl than many other OSses
where replacing /usr/bin/perl with something of your choice will break
things.

''  However, disregarding these latter two possibilities; if Solaris is indeed
''  making threats of this nature, what would the Perl community think? Has
''  anyone else heard such outrageous claims from Sun?

Why is the opinion of the Perl community important related to this issue?



Abigail
-- 
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(
HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (
LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET",
"http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content))
=~ /(.*\))[-\s]+Addition/s) [0]'


------------------------------

Date: Thu, 4 Nov 2004 19:53:45 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Spurious "Use of uninitialized value" messages with '-w'
Message-Id: <slrncoln99.ep6.tadmc@magna.augustmail.com>

Sam Denton <dejanews@email.com> wrote:

> Subject: Spurious "Use of uninitialized value" messages with '-w'


There are no "spurious" messages.

"spurious" does not mean "I don't understand where they come from",
it means unwarranted messages.

You do indeed use an undef value (that's what makes "uninitialized value" 
messages), so the warnings _are_ warranted.


>   +213      print ", undef" if undef $fsmount;


You just told perl to give $fsmount the undef value.

Why did you tell it that?

I think you wanted this instead:

   print ", undef" unless defined $fsmount;



-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Thu, 4 Nov 2004 20:02:08 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Spurious "Use of uninitialized value" with -w, redux
Message-Id: <slrncolnp0.ep6.tadmc@magna.augustmail.com>

Sam Denton <dejanews@email.com> wrote:

> OK, my first post had a bug, but it's a real problem, honest.


Post a short and complete program *that we can run* that
makes those warnings, and we will help you make the warnings
go away.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: 4 Nov 2004 19:56:58 -0800
From: "EH" <bogusasdfasdf@hotmail.com>
Subject: Using libwww to retrieve a UTF-8 webpage
Message-Id: <1099627018.580176.229190@f14g2000cwb.googlegroups.com>

Hello all,

I'd appreciate any advice you might have.  I'm trying to download a web
page (that's in utf-8) and save it as a local file.  I'm using
ActivePerl 5.8.  The problem is that either the file that's saved isn't
correctly encoded or my get method isn't retrieving the html page
correctly.  I'm using the Chinese Traditional Google News as an
example.  A comparison of the file that's saved with the website shows
that they are clearly not that same.


This is my relatively simple script:

use utf8;
use LWP::UserAgent;

$ua = LWP::UserAgent->new;
my @ns_headers = (
'User-Agent' => 'Mozilla/4.76 [en] (Win98; U)',
'Accept' => 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
image/png, */*',
'Accept-Charset' => 'utf-8',
'Accept-Language' => 'en-US',
);

$url = "http://news.google.com/news?ned=cn&hl=zh-CN";

my $content = $ua->get ($url, @ns_headers);

open TEST, ">:utf8", "wwwutftest.html" || die "failed to open $\n";

if ($content->is_success) {
print TEST $content->content();
} else {
print "failed to get: $!";
}

close(TEST);


Thanks for any suggestions you might have.



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 V10 Issue 7360
***************************************


home help back first fref pref prev next nref lref last post