[29483] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 727 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 7 21:10:21 2007

Date: Tue, 7 Aug 2007 18:09:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 7 Aug 2007     Volume: 11 Number: 727

Today's topics:
        flood coming to free.superphone.canada <numdafi@supernews.com>
    Re: module OpenOffice::OODoc fails with Unicode charact <invalid@invalid.org>
    Re: progress report ideas? xhoster@gmail.com
    Re: simple Perl CGI scripts help <glex_no-spam@qwest-spam-no.invalid>
    Re: Size of all files in a directory? <noreply@gunnar.cc>
    Re: Size of all files in a directory? <brian.helterline@hp.com>
    Re: Size of all files in a directory? <mritty@gmail.com>
    Re: Size of all files in a directory? <noreply@gunnar.cc>
    Re: Size of all files in a directory? <mritty@gmail.com>
    Re: Subroutines and '&' <g_m@remove-comcast.net>
    Re: Subroutines and '&' (Randal L. Schwartz)
    Re: Subroutines and '&' <g_m@remove-comcast.net>
    Re: Subroutines and '&' (Randal L. Schwartz)
    Re: Subroutines and '&' <g_m@remove-comcast.net>
    Re: Subroutines and '&' <mritty@gmail.com>
    Re: Subroutines and '&' <wahab@chemie.uni-halle.de>
    Re: Subroutines and '&' <dummy@example.com>
    Re: Subroutines and '&' <No_4@dsl.pipex.com>
    Re: Tuning - Styling <damorgan@psoug.org>
    Re: Tuning - Styling <ian-news@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 7 Aug 2007 22:03:58 GMT
From: Peter Pearson <numdafi@supernews.com>
Subject: flood coming to free.superphone.canada
Message-Id: <kqdueo4tmbyat70ysrm404o1inqjqad@4ax.com>

To avoid the flood, join me at Supernews.

Sign up for a risk-free trial.

https://www.supernews.com/signup/

--
They are shoping rather than clever, in conjunction with coming, underneath coastal males.



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

Date: Tue, 07 Aug 2007 20:34:42 +0200
From: David Sudlow <invalid@invalid.org>
Subject: Re: module OpenOffice::OODoc fails with Unicode characters
Message-Id: <46b8bb48$0$27411$ba4acef3@news.orange.fr>

Christian Winter wrote:
> David Sudlow wrote:
>> When I try to write out a utf8 string using extendText(), 
>> appendParagraph or other methods with the OpenOffice::OODoc module, I 
>> get the following error:
>>
>> Cannot decode string with wide characters at C:/Perl/lib/Encode.pm 
>> line 162.
>>
>> I have the localEncoding set to utf8 as I should and it reads in fine 
>> from an office document containing utf8 characters.
>>
>> Here is a short but complete script that illustrates the issue:
>>
>> use strict;
>> use warnings;
>> use OpenOffice::OODoc;
> 
> Insert
>   use Encode qw(encode);
> here...
> 
>>
>> ooLocalEncoding('utf8');
>>
>> my $archive = OpenOffice::OODoc::File->new(
>>         "my_document.odt",
>>         create => "text");
>>
>>
>> my $text = ooDocument(
>>     archive => $archive,
>>     member => 'content'
>>     );
>>
> 
> ...and make this:
> 
>> $text->appendParagraph(text => "hello\x{100}");
> 
> my $hello = encode('utf-8', "hello\x{100}");
> $text->appendParagraph(text => $hello);
> 
>> $archive->save();
> 
> and things should work. appendParagraph() seemingly expects the
> text parameter to be a series of utf-8 octets, while "hello\x{100}"
> creates a string with a wide character in Perl's native encoding.
> 
> HTH
> -Chris

Thanks, this works (in my real code as well as the example). It feels 
like a bit of a kludge though. Shouldn't there be a way to tell perl to 
pass utf-8 strings without the explicit conversion, given that I am 
reading in utf8 and passing it to a function that expects utf8?

Would you consider this a perl issue or an OpenOffice::OODoc issue an 
'Encode' issue or 'expected behaviour'?

Dave


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

Date: 07 Aug 2007 19:07:18 GMT
From: xhoster@gmail.com
Subject: Re: progress report ideas?
Message-Id: <20070807150720.698$Hi@newsreader.com>

"~greg" <g_m@remove-comcast.net> wrote:
> Whenever I write a script that could take more than a few seconds,
> I always make it report its progress, so that I'll at least know
> that it's doing something, and not caught in an infinite loop.
>
> Sometimes this points up an inefficiency in the program.
> But I am really only talking about peace of mind,
> and not formal Benchmarking.
> Or elaborate formal progress reports for final users.
>
> What I usually do is use a natural index, or a dedicated counter,
> and put a line something like this somewhere in the script:
>
>     print "$COUNT\n" if $COUNT++  % $MODULUS   == 0;

That only assures you that the infinite loop you are caught in does not
(or does) include the above statement.

>
> that that is what is really wanted!
> --a progress report
> that reliably prints out at fixed time intervals,
> such as every 5 seconds.

5 seconds intervals happen whether you are in an infinite loop or not.

>
> "alarm", or something like it, would have to be used.

{
  local $SIG{ALRM}= sub { print ".\n"; alarm 10 };
  alarm 10;
  #whatever slow code here.
  alarm 0;
};


> Which just reminded me (just now)
> that I never much liked (or even understood) signal handling.

It varies from OS to OS and perl version to version.

>
> ~~
>
> So, my question is, has anybody already done anything like that?
> - progress reports at fixed time intervals?

Yes.  I use alarm.  But the goal is not to actually report progress, but
simply to keep an impatient connection from timing out.

>
> Or, more generally, what styles of progress reports do people use?

I've tried assigning a status to $0 as an unobtrusive way of doing
that.  That way if you can see the status if you want, but it doesn't
scroll across your screen or fill your log files when you aren't
interested. To see the contents of $0, on my linux system, you can run top
and hit 'c' to toggle command line.  The reported process name is whatever
you set $0 to.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Tue, 07 Aug 2007 14:36:01 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: simple Perl CGI scripts help
Message-Id: <46b8c9a1$0$10310$815e3792@news.qwest.net>

CAT wrote:
> On Aug 7, 12:02 pm, Ian Wilson <scoblo...@infotop.co.uk> wrote:
>> CAT wrote:
>>
>>> I am using this showme.cgi scripts to run the remote scripts check.sh
[...]
> Thanks all, the above replies are very helpful to improve my perl
> programming skill, I already revised my codes according all of your
> suggestions.

That's amazing, since you haven't posted any perl code.

> 
> My problem is still on the local side, I could run the perl scripts on
> command line without any problem, however, whenever I tried to use web
> interface, I will get the problem. ( it is wired that if I click the
> button after 20 minutes or longer, it works, then, if I click again,
> it will hang there, I cleared the cache file each time).

Well then, it must be wired wrong.  Make sure red connects to red
and black connects to black.

Read the "Posting Guidelines for comp.lang.perl.misc", next time.


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

Date: Tue, 07 Aug 2007 20:06:01 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Size of all files in a directory?
Message-Id: <5hrqquF3mk2sgU1@mid.individual.net>

Paul Lalli wrote:
> On Aug 7, 12:45 pm, Bill H <b...@ts1000.us> wrote:
>> There is probably a perl command for this but I can't seem to find it
>> (and knowing how my questions have been answered in the FAQ posting
>> recently it will probably show up in a few minutes). But here goes, is
>> there a command for getting the size of all the files in a directory
>> (total size)?
> 
> No, but it's not exactly difficult to do in a couple commands:
> 
> use List::Util qw/sum/;
> open my $dh, $dir or die "Cannot open directory $dir: $!":

Suppose you mean

    opendir ...

> my $total_size = sum( map { -f "$dir/$_" ? -s _ : 0 }  }
> readdir($dh));
> 
> Written out more explicitly:
> open my $dh, $dir or die "Cannot open directory $dir: $!":

Same.

> my $total_size = 0;
> while (my $file = readdir($dh)) {
>    next if !-f "$dir/$file";
>    $total_size += -s _;
> }

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


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

Date: Tue, 07 Aug 2007 11:12:00 -0700
From: Brian Helterlilne <brian.helterline@hp.com>
Subject: Re: Size of all files in a directory?
Message-Id: <f9aclg$ivi$1@usenet01.boi.hp.com>

Paul Lalli wrote:
> On Aug 7, 12:45 pm, Bill H <b...@ts1000.us> wrote:
>> There is probably a perl command for this but I can't seem to find it
>> (and knowing how my questions have been answered in the FAQ posting
>> recently it will probably show up in a few minutes). But here goes, is
>> there a command for getting the size of all the files in a directory
>> (total size)?
> 
> No, but it's not exactly difficult to do in a couple commands:
> 
> use List::Util qw/sum/;
> open my $dh, $dir or die "Cannot open directory $dir: $!":

opendir

> my $total_size = sum( map { -f "$dir/$_" ? -s _ : 0 }  }
> readdir($dh));
> 
> Written out more explicitly:
> open my $dh, $dir or die "Cannot open directory $dir: $!":

opendir

> my $total_size = 0;
> while (my $file = readdir($dh)) {
>    next if !-f "$dir/$file";
>    $total_size += -s _;
> }


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

Date: Tue, 07 Aug 2007 13:01:43 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: Size of all files in a directory?
Message-Id: <1186516903.462609.239150@w3g2000hsg.googlegroups.com>

On Aug 7, 2:06 pm, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> Paul Lalli wrote:
> > open my $dh, $dir or die "Cannot open directory $dir: $!":
>
> Suppose you mean
>
>     opendir ...

Damnit.  That's the one bug I make all the time in my real programs
too, and am constantly confused as to why I'm not finding any files in
the directory.  Usually I catch it after 30 seconds...

I really wish readdir() returned an error if it was passed a
filehandle reference rather than a directoryhandle reference...

Thanks for the correction, Gunnar & Brian.

Paul Lalli



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

Date: Wed, 08 Aug 2007 00:07:15 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Size of all files in a directory?
Message-Id: <5hs8v8F3mksmiU1@mid.individual.net>

Paul Lalli wrote:
> I really wish readdir() returned an error if it was passed a
> filehandle reference rather than a directoryhandle reference...

$! seems to contain what you want.

$ cat test.pl
open( my $dh, '.' );
my @files = readdir $dh or die $!;
$ perl test.pl
Inappropriate ioctl for device at test.pl line 2.
$

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


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

Date: Tue, 07 Aug 2007 15:20:58 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: Size of all files in a directory?
Message-Id: <1186525258.233707.198480@o61g2000hsh.googlegroups.com>

On Aug 7, 6:07 pm, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote:
> Paul Lalli wrote:
> > I really wish readdir() returned an error if it was passed a
> > filehandle reference rather than a directoryhandle reference...
>
> $! seems to contain what you want.
>
> $ cat test.pl
> open( my $dh, '.' );
> my @files = readdir $dh or die $!;
> $ perl test.pl
> Inappropriate ioctl for device at test.pl line 2.

Yes, but if you're doing it the "right" way:

open my $dh, '.';
while (my $file = readdir $dh) {
   print "$file\n";
}

then you're not really given any reason to know that an operating
system error occurred.  It just looks like no files were read.   That
is, there's nothing intuitively telling me readdir returned false
because there was an OS error, or because the directory actually was
empty.  I guess I would rather it throw an exception.

Paul Lalli



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

Date: Tue, 7 Aug 2007 14:31:46 -0400
From: "~greg" <g_m@remove-comcast.net>
Subject: Re: Subroutines and '&'
Message-Id: <xv2dnRgSY4AfJCXbnZ2dnUVZ_ruqnZ2d@comcast.com>


"Bill H" <bill@ts1000.us> wrote in message news:1186485205.209362.86930@w3g2000hsg.googlegroups.com...
>I have always called my subroutines with an '&', Example:
>
> &something;
>
> sub something
> {
> return;
> }
>
> But I see in the perlfaq that the '&' isnt used. Is there any reason I
> should / should't be using the '&' or does it just not make a
> difference?



How old are you? :)

The reason that I ask is that I don't think that that syntax
has been required for a very long time. (Not since perl v5 I think).

It is still required,
but only when dealing with references (I think)
~~~

use strict;
use warnings;
# ;)

sub something
{
   print "something\n";
}

my $something = \&something;

$something->();

__END__








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

Date: Tue, 07 Aug 2007 11:32:34 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Subroutines and '&'
Message-Id: <867io7tcu5.fsf@blue.stonehenge.com>

>>>>> "Sherm" == Sherm Pendley <spamtrap@dot-app.org> writes:

Sherm> It *does* make a difference - if you don't know or understand what that
Sherm> difference is, or you don't specifically want the behavior specified by
Sherm> the &, you shouldn't use it.

Or, for the opposite point of view, if you have:

    sub log { print STDERR localtime() . ": @_\n" }

then you better darn well invoke it as:

     &log("my message");

and *not*:

    log("my message"); # invokes built-in logarithm function

And until you know all the perl built-ins, you should use &.  And this
is what we teach in Learning Perl.

Please don't be so quick to dismiss the value of the leading &.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
Posted via a free Usenet account from http://www.teranews.com



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

Date: Tue, 7 Aug 2007 14:57:33 -0400
From: "~greg" <g_m@remove-comcast.net>
Subject: Re: Subroutines and '&'
Message-Id: <-d-dnRNRepwdIiXbnZ2dnUVZ_hqdnZ2d@comcast.com>


"Randal L. Schwartz" <merlyn@stonehenge.com> wrote in message news:867io7tcu5.fsf@blue.stonehenge.com...
>>>>>> "Sherm" == Sherm Pendley <spamtrap@dot-app.org> writes:
>
> Sherm> It *does* make a difference - if you don't know or understand what that
> Sherm> difference is, or you don't specifically want the behavior specified by
> Sherm> the &, you shouldn't use it.
>
> Or, for the opposite point of view, if you have:
>
>    sub log { print STDERR localtime() . ": @_\n" }
>
> then you better darn well invoke it as:
>
>     &log("my message");
>
> and *not*:
>
>    log("my message"); # invokes built-in logarithm function
>
> And until you know all the perl built-ins, you should use &.  And this
> is what we teach in Learning Perl.
>
> Please don't be so quick to dismiss the value of the leading &.
>
> -- 
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
> <merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
> See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


Ah so!

    "Ambiguous call resolved as CORE::log(),
    qualify as such or use & at ...
    Argument "my message" isn't numeric in log at ...
    Can't take log of 0 at ... "

And here I had always just implicitly assumed that a user defined
function would override and hide a built-in!

But then again I have always capitalize my own function names -

  sub Log { ... }

So unless there are caplitalized built-ins,
then that should keep me out of this kind of trouble, no?

~greg










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

Date: Tue, 07 Aug 2007 11:54:47 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Subroutines and '&'
Message-Id: <86y7gnrx8o.fsf@blue.stonehenge.com>

>>>>> "~greg" == ~greg  <g_m@remove-comcast.net> writes:

~greg> It is still required,
~greg> but only when dealing with references (I think)

Or when dealing with a subroutine that is the same name as a built-in.
See my other post.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
Posted via a free Usenet account from http://www.teranews.com



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

Date: Tue, 7 Aug 2007 15:09:53 -0400
From: "~greg" <g_m@remove-comcast.net>
Subject: Re: Subroutines and '&'
Message-Id: <Ua2dnUTeQsP4XyXbnZ2dnUVZ_vOlnZ2d@comcast.com>

> > Randal L. Schwartz -  wrote ...
> > ....


I wrote >
> But then again I have always capitalize my own function names -
>  sub Log { ... }
> So unless there are caplitalized built-ins,
> then that should keep me out of this kind of trouble, no?
> ~greg



I call it "the ~gregian transform".

Not too profound - just a little trick to efficiently
keep me out of that kind of trouble and off the streets.

;)

~greg








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

Date: Tue, 07 Aug 2007 12:16:35 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: Subroutines and '&'
Message-Id: <1186514195.148512.141100@w3g2000hsg.googlegroups.com>

On Aug 7, 2:32 pm, mer...@stonehenge.com (Randal L. Schwartz) wrote:

> Or, for the opposite point of view, if you have:
>
>     sub log { print STDERR localtime() . ": @_\n" }
>
> then you better darn well invoke it as:
>
>      &log("my message");
>
> and *not*:
>
>     log("my message"); # invokes built-in logarithm function
>
> And until you know all the perl built-ins, you should use &.

The difference, of course, is that failing to use & when required will
generate a pretty explicit warning, while using it when you shouldn't
will not.  That's why I generally tell my students this is the one
tiny piece of Learning Perl that I disagree with. :-/

Paul Lalli



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

Date: Tue, 07 Aug 2007 21:26:35 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: Subroutines and '&'
Message-Id: <f9ah1a$u5q$1@nserver.hrz.tu-freiberg.de>

~greg wrote:
> It is still required,
> but only when dealing with references (I think)

And nonlocal context 'jumps':

    ...
    sub indirect { print "otherthing\n@_\n" };

    sub onething { goto &indirect; print "this wont show up\n" }

    onething( qw'A B C' );
    ...


Regards

M.


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

Date: Tue, 07 Aug 2007 21:40:07 GMT
From: "John W. Krahn" <dummy@example.com>
Subject: Re: Subroutines and '&'
Message-Id: <XE5ui.81203$tB5.1231@edtnps90>

Randal L. Schwartz wrote:
>>>>>> "Sherm" == Sherm Pendley <spamtrap@dot-app.org> writes:
> 
> Sherm> It *does* make a difference - if you don't know or understand what that
> Sherm> difference is, or you don't specifically want the behavior specified by
> Sherm> the &, you shouldn't use it.
> 
> Or, for the opposite point of view, if you have:
> 
>     sub log { print STDERR localtime() . ": @_\n" }
> 
> then you better darn well invoke it as:
> 
>      &log("my message");
> 
> and *not*:
> 
>     log("my message"); # invokes built-in logarithm function
> 
> And until you know all the perl built-ins, you should use &.  And this
> is what we teach in Learning Perl.
> 
> Please don't be so quick to dismiss the value of the leading &.

Fortunately the syntax highlighting in my editor of choice allows me to 
distinguish between built-in functions and user defined subroutines.

:-)


John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


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

Date: Wed, 08 Aug 2007 01:40:37 +0100
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: Subroutines and '&'
Message-Id: <o8adnSFj7_majCTbnZ2dnUVZ8sfinZ2d@pipex.net>

Randal L. Schwartz wrote:

> 
> And until you know all the perl built-ins, you should use &.  And this
> is what we teach in Learning Perl.

    Teach them to test the code they write too and such issues would never 
get into the wild.


-- 
              Just because I've written it doesn't mean that
                   either you or I have to believe it.


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

Date: Tue, 07 Aug 2007 14:13:15 -0700
From: DA Morgan <damorgan@psoug.org>
To:  airconditi@gmail.com
Subject: Re: Tuning - Styling
Message-Id: <46B8E06B.8090109@psoug.org>

airconditi@gmail.com wrote:
> Cool cars, tuning & styling, here you can find many tuned cars with
> tons of pictures!!!!!!!
> 
> http://tuning-styling.blogspot.com/

Too bad we won't be able to find someone that can break your
fingers to keep you from spamming every usenet group you can spell.

You have been reported to spamcop and google for violating your
terms of service your agreement.
-- 
Daniel A. Morgan
Puget Sound Oracle Users Group
www.psoug.org


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

Date: Wed, 08 Aug 2007 09:41:00 +1200
From: Ian Collins <ian-news@hotmail.com>
Subject: Re: Tuning - Styling
Message-Id: <5hs77cF3lvf8eU18@mid.individual.net>

DA Morgan wrote:
> 
> Too bad we won't be able to find someone that can break your
> fingers to keep you from spamming every usenet group you can spell.
> 
If you are going to reply to spam that decent news servers have filtered
out, please don't quote it!

-- 
Ian Collins.


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

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 V11 Issue 727
**************************************


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