[29482] in Perl-Users-Digest
Perl-Users Digest, Issue: 726 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 7 14:10:18 2007
Date: Tue, 7 Aug 2007 11:09:06 -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: 726
Today's topics:
Re: CGI. postgres local install, DBD::Pg fails <glex_no-spam@qwest-spam-no.invalid>
Re: CGI. postgres local install, DBD::Pg fails brian.darkblueb@gmail.com
Re: Help in file locking and synchronization xhoster@gmail.com
Re: Help in file locking and synchronization <stoupa@practisoft.cz>
Re: module OpenOffice::OODoc fails with Unicode charact <thepoet_nospam@arcor.de>
progress report ideas? <g_m@remove-comcast.net>
Re: progress report ideas? <veatchla@yahoo.com>
Re: progress report ideas? <g_m@remove-comcast.net>
Re: Select / Case in perl <stoupa@practisoft.cz>
Re: simple Perl CGI scripts help <scobloke2@infotop.co.uk>
Re: simple Perl CGI scripts help <yinleew@gmail.com>
Re: simple Perl CGI scripts help <yinleew@gmail.com>
Size of all files in a directory? <bill@ts1000.us>
Re: Size of all files in a directory? <mritty@gmail.com>
Re: Size of all files in a directory? <g_m@remove-comcast.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 07 Aug 2007 10:10:33 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: CGI. postgres local install, DBD::Pg fails
Message-Id: <46b88b69$0$498$815e3792@news.qwest.net>
brian.darkblueb@gmail.com wrote:
> DBD::Pg installed fine on a stock OS X machine. Apache is turned on
> via web sharing.
>
> When we installed DBD::Pg, it magically 'found' that postgres was
> installed in the local (admin) folder instead of /usr/local. All
> DBD::Pg test ran as fine.
>
> BUT when code runs as a CGI, the CGI user 'www' apparently cannot
> access the postgres libraries. A quick attempt at setting a library's
> permissions (libq ?) was no help.
>
> suggestions welcome
How do you know 'www' can't access the libraries? What is the error?
------------------------------
Date: Tue, 07 Aug 2007 09:50:32 -0700
From: brian.darkblueb@gmail.com
Subject: Re: CGI. postgres local install, DBD::Pg fails
Message-Id: <1186505432.525999.265490@i13g2000prf.googlegroups.com>
On Aug 7, 8:10 am, "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
wrote:
> brian.darkbl...@gmail.com wrote:
> > DBD::Pg installed fine on a stock OS X machine. Apache is turned on
> > via web sharing.
>
> > When we installed DBD::Pg, it magically 'found' that postgres was
> > installed in the local (admin) folder instead of /usr/local. All
> > DBD::Pg test ran as fine.
>
> > BUT when code runs as a CGI, the CGI user 'www' apparently cannot
> > access the postgres libraries. A quick attempt at setting a library's
> > permissions (libq ?) was no help.
>
> > suggestions welcome
>
> How do you know 'www' can't access the libraries? What is the error?
I am not at the machine at this moment, but, two knowledgeable people
looked carefully at the logs and said that this was the case. I will
be there on the show floor at LinuxWorld later today. Suggestions
welcome.
------------------------------
Date: 07 Aug 2007 15:47:35 GMT
From: xhoster@gmail.com
Subject: Re: Help in file locking and synchronization
Message-Id: <20070807114736.545$wy@newsreader.com>
ramesh.thangamani@gmail.com wrote:
> I am working on a script which queries LDAP for a group of people and
> stores the details in XML preserving the hierarchy. I have used a perl
> module to create the XML file, the same module can parse it when
> needed. I will also have a perl script to create the XML file daily so
> that the details in the XML file are in sync with the LDAP details.
>
> Now the problem here is there can be synchronization problem when the
> XML is getting generated
> by more than one user running the script at the same time. What could
> be the best approach for this problem. Any suggestions ?
>
> - I have seen file locking stuff but not sure what needs to be done
> to avoid any issues .
It depends on exactly what issues you want to avoid. You could have
your programs, when they decide to build a new file, do so in a local
uniquely named temp file, then rename that to be the standard location.
(I don't know how this will work on Windows, renaming an open file or
renaming a file to overwrite the entry for an open file). This should be
OK in the sense that the file should not be corrupted by multiple writers,
but it won't prevent 20 programs from all slamming your LDAP server at the
same time, each trying to build the new file.
> - Will be better to have some timeout and wait to write the file ?.
It is hard to say what this even means. What operation is being timed
out? How do you detect it?
> - Or should I skip if the file has already been created like that etc.
Again, I don't know what this means. Could you show the proposed code that
would implement it?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Tue, 7 Aug 2007 18:09:50 +0200
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: Help in file locking and synchronization
Message-Id: <f9a5j7$mfe$2@ns.felk.cvut.cz>
ramesh.thangamani@gmail.com wrote:
> I am working on a script which queries LDAP for a group of people and
> stores the details in XML preserving the hierarchy. I have used a perl
> module to create the XML file, the same module can parse it when
> needed. I will also have a perl script to create the XML file daily so
> that the details in the XML file are in sync with the LDAP details.
>
> Now the problem here is there can be synchronization problem when the
> XML is getting generated
> by more than one user running the script at the same time. What could
> be the best approach for this problem. Any suggestions ?
>
> - I have seen file locking stuff but not sure what needs to be done
> to avoid any issues .
> - Will be better to have some timeout and wait to write the file ?.
> - Or should I skip if the file has already been created like that etc.
How big is the XML file? If not too big then you can lock LDAP table (I
suppose MySQL), generate XML on the fly and unlock LDAP table.
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
------------------------------
Date: Tue, 07 Aug 2007 18:48:51 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: module OpenOffice::OODoc fails with Unicode characters
Message-Id: <46b8a273$0$20999$9b4e6d93@newsspool1.arcor-online.net>
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
------------------------------
Date: Tue, 7 Aug 2007 12:30:02 -0400
From: "~greg" <g_m@remove-comcast.net>
Subject: progress report ideas?
Message-Id: <bvSdnWdLhfK5ACXbnZ2dnUVZ_rGrnZ2d@comcast.com>
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;
Or a dot-report:
print '.'; print "\n" if $COUNT++ % $MODULUS == 0;
Where the $MODULUS has to be "fine tuned" to each script,
--something like, say, 1000,
--or whatever it takes to make the report
print out at reasonable time intervals
and in reasonable (readable) amounts.
Perhaps once every 5 seconds or so.
Which just gave me the idea
(just now - which is why I'm posting)
that that is what is really wanted!
--a progress report
that reliably prints out at fixed time intervals,
such as every 5 seconds.
"alarm", or something like it, would have to be used.
Which just reminded me (just now)
that I never much liked (or even understood) signal handling.
~~
So, my question is, has anybody already done anything like that?
- progress reports at fixed time intervals?
Or, more generally, what styles of progress reports do people use?
~greg
------------------------------
Date: Tue, 07 Aug 2007 12:13:40 -0500
From: l v <veatchla@yahoo.com>
Subject: Re: progress report ideas?
Message-Id: <13bha17q8prr89d@news.supernews.com>
~greg 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;
>
> Or a dot-report:
>
> print '.'; print "\n" if $COUNT++ % $MODULUS == 0;
>
>
> Where the $MODULUS has to be "fine tuned" to each script,
> --something like, say, 1000,
> --or whatever it takes to make the report
> print out at reasonable time intervals
> and in reasonable (readable) amounts.
> Perhaps once every 5 seconds or so.
>
> Which just gave me the idea
> (just now - which is why I'm posting)
>
> that that is what is really wanted!
> --a progress report
> that reliably prints out at fixed time intervals,
> such as every 5 seconds.
>
>
> "alarm", or something like it, would have to be used.
>
> Which just reminded me (just now)
> that I never much liked (or even understood) signal handling.
>
> ~~
>
> So, my question is, has anybody already done anything like that?
> - progress reports at fixed time intervals?
>
> Or, more generally, what styles of progress reports do people use?
>
>
> ~greg
yes. In fact, someone make a module just for that purpose.
http://search.cpan.org/~fluffy/Term-ProgressBar-2.09/lib/Term/ProgressBar.pm
--
Len
------------------------------
Date: Tue, 7 Aug 2007 14:03:27 -0400
From: "~greg" <g_m@remove-comcast.net>
Subject: Re: progress report ideas?
Message-Id: <_eqdndL-kqxILyXbnZ2dnUVZ_iydnZ2d@comcast.com>
"l v" <veatchla@yahoo.com> wrote in message news:13bha17q8prr89d@news.supernews.com...
> ~greg 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;
>>
>> Or a dot-report:
>>
>> print '.'; print "\n" if $COUNT++ % $MODULUS == 0;
>>
>>
>> Where the $MODULUS has to be "fine tuned" to each script,
>> --something like, say, 1000,
>> --or whatever it takes to make the report
>> print out at reasonable time intervals
>> and in reasonable (readable) amounts.
>> Perhaps once every 5 seconds or so.
>>
>> Which just gave me the idea
>> (just now - which is why I'm posting)
>>
>> that that is what is really wanted!
>> --a progress report
>> that reliably prints out at fixed time intervals,
>> such as every 5 seconds.
>>
>>
>> "alarm", or something like it, would have to be used.
>>
>> Which just reminded me (just now)
>> that I never much liked (or even understood) signal handling.
>>
>> ~~
>>
>> So, my question is, has anybody already done anything like that?
>> - progress reports at fixed time intervals?
>>
>> Or, more generally, what styles of progress reports do people use?
>>
>>
>> ~greg
>
> yes. In fact, someone make a module just for that purpose.
> http://search.cpan.org/~fluffy/Term-ProgressBar-2.09/lib/Term/ProgressBar.pm
>
No, it doesn't seem to be...
It seems to me that this Term::ProgressBar
is a user-oriented classic progress bar,
a sort of "space oriented" thing
-- ie, guaranteed to print out an indication
of 0 to 100% completion.
But what I want is a "time oriented"
"working" (--not "completion") indicator,
-- guaranteed to print SOMETHING every 5 seconds, say.
(so that it'd have to use an alarm.)
thanks, though.
~greg
------------------------------
Date: Tue, 7 Aug 2007 17:59:18 +0200
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: Select / Case in perl
Message-Id: <f9a5j7$mfe$1@ns.felk.cvut.cz>
Bill H wrote:
> I did a search of the group and found many messages about a select /
> case function in Perl and found references to perldoc -f case and
> perldoc -f switch - but neither of these are found under activestate
> v5.8's perldoc. Can someone point me to some reference on how to
> simulate this structure in perl so I dont have to use endless if's?
>
> Bill H
Use if, elsif, else.
Some languages allow
select case(variable)
case value
command
case value
command
other
command
end case
some other allow
select
case variable=value
command
case other_variable=other_value
command
other
command
end case
In Perl is the best way to use if-elsif-else (by me).
if($variable == 1)
{command}
elsif($other_variable == 2)
{command}
elsif($string_variable eq 'test')
{command}
else
{other_command}
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
------------------------------
Date: Tue, 07 Aug 2007 17:02:32 +0100
From: Ian Wilson <scobloke2@infotop.co.uk>
Subject: Re: simple Perl CGI scripts help
Message-Id: <46b8979a$0$31725$db0fefd9@news.zen.co.uk>
CAT wrote:
>
> I am using this showme.cgi scripts to run the remote scripts check.sh
> on another unix server, the public key already copied over to that
> machine so that the password is not required.
> My problem is, if I comment this line in the remote scripts, the CGI
> will work and will print files to my IE browser
> #APP_ROOT=/opt/APP/server/app
> #export APP_ROOT
>
> If I leave them uncommented, only the command line will work and the
> IE and firefox browser will wait forever even I set up the timeout
> value as big enough.
You are not using the "-l" option of ssh when you run the remote script
so the effective userid for the remote script differs when you invoke it
from a CGI script. This might affect the current working directory for
the remote script as well as its permissions there.
You seem to be discarding STDERR output of your remote script.
I'd change check.sh from
#!/usr/bin/ksh
APP_ROOT=/opt/APP/server/app
export APP_ROOT
TODAY=`date`
echo $TODAY > /tmp/check.txt
echo ""
/opt/APP/server/app /bin/app status \
| grep NOT-RUNNING >> /tmp/check.txt
to
#!/usr/bin/ksh
function checkstuff {
APP_ROOT=/opt/APP/server/app
export APP_ROOT
TODAY=`date`
echo $TODAY > /tmp/check.txt
echo ""
/opt/APP/server/app /bin/app status \
| grep NOT-RUNNING >> /tmp/check.txt
}
checkstuff 2>/tmp/check.err >check.out
Then see what turns up in /tmp/check.err on the remote system
P.S. I'm no Korn shell wizard but I suspect you could use some help from
a shell related newsgroup like comp.unix.shell.
P.P.S. I'd do both sides in Perl or both sides in Ksh. Mixing both
together seems an unecessary complication. YMMV.
------------------------------
Date: Tue, 07 Aug 2007 17:14:08 -0000
From: CAT <yinleew@gmail.com>
Subject: Re: simple Perl CGI scripts help
Message-Id: <1186506848.170873.276940@19g2000hsx.googlegroups.com>
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
> > on another unix server, the public key already copied over to that
> > machine so that the password is not required.
> > My problem is, if I comment this line in the remote scripts, the CGI
> > will work and will print files to my IE browser
> > #APP_ROOT=/opt/APP/server/app
> > #export APP_ROOT
>
> > If I leave them uncommented, only the command line will work and the
> > IE and firefox browser will wait forever even I set up the timeout
> > value as big enough.
>
> You are not using the "-l" option of ssh when you run the remote script
> so the effective userid for the remote script differs when you invoke it
> from a CGI script. This might affect the current working directory for
> the remote script as well as its permissions there.
>
> You seem to be discarding STDERR output of your remote script.
>
> I'd change check.sh from
>
> #!/usr/bin/ksh
> APP_ROOT=/opt/APP/server/app
> export APP_ROOT
> TODAY=`date`
> echo $TODAY > /tmp/check.txt
> echo ""
> /opt/APP/server/app /bin/app status \
> | grep NOT-RUNNING >> /tmp/check.txt
>
> to
>
> #!/usr/bin/ksh
> function checkstuff {
> APP_ROOT=/opt/APP/server/app
> export APP_ROOT
> TODAY=`date`
> echo $TODAY > /tmp/check.txt
> echo ""
> /opt/APP/server/app /bin/app status \
> | grep NOT-RUNNING >> /tmp/check.txt
> }
> checkstuff 2>/tmp/check.err >check.out
>
> Then see what turns up in /tmp/check.err on the remote system
>
> P.S. I'm no Korn shell wizard but I suspect you could use some help from
> a shell related newsgroup like comp.unix.shell.
>
> P.P.S. I'd do both sides in Perl or both sides in Ksh. Mixing both
> together seems an unecessary complication. YMMV.
Thanks all, the above replies are very helpful to improve my perl
programming skill, I already revised my codes according all of your
suggestions.
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).
Best
------------------------------
Date: Tue, 07 Aug 2007 17:34:03 -0000
From: CAT <yinleew@gmail.com>
Subject: Re: simple Perl CGI scripts help
Message-Id: <1186508043.294683.9850@k79g2000hse.googlegroups.com>
On Aug 7, 1:14 pm, CAT <yinl...@gmail.com> 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
> > > on another unix server, the public key already copied over to that
> > > machine so that the password is not required.
> > > My problem is, if I comment this line in the remote scripts, the CGI
> > > will work and will print files to my IE browser
> > > #APP_ROOT=/opt/APP/server/app
> > > #export APP_ROOT
>
> > > If I leave them uncommented, only the command line will work and the
> > > IE and firefox browser will wait forever even I set up the timeout
> > > value as big enough.
>
> > You are not using the "-l" option of ssh when you run the remote script
> > so the effective userid for the remote script differs when you invoke it
> > from a CGI script. This might affect the current working directory for
> > the remote script as well as its permissions there.
>
> > You seem to be discarding STDERR output of your remote script.
>
> > I'd change check.sh from
>
> > #!/usr/bin/ksh
> > APP_ROOT=/opt/APP/server/app
> > export APP_ROOT
> > TODAY=`date`
> > echo $TODAY > /tmp/check.txt
> > echo ""
> > /opt/APP/server/app /bin/app status \
> > | grep NOT-RUNNING >> /tmp/check.txt
>
> > to
>
> > #!/usr/bin/ksh
> > function checkstuff {
> > APP_ROOT=/opt/APP/server/app
> > export APP_ROOT
> > TODAY=`date`
> > echo $TODAY > /tmp/check.txt
> > echo ""
> > /opt/APP/server/app /bin/app status \
> > | grep NOT-RUNNING >> /tmp/check.txt
> > }
> > checkstuff 2>/tmp/check.err >check.out
>
> > Then see what turns up in /tmp/check.err on the remote system
>
> > P.S. I'm no Korn shell wizard but I suspect you could use some help from
> > a shell related newsgroup like comp.unix.shell.
>
> > P.P.S. I'd do both sides in Perl or both sides in Ksh. Mixing both
> > together seems an unecessary complication. YMMV.
>
> Thanks all, the above replies are very helpful to improve my perl
> programming skill, I already revised my codes according all of your
> suggestions.
>
> 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).
>
> Best- Hide quoted text -
>
> - Show quoted text -
Thanks, many thanks to all of your great helpers.
I learned a lot and would like to follow in the future programming.
And, you know what, I migrated all these scripts to another better
performance machine, faster CPU, larger memory, it works now.
Thanks again for your time.
------------------------------
Date: Tue, 07 Aug 2007 09:45:16 -0700
From: Bill H <bill@ts1000.us>
Subject: Size of all files in a directory?
Message-Id: <1186505116.210601.196850@g4g2000hsf.googlegroups.com>
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)?
Bill H
------------------------------
Date: Tue, 07 Aug 2007 10:10:09 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Size of all files in a directory?
Message-Id: <1186506609.227221.17830@q75g2000hsh.googlegroups.com>
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: $!":
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: $!":
my $total_size = 0;
while (my $file = readdir($dh)) {
next if !-f "$dir/$file";
$total_size += -s _;
}
Paul Lalli
------------------------------
Date: Tue, 7 Aug 2007 13:50:54 -0400
From: "~greg" <g_m@remove-comcast.net>
Subject: Re: Size of all files in a directory?
Message-Id: <BuidnWtBLe2JLSXbnZ2dnUVZ_gWdnZ2d@comcast.com>
"Bill H" <bill@ts1000.us> wrote in message news:1186505116.210601.196850@g4g2000hsf.googlegroups.com...
> 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)?
>
> Bill H
>
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: 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 726
**************************************