[25117] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7367 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Nov 6 00:08:47 2004

Date: Fri, 5 Nov 2004 21:05:09 -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: 7367

Today's topics:
    Re: $& imposes a considerable performance penalty they  <emschwar@pobox.com>
    Re: A small Perl problem <tadmc@augustmail.com>
        an original perldoc viewer <ioneabu@yahoo.com>
    Re: an original perldoc viewer <1usa@llenroc.ude.invalid>
    Re: an original perldoc viewer <chaosppp@cox.net>
    Re: an original perldoc viewer <ioneabu@yahoo.com>
        Calling a CGI script from local PC vs server (Doc)
    Re: Calling a CGI script from local PC vs server <1usa@llenroc.ude.invalid>
    Re: Calling a CGI script from local PC vs server <noreply@gunnar.cc>
    Re: Check POP3 E-mail <tadmc@augustmail.com>
    Re: EOF issue <1usa@llenroc.ude.invalid>
    Re: EOF issue <wyzelli@yahoo.com>
    Re: EOF issue <tadmc@augustmail.com>
        FAQ 6.14: How can I print out a word-frequency or line- <comdog@panix.com>
        Lexical file handles <tintin@invalid.invalid>
    Re: Lexical file handles <noreply@gunnar.cc>
    Re: Lexical file handles <notvalid@email.com>
    Re: lists,shift,subs and dumb question <tadmc@augustmail.com>
        pulling or getting perl script name inside script <JM@jm.biz>
    Re: pulling or getting perl script name inside script <1usa@llenroc.ude.invalid>
    Re: pulling or getting perl script name inside script <tadmc@augustmail.com>
    Re: Q: re Inline and Benchmark <kalinaubears@iinet.net.au>
    Re: remove unwanted parts from strings <jurgenex@hotmail.com>
    Re: remove unwanted parts from strings <jurgenex@hotmail.com>
        sanity checking proxy URL before passing to LWP (buildmorelines)
    Re: sanity checking proxy URL before passing to LWP <1usa@llenroc.ude.invalid>
    Re: Solaris taking over Perl ownership <tintin@invalid.invalid>
    Re: Solaris taking over Perl ownership (krakle)
    Re: Solaris taking over Perl ownership <tadmc@augustmail.com>
    Re: Solaris taking over Perl ownership <tintin@invalid.invalid>
    Re: Using libwww to retrieve a UTF-8 webpage <bogusasdfasdf@hotmail.com>
        why not    print $A[0] (Mark Galecki)
    Re: why not    print $A[0] <tim@vegeta.ath.cx>
    Re: why not    print $A[0] <noreply@gunnar.cc>
    Re: Win32::OLE msxml collection problem (Jay Tilton)
    Re: Win32::OLE msxml collection problem <simon@unisolve.com.au>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 05 Nov 2004 16:17:05 -0700
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: $& imposes a considerable performance penalty they say
Message-Id: <eto654janta.fsf@wilson.emschwar>

Uri Guttman <uguttman@athenahealth.com> writes:
> so in general, don't use [$&], use explicit capturing
> parens which will only cause the s/// with them to copy the original
> string. 

I don't have such an old perl to hand, but perlre points out that:

  As of 5.005, $& is not so costly as the other two.

(meaning $' and $`)

How much less costly is it?

As a side note: Thanks to Abigail, mostly, one alteration I've made to
my personal programming practises lately is that I've started using
things like $&, shelling out, etc., more often in cases where the code
isn't time-critical (which is, frankly, most of the time).  I've found
that it will often save me mental effort time, and in many cases makes
the code clearer than a more conventional approach might dictate.

Recently, for instance, I replaced a shell script that examined a
Linux system, and printed out what cards it thought were in which
slots, with a Perl program that does all sorts of conventionally 'bad'
things, like using $&, lots of `find -name ... | grep | sort -u`, and
the like because I was trying, as much as possible, to stick with the
logic of the shell script, and I figured "Heck, I'll optimize it
later, and pass around arrayrefs instead of calling `lspci`
everywhere, and use File::Find, and stop with the $&."

Before I even got around to it, I ran some benchmarks, and I still cut
down the average run time from 10 seconds to 3, so I give myself a
free pass for using those constructs in that context.  I realize that
is not disagreeing with you, just that sometimes, the performance hit
of using $&, or shelling out even when there's a perfectly good module
available, isn't significant.

My advice would be to use them wherever you like, but be aware that
they can indeed cause performance problems.  Even so, I'd still
profile your program before rushing to those as the first cure to poor
performance-- you may well find, as I have, that poor algorithms or
inefficient data structures are far more detrimental to your program's
run than $& could ever be.

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


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

Date: Fri, 5 Nov 2004 18:25:52 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: A small Perl problem
Message-Id: <slrncoo6gg.hra.tadmc@magna.augustmail.com>

Ali <ali.baig@gmail.com> wrote:


> I am using Perl 5.005.


Why?

A lot has happened in the 6 years since that version was released...


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


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

Date: Fri, 05 Nov 2004 23:15:50 -0500
From: wana <ioneabu@yahoo.com>
Subject: an original perldoc viewer
Message-Id: <10ooglasp5pf7a1@news.supernews.com>

I have been reprimanded for my lack of knowledge of perldoc material so I
have decided to do more reading.  I realized that I am often (%50 of the
time) working on a machine that does not have Perl but is connected to the
internet.  My first thought was to go to perldoc.com, but it seemed  to be
down tonight, so I wrote a simple home-made solution to get by for now.  I
was hoping pod2html would format my perldocs but it did not work when I
tried: pod2html perltoc (maybe perldoc pod2html says how to do it).  Here
it is.  Improvements, especially in output formatting, would be welcome.

#!/usr/bin/perl
use strict;
use warnings;
use CGI qw(:standard escapeHTML escape);
$CGI::POST_MAX=1024 * 100;  # max 100K posts
$CGI::DISABLE_UPLOADS = 1;  # no uploads

my $a = 'perldoc to be displayed here';
if (param('display'))
{
        if (my $doc = param('docname'))
        {
                $a = `perldoc $doc`;
        }
}
print header(), start_html();
print start_form(), p('Type name of perldoc'),
        p(textfield(-name=>'docname')),
        p(submit(-name=>'display')),
        end_form();
print hr, pre($a),end_html();


Thanks!

wana


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

Date: 6 Nov 2004 03:33:38 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: an original perldoc viewer
Message-Id: <Xns9598E57F2C34Casu1cornelledu@132.236.56.8>

wana <ioneabu@yahoo.com> wrote in
news:10ooglasp5pf7a1@news.supernews.com: 

> I have been reprimanded for my lack of knowledge of perldoc material
> so I have decided to do more reading.  I realized that I am often (%50
> of the time) working on a machine that does not have Perl but is
> connected to the internet.  

Why don't you have Perl on the machine where you are doing your 
development?


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

Date: Fri, 05 Nov 2004 21:05:09 -0700
From: Phillip Hartfield <chaosppp@cox.net>
Subject: Re: an original perldoc viewer
Message-Id: <U3Yid.35163$SW3.24757@fed1read01>

A. Sinan Unur wrote:
> wana <ioneabu@yahoo.com> wrote in
> news:10ooglasp5pf7a1@news.supernews.com: 
> 
> 
>>I have been reprimanded for my lack of knowledge of perldoc material
>>so I have decided to do more reading.  I realized that I am often (%50
>>of the time) working on a machine that does not have Perl but is
>>connected to the internet.  
> 
> 
> Why don't you have Perl on the machine where you are doing your 
> development?

Even on a standalone P1 w/64mb ram, I used winrar to chunk activestates 
version over so I could code.

I added a Tk proglet to put perldoc output in a text widget, using msdos 
window without decent pager is grating.  TG4Perl!

Phil <-typing with one hand bites

PS patiently waiting on right hand to get over its pain-in-the-joints 
attitude so i can add auto-indexing and linking feature to my pathetic 
proglet.



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

Date: Sat, 06 Nov 2004 00:31:07 -0500
From: wana <ioneabu@yahoo.com>
Subject: Re: an original perldoc viewer
Message-Id: <10ool2g100o9he5@news.supernews.com>

A. Sinan Unur wrote:

> wana <ioneabu@yahoo.com> wrote in
> news:10ooglasp5pf7a1@news.supernews.com:
> 
>> I have been reprimanded for my lack of knowledge of perldoc material
>> so I have decided to do more reading.  I realized that I am often (%50
>> of the time) working on a machine that does not have Perl but is
>> connected to the internet.
> 
> Why don't you have Perl on the machine where you are doing your
> development?

My laptop, which I do most development on, has Perl.  It is a Toshiba
Satellite with Suse Linux which turned out to be a perfect Windows
replacement.

I am a complete amateur programmer in the sense that my job does not involve
programming at all.  I am lucky in the sense that we are very well
connected at work with many Windows machines connected to the internet via
cable modem.  I have enough free time during the day to browse around
online and connect via ssh to my web provider which is really the most fun
place to do Perl programming for me (I can only use vi as editor there).

I do hope to someday make a career of developing software when I get good
enough.  For now, I only get a few precious hours during the week with my
Linux laptop.

At work, my PDA can connect to the internet wirelessly, so my little program
is perfect for a quick perldoc read.  I have it running online at an
undisclosed location (just in case it's not totally secure).

wana


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

Date: 5 Nov 2004 18:03:18 -0800
From: furoco@blueyonder.co.uk (Doc)
Subject: Calling a CGI script from local PC vs server
Message-Id: <8e2a6205.0411051803.12cc55eb@posting.google.com>

Hi,

I have the test script (bottom) which works fine if you invoke it from
the HTML form at:

http://www.learnitfirm.com/LearningResources/HTML/Resources/SampleForm.htm

If I run SampleForm.htm from my C: drive or even from another web
server (changing the action property to

  action="http://www.learnitfirm.com/bin/printvars.cgi")

the script runs (showing "Thank you") but no data is listed.

Please tell me I am missing something simple - any ideas folks?

Thanks

##### printvars.cgi below #########

#!/usr/local/bin/perl

use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;

print header;
print start_html("Thank You");
print h2("Thank You");

my %form;
foreach my $p (param()) {
    $form{$p} = param($p);
    print "$p = $form{$p}<br>\n";
}
print end_html;


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

Date: 6 Nov 2004 02:31:33 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Calling a CGI script from local PC vs server
Message-Id: <Xns9598DAF8E8AE4asu1cornelledu@132.236.56.8>

furoco@blueyonder.co.uk (Doc) wrote in
news:8e2a6205.0411051803.12cc55eb@posting.google.com: 

First off, you are asking an off-topic question. Please keep in mind that 
Perl is not CGI and CGI is not Perl.

Second, you are asking a question that should first have been directed to 
the whomever is providing the hidden URL redirection service.

At this point, you should take a break and go ahead the posting guidelines 
for this newsgroup.

> I have the test script (bottom) which works fine if you invoke it from
> the HTML form at:
> 
> http://www.learnitfirm.com/LearningResources/HTML/Resources/SampleForm.
> htm 
> 
> If I run SampleForm.htm from my C: drive or even from another web
> server (changing the action property to
> 
>   action="http://www.learnitfirm.com/bin/printvars.cgi")
> 
> the script runs (showing "Thank you") but no data is listed.

That is because the web page relies on hidden frames to route requests. 

www.learnitfirm.com resolves to 63.85.86.83. http://63.85.86.83/ takes me 
to a "Coming soon!".

If you actually checked the source of the SampleForm.htm top level frame 
(which is hidden) you'd see the crap below:

<html>
<head>
</head>

<frameset rows=100%,* scrolling=no frameborder=0 framespacing=0>

<frame name=08439ed06892e30e5d45a5f322ad65c scrolling=auto noresize 
target=08439ed06892e30e5d45a5f322ad65c 
src="http://www.ukwebtech.pwp.blueyonder.co.uk/LearningResources/HTML/Resou
rces/SampleForm.htm">

<noframes>
<body>
<font color=#000000><p>This page uses frames, but your browser doesn't 
support them.</p>

<p>Click <a 
href="http://www.ukwebtech.pwp.blueyonder.co.uk/LearningResources/HTML/Reso
urces/SampleForm.htm">here</a> to continue.</p></font>

</body>
</noframes>
</frameset>
<body>
</body>
</html>

> Please tell me I am missing something simple - any ideas folks?

In real life, your CGI script seems to live at

http://www.ukwebtech.pwp.blueyonder.co.uk/bin/printvars.cgi

Why don't you use that?

Of course, none of this has anything to do with Perl.

Sinan


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

Date: Sat, 06 Nov 2004 03:38:29 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Calling a CGI script from local PC vs server
Message-Id: <2v2rnoF2gdk2eU1@uni-berlin.de>

Doc wrote:
> I have the test script (bottom) which works fine if you invoke it from
> the HTML form at:
> 
> http://www.learnitfirm.com/LearningResources/HTML/Resources/SampleForm.htm
> 
> If I run SampleForm.htm from my C: drive or even from another web
> server (changing the action property to
> 
>   action="http://www.learnitfirm.com/bin/printvars.cgi")
> 
> the script runs (showing "Thank you") but no data is listed.

Can it possibly be that the web server has been configured to only 
accept local HTTP requests?

> Please tell me I am missing something simple - any ideas folks?

You are missing that this is a group for discussing Perl programming, 
while your question is about web servers, CGI, HTTP, etc. To increase 
your chances to get a better answer, I'd suggest that you try 
comp.infosystems.www.authoring.cgi instead.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Fri, 5 Nov 2004 18:16:14 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Check POP3 E-mail
Message-Id: <slrncoo5ue.hra.tadmc@magna.augustmail.com>

David Gale <dsgSPAMFILTER@alum.dartmouth.org> wrote:

> my $var;
> my $var = 0;
> my $var = '';
> 
> are all equivalent statements, 


No they're not.

$var gets 3 different values for the 3 different statements,
I don't see that as "equivalent"!


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


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

Date: 5 Nov 2004 23:58:55 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: EOF issue
Message-Id: <Xns9598C1183A04Easu1cornelledu@132.236.56.8>

"IanW" <onedoesnot@needto.know> wrote in
news:cmg8is$vm4$1@blackmamba.itd.rl.ac.uk: 

> "Tad McClellan" <tadmc@augustmail.com> wrote in message
> news:slrncon27d.glk.tadmc@magna.augustmail.com...
> [..]
>>    {
>>       local $/ = "===============\n";
>>       push @chunk, $_ while <FILE>;
>>       chomp @chunk;                    # chomp() knows what to remove
>>       too! 
>>    }
> 
> where would one process each chunk in that - it seems to just slurp
> every line of the file into @chunk except the "=" x 15 ones?

You might want to try and see what each element of the array holds as well 
as read about $/ in perldoc perlvar.

Sinan.


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

Date: Sat, 06 Nov 2004 00:29:26 GMT
From: "Peter Wyzl" <wyzelli@yahoo.com>
Subject: Re: EOF issue
Message-Id: <GVUid.17705$K7.14654@news-server.bigpond.net.au>

"Uri Guttman" <uri@stemsystems.com> wrote in message 
news:x7pt2s48j0.fsf@mail.sysarch.com...
>>>>>> "PW" == Peter Wyzl <wyzelli@yahoo.com> writes:
>
>  PW> default.
>  PW> {
>  PW>     local $/ = ''; #slurp mode
>
> that is paragraph mode. undef is the value for slurp mode.
> and File::Slurp is faster and a nicer API IMO :).

Oops.  For the benefit of OT, I got away with that while testing because 
there happen to be no 'paragraphs' in the sample file, so it all slurps into 
one paragraph.  Were there paragraphs in the file, strange things could 
result.  'Slurp' mode is what I wanted.  I also meant to add the caveat that 
with large files this will consume lots of memory, but since you seem to be 
assigning all the file to @chunk anyway I didn't think it would be a 
problem.

Seems my sig got broken too... :(

-- 
Wyzelli
print while <DATA>;
__DATA__
Just another Perl Hacker 




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

Date: Fri, 5 Nov 2004 18:09:24 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: EOF issue
Message-Id: <slrncoo5hk.hra.tadmc@magna.augustmail.com>

IanW <onedoesnot@needto.know> wrote:
> "Tad McClellan" <tadmc@augustmail.com> wrote in message
> news:slrncon27d.glk.tadmc@magna.augustmail.com...
> [..]
>>    {
>>       local $/ = "===============\n";
>>       push @chunk, $_ while <FILE>;
>>       chomp @chunk;                    # chomp() knows what to remove too!
>>    }
> 
> where would one process each chunk in that 


You wouldn't, you could process each chunk _outside_ of that
by iterating over @chunk.

If you want to process chunks as they come in rather than gather
them all into an array, then you can do that to:

   {
      local $/ = "===============\n";
      while ( <FILE> ) {
         # process chunk (a multiline string)
      }
   }


> - it seems to just slurp every
> line of the file into @chunk 


Each element of @chunk is, well, a chunk. You had a single chunk
in @chunk in your code with a _line_ from the chunk as the
array elements.


> except the "=" x 15 ones?


No, it gets the =15 ones too, but the chomp() then removes them.


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


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

Date: Sat, 6 Nov 2004 05:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 6.14: How can I print out a word-frequency or line-frequency summary?
Message-Id: <cmhlu5$s8p$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.

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

6.14: How can I print out a word-frequency or line-frequency summary?

    To do this, you have to parse out each word in the input stream. We'll
    pretend that by word you mean chunk of alphabetics, hyphens, or
    apostrophes, rather than the non-whitespace chunk idea of a word given
    in the previous question:

        while (<>) {
            while ( /(\b[^\W_\d][\w'-]+\b)/g ) {   # misses "`sheep'"
                $seen{$1}++;
            }
        }
        while ( ($word, $count) = each %seen ) {
            print "$count $word\n";
        }

    If you wanted to do the same thing for lines, you wouldn't need a
    regular expression:

        while (<>) {
            $seen{$_}++;
        }
        while ( ($line, $count) = each %seen ) {
            print "$count $line";
        }

    If you want these output in a sorted order, see perlfaq4: ``How do I
    sort a hash (optionally by value instead of key)?''.



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

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: Sat, 6 Nov 2004 14:17:01 +1300
From: "Tintin" <tintin@invalid.invalid>
Subject: Lexical file handles
Message-Id: <2v2mtvF2gonq3U1@uni-berlin.de>

Now that recent versions of Perl have lexical file handles, can anyone give 
me some practical examples of why they are useful/better.

The only thing I can think of is that with 'use strict', you'll catch typos 
in your filehandles, however I'm sure there's plenty of other reasons. 




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

Date: Sat, 06 Nov 2004 02:19:39 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Lexical file handles
Message-Id: <2v2neoF2ga96kU1@uni-berlin.de>

Tintin wrote:
> Now that recent versions of Perl have lexical file handles, can
> anyone give me some practical examples of why they are useful/better.
> 
> The only thing I can think of is that with 'use strict', you'll catch
> typos in your filehandles, however I'm sure there's plenty of other
> reasons.

They are automatically closed when out of scope.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Sat, 06 Nov 2004 01:31:48 GMT
From: Ala Qumsieh <notvalid@email.com>
Subject: Re: Lexical file handles
Message-Id: <8QVid.38910$QJ3.4416@newssvr21.news.prodigy.com>

Tintin wrote:

> Now that recent versions of Perl have lexical file handles, can anyone give 
> me some practical examples of why they are useful/better.

They are not global anymore.

Like any other lexical variable, filehandles should be constrained to 
the narrowest scope possible. One side effect of undef()ing a lexical 
filehandle is that it closes the handle. So, I often do this:

	{
	  open my $fh, $file or die ...;
	  while (<$fh>) { ... }
	}

This will automatically close my filehandle upon reaching the end of the 
block. It also lets me use $fh for every file I open (assuming I have 
only one open at a time) with no fear of stomping on other variables.

It is also easier to pass it to subroutines as argument.

--Ala


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

Date: Fri, 5 Nov 2004 18:30:20 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: lists,shift,subs and dumb question
Message-Id: <slrncoo6os.hra.tadmc@magna.augustmail.com>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> Uri Guttman wrote:
>> Jeff Thies writes:
>>> Thanks, Looks like I made a List of lists without realizing it.
>>> (('val1',),('val3'))
>> 
>> huh? that isn't a list of lists.
> 
> Quote from "perldoc perldata":
> "The list 1,,3 is a concatenation of two lists, ..."


A list-of-lists has nested lists, a concatenation of two lists
has no nesting going on. They are not at all the same thing.


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


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

Date: Sat, 06 Nov 2004 02:55:09 GMT
From: "J M" <JM@jm.biz>
Subject: pulling or getting perl script name inside script
Message-Id: <h2Xid.22397$Al3.22119@newssvr30.news.prodigy.com>

I have writeLog sub across several perl scripts that I use to generate logs 
from scripts.  I like to put script name in side log. Until now I have been 
manually putting script name in writeLog sub but is there a way to pull 
script name dynamically so I don't have to use static script names inside 
perl script?  TIA! 




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

Date: 6 Nov 2004 02:58:58 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: pulling or getting perl script name inside script
Message-Id: <Xns9598DF9EC2E66asu1cornelledu@132.236.56.8>

"J M" <JM@jm.biz> wrote in
news:h2Xid.22397$Al3.22119@newssvr30.news.prodigy.com: 

> I have writeLog sub across several perl scripts that I use to generate
> logs from scripts.  I like to put script name in side log. Until now I
> have been manually putting script name in writeLog sub but is there a
> way to pull script name dynamically so I don't have to use static
> script names inside perl script?  TIA! 

D:\Home> cat I_ought_to_read_the_docs_before_posting
print "$0\n";

D:\Home> perl I_ought_to_read_the_docs_before_posting
I_ought_to_read_the_docs_before_posting

Specifically, perldoc perlvar

Sinan 



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

Date: Fri, 5 Nov 2004 21:16:31 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: pulling or getting perl script name inside script
Message-Id: <slrncooggf.ic3.tadmc@magna.augustmail.com>

J M <JM@jm.biz> wrote:

> is there a way to pull 
> script name dynamically


No need to "pull" it from anywhere, it is already sitting there
in a scalar variable, waiting for you to use it.

A friendly Perl program:

   print 'Hi ', scalar(getpwuid($>)), ". My name is $0. How are you today?\n";
   #                                                ^^
   #                                                ^^ program name


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


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

Date: Sat, 06 Nov 2004 01:50:14 +0000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: Q: re Inline and Benchmark
Message-Id: <418c2f26$0$6552$5a62ac22@per-qv1-newsreader-01.iinet.net.au>

Tassilo v. Parseval wrote:
> Also sprach Sisyphus:
> 
> 
>>'sisyphus2()' despite addressing the "buffer duplication" issue, is 
>>about 4 times slower than 'sisyphus()'. This is because 'sv_insert()' is 
>>  slow. Maybe there's a more efficient way of setting the characters of 
>>a SV to random values. If there is, then I couldn't find it, and we'll 
>>have to wait for someone else to tell us about it.
> 
> 
> Why not just SvGROW the SV to the desired length and afterwards 
>     
>     i = 0;
>     while (i < l)
> 	SvPVX(sv)[i++] = rand() % 256;
> 
> SvPVX returns the address of the C-string stored in the SV. Once you
> know that the SV is at least a PV you can do it.
> 
> Tassilo

NEWSV() creates the string of the desired length - so, unless I'm 
missing the point, there's no need for SvGROW(). I've replaced each 'l' 
with 'len' for readability ... something I should have done earlier.

          SV * fastest () {
              SV * outsv;
              int    i;
              int    len = 20000;

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

	     for (i = 0; i < len; i ++) {
                   SvPVX(outsv)[i++] = rand() % 256;
              }
	     SvPOK_on(outsv);
	     SvCUR_set(outsv, len);
              return outsv;
          }

That's clearly the fastest way of doing it. It's twice as fast as 
sisyphus(). That damned warning about the uninitialised subroutine 
entry, which seems somehow connected with my use of sv_insert(), also 
disappears. (I'm going to have to ask about that crazy warning on the XS 
list. I know why it normally appears, and how to deliberately create it, 
but I can't for the life of me work out why the sisyphus() code produces 
it.)

So ... is the above as you intended ? It produces strings of the correct 
length and they seem to be random. But whereas sisyphus() and 
sisyphus2() produce the same random string, fastest() produces a 
different string - though there's a significant (offset) section that 
*does* match.

The answer is probably staring me in the face. My perlapi docs claim 
that the SV (ie 'outsv') must contain a string - and I wonder if there's 
any guarantee that it does (initially) and what happens when it contains 
more than one NULL character.

There's something I've not done quite right. With luck, things will be 
quiet at work tonight and I might get a chance to work it out myself ....

Cheers,
Rob

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



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

Date: Sat, 06 Nov 2004 02:08:30 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: remove unwanted parts from strings
Message-Id: <ymWid.400$6t.91@trnddc05>

bingster wrote:
> If there is a string like this:
> $test = 'a bc (B, M, D),d e (B, M),lfm (D)'
> how can I remove all the '(*.)' parts to make it something like:
> 'a bc,d e,lfm'
>
> I tried:
> $test =~ s/\(*.\)//g;
> But the result is 'a bc (B, M, ,d e (B, ,lfm '.

As others have pointed out you probably don't want /*./ but rather /.*/
Add a non-greedy marker to the recipe and you are done:

    $_ = 'a bc (B, M, D),d e (B, M),lfm (D)';
    s/\(.*?\)//g;
    print;

For further details please see "perldoc perlre", section "Regular 
Expressions", paragraph starting with
    "By default, a quantified subpattern is "greedy", that is, ... "

jue 




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

Date: Sat, 06 Nov 2004 02:10:44 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: remove unwanted parts from strings
Message-Id: <EoWid.401$6t.359@trnddc05>

Lars Eighner wrote:
[convoluted way to create a non-greedy expression snipped]

> I believe there are other ways to make regular expressions less
> greedy, and perhaps some of them are better, but this makes sense
> to me.

Yep, there is. Just append a "?" to the quantifier, exactly as described in 
the very paragraph you started to quote.

jue 




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

Date: 5 Nov 2004 18:28:02 -0800
From: bulk88@hotmail.com (buildmorelines)
Subject: sanity checking proxy URL before passing to LWP
Message-Id: <ee659c69.0411051828.269a891d@posting.google.com>

What is the best/normal/typical way of validating or sanity checking a
URL that a user gave that will become the proxy address that will get
passed to LWP, I would prefer modules if possible? If it isnt
acceptable to let LWP error with "501 Protocol scheme '' is not
supported".

Also are there any modules that will turn something like "localhost"
into "http://localhost/" because LWP says "501 Protocol scheme '' is
not supported" if I just give it "localhost". Also do I need to worry
about https addresses?

Would all of I want to do work by making a regular expression such as
m/http(|s):\/\/.+/i (invented myself)?


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

Date: 6 Nov 2004 02:33:05 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: sanity checking proxy URL before passing to LWP
Message-Id: <Xns9598DB3B5F3C3asu1cornelledu@132.236.56.8>

bulk88@hotmail.com (buildmorelines) wrote in 
news:ee659c69.0411051828.269a891d@posting.google.com:

> What is the best/normal/typical way of validating or sanity checking a
> URL that a user gave that will become the proxy address that will get
> passed to LWP, I would prefer modules if possible? 

Search CPAN for Regexp::Common.

> Would all of I want to do work by making a regular expression such as
> m/http(|s):\/\/.+/i (invented myself)?

I am not sure what you mean?

Sinan.


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

Date: Sat, 6 Nov 2004 14:08:51 +1300
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: Solaris taking over Perl ownership
Message-Id: <2v2melF2gvuphU1@uni-berlin.de>


"Andrew Hamm" <ahamm@mail.com> wrote in message 
news:2v0dulF2fjks0U1@uni-berlin.de...
>
> 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.

Would installing the latest Perl Solaris package from 
http://sunfreeware.com/ be useful for you? 




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

Date: 5 Nov 2004 17:09:04 -0800
From: krakle@visto.com (krakle)
Subject: Re: Solaris taking over Perl ownership
Message-Id: <237aaff8.0411051709.66c732ae@posting.google.com>

Abigail <abigail@abigail.nl> wrote in message news:<slrncomchf.mg8.abigail@alexandra.abigail.nl>...
> However, IIRC (I don't have a box I can check at the moment) on Solaris,
> the "system" perl

The what? perl? What's that? You mean Perl.

> isn't /usr/bin/perl - instead, /usr/bin/perl is a link
> to the "system" perl.

perl? You mean 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
                  ^^^                            ^^^

Correct those 2 to Perl.
 
> I think SUN did a better job of dealing with perl than many other OSses
                                               ^^^

Perl.

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

And you finally learned :)

I love the hypocritical Perl community whose corrections of others are
their own mistakes... God bless us...


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

Date: Fri, 5 Nov 2004 21:02:36 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Solaris taking over Perl ownership
Message-Id: <slrncoofmc.i8r.tadmc@magna.augustmail.com>

Pinocchio <krakle@visto.com> wrote:
> Abigail <abigail@abigail.nl> wrote in message news:<slrncomchf.mg8.abigail@alexandra.abigail.nl>...
>> However, IIRC (I don't have a box I can check at the moment) on Solaris,
>> the "system" perl
> 
> The what? perl? What's that? You mean Perl.


No he didn't.


>> isn't /usr/bin/perl - instead, /usr/bin/perl is a link
>> to the "system" perl.
> 
> perl? You mean Perl.


No he didn't.


>> 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
>                   ^^^                            ^^^
> 
> Correct those 2 to Perl.


No corrections are needed, since there are no mistakes there.


>> I think SUN did a better job of dealing with perl than many other OSses
>                                                ^^^
> 
> Perl.


No, perl.


>> Why is the opinion of the Perl community important related to this issue?
> 
> And you finally learned :)


No, finally he wanted to refer to the programming language while
earlier he had been referring to the perl binary (the interpreter).


> I love the hypocritical Perl community whose corrections of others are
> their own mistakes... God bless us...


And I love those anti-community posters who display their ignorance
to thousands of people around the world while trying to sound
authoritative.

There is a FAQ about the difference between "perl" and "Perl" you know.


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


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

Date: Sat, 6 Nov 2004 16:10:49 +1300
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: Solaris taking over Perl ownership
Message-Id: <2v2tjbF2gaj8aU1@uni-berlin.de>


"krakle" <krakle@visto.com> wrote in message 
news:237aaff8.0411051709.66c732ae@posting.google.com...
> Abigail <abigail@abigail.nl> wrote in message 
> news:<slrncomchf.mg8.abigail@alexandra.abigail.nl>...
>> However, IIRC (I don't have a box I can check at the moment) on Solaris,
>> the "system" perl
>
> The what? perl? What's that? You mean Perl.
>
>> isn't /usr/bin/perl - instead, /usr/bin/perl is a link
>> to the "system" perl.
>
> perl? You mean Perl.

No, he wrote 'perl' and really did mean 'perl', because it is 'perl'.

You need to recheck the FAQ.

perldoc -q difference

>
>> 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
>                  ^^^                            ^^^
>
> Correct those 2 to Perl.

s/Correct those 2/It would be incorrect to change them/

>
>> I think SUN did a better job of dealing with perl than many other OSses
>                                               ^^^
>
> Perl.
>
>> Why is the opinion of the Perl community important related to this issue?
>
> And you finally learned :)

And wouldn't it be nice if you checked the FAQ and learned the difference 
yourself.


> I love the hypocritical Perl community whose corrections of others are
> their own mistakes... God bless us...

Pot, kettle, black 




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

Date: 5 Nov 2004 17:31:41 -0800
From: "EH" <bogusasdfasdf@hotmail.com>
Subject: Re: Using libwww to retrieve a UTF-8 webpage
Message-Id: <1099704701.439652.204000@f14g2000cwb.googlegroups.com>

It turns out at least part of my problem was that Google detects the
user agent and sends a different type of encoding depending on the
capabilities of the receiving browser.  If I pretend that I'm IE 6.0,
I'll get a meta header that says the document is UTF-8, but
unfortunately, the document is still not saved correctly.  I changed
the above code to be:

use utf8;
use Encode;
use LWP::UserAgent;

$ua = LWP::UserAgent->new;

my @ns_headers = (
'User-Agent' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
 .NET CLR 1.1.4322)',
'Accept' => 'text/html, 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";
#$url = "http://news.google.com.tw/news?ned=it&hl=it";

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);

If anyone has any suggestions on how I can correctly save UTF-8 pages,
I would much appreciate it.



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

Date: 5 Nov 2004 17:28:55 -0800
From: mark_galeck_spam_magnet@yahoo.com (Mark Galecki)
Subject: why not    print $A[0]
Message-Id: <50064a21.0411051728.64f612e7@posting.google.com>

Hello,  

I am new to Perl.  The Perl FAQ, referenced in this newsgroup, says
"only simple scalar variables, not expressions or subscripts into
hashes or arrays, can be used with built-ins like print"

Where is this explained in the Camel book?  Or (equivalent question)
Why not?

(background:  I have been trying to do 
print $A[0] "foo";  
and that would not even  compile, where
$a = $A[0];  print $a "foo";
works fine, and also
close $A[0];
works.  So I just don't get it, why not, and I want to see this
explained in the Camel book - can't find it there so far...).

thank you

Mark Galeck


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

Date: Sat, 06 Nov 2004 01:37:22 -0000
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: why not    print $A[0]
Message-Id: <slrncooag9.ulo.tim@vegeta.saiyix>

Mark Galecki <mark_galeck_spam_magnet@yahoo.com> wrote:
>  I am new to Perl.  The Perl FAQ, referenced in this newsgroup, says
>  "only simple scalar variables, not expressions or subscripts into
>  hashes or arrays, can be used with built-ins like print"
>  
>  Where is this explained in the Camel book?  Or (equivalent question)
>  Why not?

Your question is out of context.  After some grepping, I tracked down
the FAQ you partially quoted.  It is perlfaq5: "How can I use
a filehandle indirectly?"  As this proper context (this "context" is
a recurring theme around here) states, the paragraph relates to the use
of *filehandles* with print(), printf(), and diamond operator.  Check
out `perldoc -f print`, `perldoc -f printf` and perlop for more details.

Context is important, in English as in Perl.  :)

HTH,
Tim Hammerquist


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

Date: Sat, 06 Nov 2004 02:55:02 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: why not    print $A[0]
Message-Id: <2v2p63F2gs0naU1@uni-berlin.de>

Mark Galecki wrote:
> The Perl FAQ, referenced in this newsgroup, says "only simple scalar
> variables, not expressions or subscripts into hashes or arrays, can
> be used with built-ins like print"

Where in the FAQ did you read that?

> Where is this explained in the Camel book?  Or (equivalent question)
> Why not?

How about giving some context...

> (background:  I have been trying to do
> print $A[0] "foo";
> and that would not even  compile,

This works fine:

     my @A;
     open $A[0], '> file';
     print { $A[0] } "foo\n";
     close $A[0];

You just need to take care of the ambiguity.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Fri, 05 Nov 2004 23:25:29 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Win32::OLE msxml collection problem
Message-Id: <418c0a7c.6643933@news.erols.com>

"Marcus" <lumbus@ludd.luth.se> wrote:

: This is probably a stupid questions since I'm a beginner in Win32::OLE and 
: Perl...
: In the code below I can get the length from $members, but the next line 
: outputs:
: "member array name: Win32::OLE=HASH(0x1825090)->Item(0)->{text}"
: 
: code:
: $members = $object->getElementsByTagName("BriefDescription");
: print "$members->{length}\n";
: print "member array name: $members->Item(0)->{text}\n";
                                    ^^^^^^^^^
Subroutine and method calls are not interpolated into double-quoted
strings.



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

Date: Sat, 06 Nov 2004 11:45:20 -0800
From: Simon Taylor <simon@unisolve.com.au>
Subject: Re: Win32::OLE msxml collection problem
Message-Id: <cmhdo5$185$1@otis.netspace.net.au>

Jay Tilton wrote:
> "Marcus" <lumbus@ludd.luth.se> wrote:
> 
> : This is probably a stupid questions since I'm a beginner in Win32::OLE and 
> : In the code below I can get the length from $members, but the next line 
> : outputs:
> : "member array name: Win32::OLE=HASH(0x1825090)->Item(0)->{text}"
> : 
> : code:
> : $members = $object->getElementsByTagName("BriefDescription");
> : print "$members->{length}\n";
> : print "member array name: $members->Item(0)->{text}\n";
>                                     ^^^^^^^^^
> Subroutine and method calls are not interpolated into double-quoted
> strings.

Quite right, unless of course one dereferences the method call
and then creates a scalar reference to that with the ${ } construct,
in which case a method call can be interpolated in double-quoted string
context, as in:

#!/usr/bin/perl
use strict;
use warnings;
use CGI;

my $q = new CGI;
print "Not the output of the header method: $q->header()\n";
print "The output of the header method: ${ \$q->header() }\n";

Simon Taylor




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

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 7367
***************************************


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