[29490] in Perl-Users-Digest
Perl-Users Digest, Issue: 734 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 9 14:14:30 2007
Date: Thu, 9 Aug 2007 11:14:09 -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 Thu, 9 Aug 2007 Volume: 11 Number: 734
Today's topics:
Re: Size of all files in a directory? <mritty@gmail.com>
Re: Size of all files in a directory? <mritty@gmail.com>
Re: Size of all files in a directory? <g_m@remove-comcast.net>
Re: Size of all files in a directory? <g_m@remove-comcast.net>
Re: Size of all files in a directory? <yankeeinexile@gmail.com>
Re: SOAP::Lite "service" examples anno4000@radom.zrz.tu-berlin.de
Re: Subroutines and '&' <Peter@PSDT.com>
trying to use a proxy <nospam@home.com>
Re: trying to use a proxy himanshu.garg@gmail.com
Re: Windows based perl editor? anno4000@radom.zrz.tu-berlin.de
Re: Windows based perl editor? <brian.pat.kelly@googlemail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 09 Aug 2007 05:14:36 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Size of all files in a directory?
Message-Id: <1186661676.847761.269350@l70g2000hse.googlegroups.com>
On Aug 9, 1:08 am, "comp.llang.perl.moderated" <c...@blv-
sam-01.ca.boeing.com> wrote:
> On Aug 7, 3:20 pm, Paul Lalli <mri...@gmail.com> wrote:
> > 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.
>
> You could get something very similar with Fatal's "succeed or die"
> semantics:
Interesting, I hadn't considered that. Thanks for the idea. Of
course, that still requires me to remember to use Fatal any time I use
readdir, and if I remember the reason I'm using Fatal, I'm likely to
remember the mistake I keep making with open/opendir. :-)
Paul Lalli
------------------------------
Date: Thu, 09 Aug 2007 06:52:53 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Size of all files in a directory?
Message-Id: <1186667573.488213.70570@r34g2000hsd.googlegroups.com>
On Aug 9, 8:14 am, Paul Lalli <mri...@gmail.com> wrote:
> On Aug 9, 1:08 am, "comp.llang.perl.moderated" <c...@blv-
> sam-01.ca.boeing.com> wrote:
> > On Aug 7, 3:20 pm, Paul Lalli <mri...@gmail.com> wrote:
> > > 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.
>
> > You could get something very similar with Fatal's "succeed
> > or die" semantics:
>
> Interesting, I hadn't considered that. Thanks for the idea.
Uhm, I conditionally take that back. ;-) Fatal seems to severely
FUBAR readdir(). What am I doing wrong?
$ ls temp/
foo.1 foo.2 foo.3
$ perl -wle'
use Fatal qw/readdir/;
opendir my $dh, "temp" or die $!;
my @files = readdir($dh);
print for @files;
'
.
$ perl -wle'
#use Fatal qw/readdir/;
opendir my $dh, "temp" or die $!;
my @files = readdir($dh);
print for @files;
'
.
..
foo.1
foo.2
foo.3
It looks like when Fatal is use, readdir always acts like it's being
called in scalar context. That cannot be a good thing. . .
Paul Lalli
------------------------------
Date: Thu, 9 Aug 2007 11:59:05 -0400
From: "~greg" <g_m@remove-comcast.net>
Subject: Re: Size of all files in a directory?
Message-Id: <SsWdncBxPrg0pSbbnZ2dnUVZ_sHinZ2d@comcast.com>
"Paul Lalli" <mritty@gmail.com> wrote in message news: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
>
(It has been a very long time since I used Unix, and
I didn't totally understand even then,...)
But isn't "everything" in UNIX supposed to be a "file"?
Of course nothing is a "file", really, in the sense we imagine it
- as manila folder containing sundry paper items
such as dossiers and press clippings and dried pressed flowers
and the occasional baggy containing a bloody knive etc...,
all kept together with a bunch of other "files" in a cabinet with sliding drawers...
-- in other words it's all metaphor anyway,
so why isn't the metaphor kept consistent in the case of directories,
which really are just another "stream"?
------------------------------
Date: Thu, 9 Aug 2007 11:57:51 -0400
From: "~greg" <g_m@remove-comcast.net>
Subject: Re: Size of all files in a directory?
Message-Id: <SsWdncFxPrg0pSbbnZ2dnUVZ_sGvnZ2d@comcast.com>
not so fast...
changing
> $size += Size("$folder/$_") foreach (@folders);
to
> $size += SIZE("$folder/$_") foreach (@folders);
in SIZE()
so that it's recursive like it's supposed to be...
(no wonder it was processing gigabytes in nanoseconds! ;)
sorry, ...
~~~~~~~~~~~~
> use strict;
> use warnings;
>
> my $Folder = .... your folder ....';
>
> sub Size
> {
> my $folder = shift;
> my $size = 0;
> opendir DIR, $folder;
> $size += -s "$folder/$_" foreach grep {-f "$folder/$_"} readdir DIR;
> closedir DIR;
> return $size;
> }
>
>
> sub SIZE
> {
> my $folder = shift;
>
> my @folders;
> my @files;
> my $size = 0;
>
> opendir D, $folder;
>
> foreach (grep { $_ !~ /^\.\.?$/ } readdir D)
> {
> if (-d "$folder/$_") { push @folders, $_}
> elsif (-f "$folder/$_") { push @files, $_}
> }
>
> closedir D;
>
> $size += -s "$folder/$_" foreach (@files);
> $size += SIZE("$folder/$_") foreach (@folders);
>
> return $size;
> }
>
> sub Units
> {
> my $b = shift;
> my $k = int($b/1024);
> my $m = int($k/1024);
> my $g = int($m/1024);
> return $g . ' giga, ' . $m . ' mega, ' . $k . ' kilo, '. $b . " bytes.\n";
> }
>
> print "$Folder\n Size of files in folder =\n ";
> print Units( Size($Folder) );
>
> print "\n";
>
> print "$Folder\n Size of files in folder and subfolders =\n ";
> print Units( SIZE($Folder) );
>
>
> __END__
------------------------------
Date: 09 Aug 2007 11:15:53 -0500
From: Lawrence Statton <yankeeinexile@gmail.com>
Subject: Re: Size of all files in a directory?
Message-Id: <87sl6s8z0m.fsf@hummer.cluon.com>
"~greg" <g_m@remove-comcast.net> writes:
>
> But isn't "everything" in UNIX supposed to be a "file"?
>
> -- in other words it's all metaphor anyway,
> so why isn't the metaphor kept consistent in the case of directories,
> which really are just another "stream"?
But you can. You can open a directory and read it. There are even
header files for understanding what the stream of bytes means. And
those header files are used by convenient functions like opendir(3C)
and readdir(3C) to read that stream of octets and return convenient
dirent data structures.
This standard C library functionality is mirrored in the perl
functions of same name.
There is nothing (besides pain, anguish, and non-portability) stopping
you from opening /usr/local/bin as a file and grovelling through the
stream yourself and building a list of filenames and inodes and cruft.
--
Lawrence Statton - lawrenabae@abaluon.abaom s/aba/c/g
Computer software consists of only two components: ones and
zeros, in roughly equal proportions. All that is required is to
place them into the correct order.
------------------------------
Date: 9 Aug 2007 13:50:54 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: SOAP::Lite "service" examples
Message-Id: <5i0kduF3mdotsU1@mid.dfncis.de>
<xhoster@gmail.com> wrote in comp.lang.perl.misc:
[...]
> Isolating around the problem, starting at line 3003:
>
> foreach (@{$services->{$service}{parameters}}) {
> # next unless $_;
> $self->{'_stub'} .= " SOAP::Data->new(name => '".$_->name."',
> type => '".$_->type."', attr => {";
>
> So the commenting out of "next unless $_" allows truly empty $_ to reach
> the following line, triggering the error. However, if I comment it back
> in, then everything gets skipped, apparently because $_ is an object which
> seems to have overloaded operations which cause it to evaluate as false in
> this (stringification?) context.
Boolean. Overload generates a boolean value out of quite a few others,
most notably stringification. That often comes unexpected to the
programmer, as seems to be the case here.
> I changed the line to execute the "next"
> on only the values of $_ which are true empty strings, rather than objects
> with overloaded operations:
>
> next if not ref $_ and not $_;
If you can modify the "use overload" statement (I'm not quite clear
about what is where), adding
bool => sub { 1 },
would be an alternative. I'm not saying it's going to make a difference
but who knows. If there is a similar problem elsewhere it would be
fixed too.
Anno
------------------------------
Date: Thu, 09 Aug 2007 13:24:47 GMT
From: Peter Scott <Peter@PSDT.com>
Subject: Re: Subroutines and '&'
Message-Id: <pan.2007.08.09.13.24.46.888333@PSDT.com>
On Wed, 08 Aug 2007 12:35:52 -0500, Lawrence Statton wrote:
> merlyn@stonehenge.com (Randal L. Schwartz) writes:
>> That's a flaw with perl-mode. cperl-mode is far better, and actively
>> maintained. First thing I do with an empty .emacs file is teach it
>> to replace perl mode with cperl-mode. :)
>
> I agree with the solution to that *particular* problem, but as is oft
> said: Nothing but perl can parse Perl with absolute certainty. While
> cperl-mode does not get nearly as confused nearly as often as
> perl-mode did, I have succeeded in confusing its parser on occasion.
Me too. One reliable way of doing that is to use m or s as naked hash
keys. Still, happens seldom enough that it's worth it to me to work
around, usually with a comment that contains the delimiters it's looking
for.
--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/
------------------------------
Date: Thu, 09 Aug 2007 11:05:33 GMT
From: "Nospam" <nospam@home.com>
Subject: trying to use a proxy
Message-Id: <1yCui.12655$rr5.6540@newsfe1-win.ntli.net>
I am trying to use a proxy the same proxy works fine in ie6/firefox but for
some strange reason I get an uninitialised value when using the proxy in ANY
perl script, the code to use the proxy is:
use strict;
use warnings;
use LWP::Debug qw(+);
use WWW::Mechanize;
my $mech = WWW::Mechanize->new();
my $url =
http://news.google.co.uk/search?q=~%22fantastic+four%22&num=100&hl=en&safe=off&start=0&as_qdr=all&filter=0;
$mech->proxy('http','http://127.0.0.1:8088');
$mech->get($url);
my @links_to_check = grep { $_->url() !~ /google/i}
$mech->find_all_links( url_regex => qr/\./i );
foreach my $links_to_check (@links_to_check)
{
print "$links_to_check \n";
}
with LWP::Debug qw(+) I receive
LWP::UserAgent::new: () LWP::UserAgent::proxy: http http://127.0.0.1:8088
LWP::UserAgent::request: () HTTP::Cookies::add_cookie_header: Checking
news.google.co.uk for cookies HTTP::Cookies::add_cookie_header: Checking
.google.co.uk for cookies HTTP::Cookies::add_cookie_header: Checking
google.co.uk for cookies HTTP::Cookies::add_cookie_header: Checking .co.uk
for cookies HTTP::Cookies::add_cookie_header: Checking co.uk for cookies
HTTP::Cookies::add_cookie_header: Checking .uk for cookies
LWP::UserAgent::send_request: GET
http://news.google.co.uk/search?q=~%22fantastic+four%22&num=100&hl=en&safe=off&start=0&as_qdr=all&filter=0
LWP::UserAgent::_need_proxy: Proxied to http://127.0.0.1:8088
LWP::Protocol::http::request: () LWP::Protocol::collect: read 130 bytes
LWP::UserAgent::request: Simple response: Not Found Use of uninitialized
value in concatenation (.) or string at movien1.pl line 28. 0 news items
found
------------------------------
Date: Thu, 09 Aug 2007 11:44:22 -0000
From: himanshu.garg@gmail.com
Subject: Re: trying to use a proxy
Message-Id: <1186659862.388054.49260@e16g2000pri.googlegroups.com>
On Aug 9, 4:05 pm, "Nospam" <nos...@home.com> wrote:
> I am trying to use a proxy the same proxy works fine in ie6/firefox but for
> some strange reason I get an uninitialised value when using the proxy in ANY
> perl script, the code to use the proxy is:
>
> use strict;
> use warnings;
> use LWP::Debug qw(+);
> use WWW::Mechanize;
>
> my $mech = WWW::Mechanize->new();
>
> my $url =http://news.google.co.uk/search?q=~%22fantastic+four%22&num=100&hl=en...
>
> $mech->proxy('http','http://127.0.0.1:8088');
>
> $mech->get($url);
>
> my @links_to_check = grep { $_->url() !~ /google/i}
> $mech->find_all_links( url_regex => qr/\./i );
>
> foreach my $links_to_check (@links_to_check)
> {
>
> print "$links_to_check \n";
>
> }
Strange,
but the script works for me with my proxy settings.
:(
HG
>
> with LWP::Debug qw(+) I receive
>
> LWP::UserAgent::new: () LWP::UserAgent::proxy: httphttp://127.0.0.1:8088
> LWP::UserAgent::request: () HTTP::Cookies::add_cookie_header: Checking
> news.google.co.uk for cookies HTTP::Cookies::add_cookie_header: Checking
> .google.co.uk for cookies HTTP::Cookies::add_cookie_header: Checking
> google.co.uk for cookies HTTP::Cookies::add_cookie_header: Checking .co.uk
> for cookies HTTP::Cookies::add_cookie_header: Checking co.uk for cookies
> HTTP::Cookies::add_cookie_header: Checking .uk for cookies
> LWP::UserAgent::send_request: GEThttp://news.google.co.uk/search?q=~%22fantastic+four%22&num=100&hl=en...
> LWP::UserAgent::_need_proxy: Proxied tohttp://127.0.0.1:8088
> LWP::Protocol::http::request: () LWP::Protocol::collect: read 130 bytes
> LWP::UserAgent::request: Simple response: Not Found Use of uninitialized
> value in concatenation (.) or string at movien1.pl line 28. 0 news items
> found
------------------------------
Date: 9 Aug 2007 13:08:17 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Windows based perl editor?
Message-Id: <5i0hu1F3l8pmpU1@mid.dfncis.de>
Clenna Lumina <savagebeaste@yahoo.com> wrote in comp.lang.perl.misc:
> l v wrote:
> > A very nice fee editor is Notepad++.
>
> I believe he meant "free" and not "fee", as they do not charge a fee to
> use it :)
That's why it's a fee editor. You edit the fee to zero.
Anno
------------------------------
Date: Thu, 09 Aug 2007 09:33:39 -0700
From: kelticeye <brian.pat.kelly@googlemail.com>
Subject: Re: Windows based perl editor?
Message-Id: <1186677219.418728.102390@57g2000hsv.googlegroups.com>
On 4 Aug, 12:55, Bill H <b...@ts1000.us> wrote:
> I do all my development on windows and then transfer it over to linux
> for actual testing.
On 5 June 2000, 08:00, ta...@metronet.com (Tad McClellan) wrote ...
> There is no old/new version difference re $ARGV.
>
> It has worked find for years. It works fine today.
The only problems I have experienced have been when a Perl Editor,
such as DzSoft Perl Editor has passed strings to this variable in
windowed mode (Vs command line mode) such that:
$ARGV[0] = "name=DzSoft+Perl+Editor"
$ARGV[1] = "email=support%40dzsoft%2Ecom"
Anyone experiencing such a problem should check this first and amend
their script accordingly.
------------------------------
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 734
**************************************