[7031] in Perl-Users-Digest
Perl-Users Digest, Issue: 656 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 24 23:07:19 1997
Date: Tue, 24 Jun 97 20:00:27 -0700
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, 24 Jun 1997 Volume: 8 Number: 656
Today's topics:
Re: "system" output into array (A. Deckers)
Re: "system" output into array <rootbeer@teleport.com>
Re: ***How to get info from the HTML files in other ser <jpoon@iastate.edu>
Re: Checking a string for "@' and "." <esupu@warwick.ac.uk>
Re: Efficiency of 'my' declaration w/in loop? (Michael Fuhr)
Re: File Permissions - 'nobody' can't open file (Nathan V. Patwardhan)
Free sex site password a12@comports.com
ftplib.pl on Windows <d93qc@qcunix1.acc.qc.edu>
Re: leading zeroes (Trey Valenta)
Re: Multiple Accepts/Sockets <merlyn@stonehenge.com>
Oracle Stored procedure calls from Perl <mshannon@lds.com>
Re: Perl and htpasswd (Daniel G. Drumm)
Re: perl core on Solaris 5.5.1 <rootbeer@teleport.com>
Re: Perl Network/Socket programming <rootbeer@teleport.com>
Perl under NWS 3.01... <serginho@alpha.hydra.com.br>
Perl5 & win 95 <arthur_dent@rocketmail.com>
Re: Perl5 & win 95 (Shelle)
Problems w/Perl Search script on NT/IIS <scotth@nyd2.com>
Q: MacPerl, CGI <mxu@eecs.ukans.edu>
Q: MacPerl, MacHTTP and CGI <mxu@eecs.ukans.edu>
Re: recursive <merlyn@stonehenge.com>
Re: recursive (Daniel G. Drumm)
Re: Request for Bids - Web Site Mirroring Script luvisi@andru.sonoma.edu
Re: Running out of memory in recursive subroutine <merlyn@stonehenge.com>
Re: socket programming (Daniel G. Drumm)
Re: stdin, stdout, exec <cgweav@eskimo.com>
Re: Strings to Associative Arrays <merlyn@stonehenge.com>
Re: System command (Andrew M. Langmead)
Re: to use flock, sysopen or open? <merlyn@stonehenge.com>
Re: Uploading in Perl 5 <sibsib@hotmail.com>
Re: Use Perl in C <sfairey@adc.metrica.co.uk>
What is "exec format error"? <changhsu@csua.berkeley.edu>
XS: MakeMakefile & complex C makefile <jheck@merck.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 24 Jun 1997 18:41:32 GMT
From: deckers@man.ac.uk (A. Deckers)
Subject: Re: "system" output into array
Message-Id: <slrn5r056j.bco.deckers@nessie.mcc.ac.uk>
In <33AFFD42.5F53@fmr.com>,
Jim Condit <jim.condit@fmr.com> wrote:
>I would like to take the output generated by the system() function and
>put it into an array, something like this:
>
>system("command which prints to the screen") > @screencapture ;
>
>This does not work, of course. I'm running 5.003 on NT 3.51.
I think you misunderstand the purpose of system(). If you want to
capture the output of a system call, you'll have to use backticks:
@ary = `command which prints to the screen`
I believe this works on NT for recent versions of Perl.
For example (this is obviously on a Unix box, but the principle is the
same):
#!/usr/bin/perl -w
my @ary = `ls`;
foreach (@ary) {
print;
}
__END__
Sorry to say this, but the answer's in the Perl FAQ.
HTH,
Alain
--
Perl information: <URL:http://www.perl.com/perl/>
Perl FAQ: <URL:http://www.perl.com/perl/faq/>
Perl archive: <URL:http://www.perl.com/CPAN/>
>>>>>>>> comp.lang.perl.misc is NOT a CGI group <<<<<<<<<<
------------------------------
Date: Tue, 24 Jun 1997 15:05:43 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Jim Condit <jim.condit@fmr.com>
Subject: Re: "system" output into array
Message-Id: <Pine.GSO.3.96.970624150457.24884B-100000@kelly.teleport.com>
On Tue, 24 Jun 1997, Jim Condit wrote:
> I would like to take the output generated by the system() function and
> put it into an array,
You'll find a way to do something like this documented in perlop(), in the
section about qx``. Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Mon, 23 Jun 1997 10:26:02 -0500
From: Johnny Poon <jpoon@iastate.edu>
To: Eric Levenez <levenez@club-internet.fr>
Subject: Re: ***How to get info from the HTML files in other server??***
Message-Id: <33AE958A.67931858@iastate.edu>
I guess I didn't ask my question clear enough. What I actually wanted
to find out is that, is there any ways to write a HTML file when loaded
from any browser, it will "automatically" grep the info out of some
other HTML's source and grep the information from there and use them.
This sounds to be that it might be able to do it in either CGI, Java, or
Javascript. Just wonder you Java experts out there would know a way.
Thanks.
Eric Levenez wrote:
> Johnny <jpoon@iastate.edu> wrote:
> > Is there any ways to get information from a HTML files located
> in
> > other server (different from the one you are on)?? I want to be
> able to
> > grep info from HTML files in other server and use it in my own HTML
>
> > file. If you have any clue, please help me out.
>
> Your browser can display the HTML source code. If you want to load
> yourself
> the HTML page, look at HTTP specification.
>
> --
>
> --------------------------------------------------------------------
> Iric Livinez "Felix qui potuit rerum cognoscere causas"
> mailto:levenez@club-internet.fr Publius Vergilius Maro,
> (NeXTMail, MIME) Georgica, II-489
> --------------------------------------------------------------------
------------------------------
Date: Mon, 23 Jun 1997 15:17:57 +0100
From: mike mah <esupu@warwick.ac.uk>
To: deanh@iinet.net.au
Subject: Re: Checking a string for "@' and "."
Message-Id: <Pine.SOL.3.95.970623151100.997A-100000@lily>
On Mon, 23 Jun 1997, Dean Hollister wrote:
>
> Can anyone point me to the required code to check whether or not a
> string has BOTH the "@" and "." characters in it?
let's say you have a string $string.
if ($string=~ /@/ && $string=~/\./)
{ #do something }
> ST:VOY Kess: "I wish people would stop talking to me as if
> I'm still a child! I'm three years old now!"
>
>
Let's strike for exellent.
Yours sincerely,
mike mah
------------------------------
Date: 24 Jun 1997 19:52:13 -0600
From: mfuhr@dimensional.com (Michael Fuhr)
Subject: Re: Efficiency of 'my' declaration w/in loop?
Message-Id: <5optkd$fjn@flatland.dimensional.com>
Don Thomson <thomson@zinger.adp.wisc.edu> writes:
[snip]
> Is the first of the above a more expensive operation efficiency-wise?
> I like the idea stylistically, but would want to avoid it if it's more
> expensive at run-time to create a lexical variable each time through
> the loop.
Somebody who knows the Perl code may give you technical reasons
for using one method over another, but an easy way to check things
out for yourself is to benchmark your actual code. There's a module
called Benchmark for doing exactly that -- do a "man Benchmark" for
details.
Hope this helps!
--
Michael Fuhr
http://www.dimensional.com/~mfuhr/
------------------------------
Date: 23 Jun 1997 13:54:31 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: File Permissions - 'nobody' can't open file
Message-Id: <5olv6n$bbq@fridge-nf0.shore.net>
? the platypus {aka David Formosa} (dformosa@st.nepean.uws.edu.au) wrote:
: This newsgroup is getting flooded with question that would be better dealt
: with in the cgi newsgroup.
Yep. Thank goodness moderation is on the horizon.
--
Nathan V. Patwardhan
nvp@shore.net
------------------------------
Date: Mon, 23 Jun 1997 10:24:52 -0600
From: a12@comports.com
Subject: Free sex site password
Message-Id: <867076955.18018@dejanews.com>
Hi, I paid $24 dollars for this password, and then for some strange reason
my check bounced, so I ended up paying almost $50 bucks. For that much
money I think I should be able to share it with people in my newsgroups.
username is - tom25
passcode is - dodge
the site is at;
http://38.217.84.11/~fbx/e.html
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: 23 Jun 1997 17:22:32 GMT
From: "Ephi Sinowitz" <d93qc@qcunix1.acc.qc.edu>
Subject: ftplib.pl on Windows
Message-Id: <01bc7ffa$2e2f88f0$c6e932aa@hnebenha5046m>
Can I use ftplib.pl on windows NT?
------------------------------
Date: 23 Jun 1997 03:30:51 GMT
From: trey@zipcon.net (Trey Valenta)
Subject: Re: leading zeroes
Message-Id: <867036819.402109@ran.zipcon.net>
>> $four =~ s/0+(\d+)/$1/o;
$four = "0004";
%nums = ( 1 => 'one',
2 => 'two',
3 => 'three',
4 => 'four',
5 => 'five',
6 => 'six',
7 => 'seven',
8 => 'eight',
9 => 'nine',
0 => 'zero' );
for ($i; $i < length($four); $i++ ) {
push(@digits, substr($four,$i,1));
}
for ( $i = 0; $i <= $#digits; $i++ ) {
if ( !$leading && $nums{$digits[$i]} eq "zero" ) { next }
else { $leading = 1 }
$after[++$x] = $nums{$digits[$i]};
}
undef($four);
for ( $i = 0; $i <= $#after; $i++ ) {
foreach $key ( keys(%nums)) {
if ( $after[$i] eq $nums{$key} ) {
$four .= $key;
}
}
}
--
Trey Valenta trey@zipcon.net
------------------------------
Date: 23 Jun 1997 08:00:24 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: kessler@dfacades.com
Subject: Re: Multiple Accepts/Sockets
Message-Id: <8coh8xbbzr.fsf@gadget.cscaper.com>
>>>>> "kessler" == kessler <kessler@dfacades.com> writes:
kessler> I have a server/client setup based on Camel p350. I fork
kessler> lots of children; they all inherit the parent's socket.
kessler> However, if they all do an "accept" on that socket, they seem
kessler> to collide (esp under Solaris), and hang.
kessler> In the Camel example, the server doesn't fork until an accept
kessler> returns; but this way, your children are spawned to handle
kessler> one connection and then expected to exit. I'd like them to
kessler> stay around and handle more connections, so that a surge in
kessler> access is quickly dealt with.
kessler> Apache can do it in C... can I do it in perl?
Yes! I've successfully written a Perl program that creates a
pre-forking Web server very much like Apache. The trick is to make
sure that only *one* child calls accept() at a time. I did it by
flocking the listening socket exclusively... works great! The code
looks like this in the child:
while (1) {
flock($master, 2); # when I get this, I'm the only listener
$slave = $master->accept or die "accept: $!"; # this blocks until connect
flock($master, 8); # let someone else get the next one, I'm busy
## now process $slave...
}
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 435 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Tue, 24 Jun 1997 16:56:45 -0400
From: Michael Shannon <mshannon@lds.com>
Subject: Oracle Stored procedure calls from Perl
Message-Id: <33B0348D.5D51@lds.com>
This seems to be a common question, that has some vague responses. I
need to be able to call an Oracle stored procedure from perl, that
actually returns some results. For example,
I have an Oracle stored procedure that accepts an ID as a parameter, and
based on that parameter, returns a social security number and a date of
birth. Real straight forward stuff. Can I get a straight forward way to
do this using the DBD/DBI Oracle stuff.
I have read in previous threads that their is an example(test_psql) of
this in Test.pl, but our installations of DBD-Oracle-0.45 & DBI-0.84
have the test.pl but make no mention of test_psql.
Thanks...Mike
mshannon@lds.com
------------------------------
Date: 24 Jun 1997 22:25:36 GMT
From: dgd@nebula.is.rpslmc.edu (Daniel G. Drumm)
Subject: Re: Perl and htpasswd
Message-Id: <5ophh0$dl5@nebula.is.rpslmc.edu>
Josh Keller (dragon_clan@usa.net) wrote:
: I would like to make a perl script that adds a username and password to
: my .htpasswd file by running htpasswd off the Linux server. Is this
: possible? If so how do I do this?
Add the HTTPD::UserAdmin package from CPAN. Then read the man page.
#!/perl
use HTTPD::UserAdmin
@Text = (DBType => 'Text',
DB => '.htpasswd',
Server => 'ncsa');
$user = new HTTPD::UserAdmin @Text;
if($user->add('dougm', 'secret')) {
print "You have the power!\n";
}
--
--
Daniel G. Drumm - ddrumm@rush.edu
Rush Presbyterian St. Luke's Medical Center - Chicago, IL
Network Division - Information Services
------------------------------
Date: Tue, 24 Jun 1997 15:09:36 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: tjohnson@ameritrade.com
Subject: Re: perl core on Solaris 5.5.1
Message-Id: <Pine.GSO.3.96.970624150638.24884C-100000@kelly.teleport.com>
On Tue, 24 Jun 1997 tjohnson@ameritrade.com wrote:
> This code ran fine under an older version of Solaris. On version 5.5.1
> it now cores sometimes, sometime not.
The code is irrelevant; Perl's not supposed to accidentally dump core.
Your copy of perl was probably miscompiled, or it's got a bug or maybe
it's triggered a bug in your system (which is not likely from your code
sample, I think). If you can reproduce the problem with 5.004, run perlbug
to file a bug report. If you can't reproduce it, well, then, your problem
is solved! :-)
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 24 Jun 1997 15:39:18 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: kingzem@nationwide.com
Subject: Re: Perl Network/Socket programming
Message-Id: <Pine.GSO.3.96.970624153806.24884G-100000@kelly.teleport.com>
On Tue, 24 Jun 1997 kingzem@nationwide.com wrote:
> The problem I've narrowed this down to is that neither the client nor
> the server sees the string sent across the socket until the socket is
> closed. I've tried flushing the filehandle to the socket after each
> print command, but it does not seem to help.
Could you show us your code? Maybe we'll see something in the posted code
that's not apparent when we merely imagine it. :-)
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 24 Jun 1997 19:45:12 GMT
From: "Sergio Stateri Jr" <serginho@alpha.hydra.com.br>
Subject: Perl under NWS 3.01...
Message-Id: <01bc80d7$83545f80$6875e7c8@Term104>
Completing the last article of mine, Does anyone here know where I can get
any documentation about Perl 5 for Netware Web Server 3.xx ? (Because the
documentation that's in the product box isn't sufficient)
--
--------------------------------------------
Sergio Stateri Jr
Sco Paulo (SP) - Brazil
e-mail: serginho@usa.net
--------------------------------------------
------------------------------
Date: 23 Jun 1997 15:16:07 GMT
From: "Philip Smith" <arthur_dent@rocketmail.com>
Subject: Perl5 & win 95
Message-Id: <01bc7fe9$2161db20$960010ac@cbtsys1.dublin2>
sorry for asking a stupid question, but maybe someone can help?
I need to know how to change the registry settings so my server can
recognize perl. Does anyone have any suggestions?
My server is Personal Web server for Windows 95.
Thanks,
Arthur_dent@rocketmail.com
------------------------------
Date: Mon, 23 Jun 1997 16:18:02 GMT
From: shelle@interaccess.com (Shelle)
Subject: Re: Perl5 & win 95
Message-Id: <5om7jq$1e8_002@interaccess.interaccess.com>
In article <01bc7fe9$2161db20$960010ac@cbtsys1.dublin2>, "Philip Smith" <arthur_dent@rocketmail.com> wrote:
>sorry for asking a stupid question, but maybe someone can help?
>
>I need to know how to change the registry settings so my server can
>recognize perl. Does anyone have any suggestions?
>
>My server is Personal Web server for Windows 95.
That wasn't that easy to figure out from their documentation...I had the same
problem. Here's an example of what my registry looks like:
*** begin sample***
[HKEY_LOCAL_MACHINE\SOFTWARE\ActiveWare\Perl5]
"BIN"="C:\\Perl\\bin"
"PRIVLIB"="C:/perl/lib/"
"HTML-DOCS"="C:\\Perl\\docs"
"WIN95SHELL"="c:\\perl\\bin\\cmd32.exe"
*** end sample***
This of course assumes that you have installed your Perl program in the
directory C:\Perl (Change that if your installed somewhere else of course.).
Something to beware of Part I: The double slashes ("\\") do indeed seem to be
necessary.
Something to beware of Part II: You will note that the PRIVLIB key uses the
slash as UNIX does ("/") rather than "\" or "\\" as used in the other keys;
This solved many problems for me - It may or may not work that way on your
machine.
Something to beware of Part III: To add additional libraries paths to your
"PRIVLIB" key, use a semi-colon to separate the paths. For example:
"PRIVLIB"="C:/perl/lib/;C:/win32app/perl-extra-libs/prod/override;C:
/win32app/perl5/lib;C:/win32app/perl-extra-libs/prod/adhoc;C:
/win32app/perl-extra-libs/prod/standard;"
Luck!
Michelle ----,-'-(@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Michelle Feigen ----,-'-(@ shelle@interaccess.com
MEAN PEOPLE SUCK!
http://homepage.interaccess.com/~shelle/
http://homepage.interaccess.com/~shelle/grafx/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
------------------------------
Date: Tue, 24 Jun 1997 16:05:03 -0400
From: Scott Holmes <scotth@nyd2.com>
Subject: Problems w/Perl Search script on NT/IIS
Message-Id: <33B0286F.1DCC@nyd2.com>
The portion of the script that I've included below is supposed to
exclude the designated directories/files from the search. The rest of
the script works fine but I keep getting hits in directories that I'm
trying to exclude. I would greatly appreciate any help. The original
script came from http://www.xav.com/scripts
(http://www.xav.com/scripts/search/nt/searchnt.zip):
$DMZ .= "e:\\CompanyDir\\wwwroot\\medical\\cri\\_vti_cnf ";
$DMZ .= "e:\\CompanyDir\\wwwroot\\medical\\scripts\\_vti_cnf ";
if ($ENV{'SERVER_SOFTWARE'} =~ /IIS/)
{
$slash = '\\';
if ((!(-e $basedir)) && ($ENV{'PATH_TRANSLATED'} =~ /(.*)\\(.*)/))
{$basedir = $1;}
}
else
{
$slash = '/';
if (!(-e $basedir))
{$basedir = $ENV{'DOCUMENT_ROOT'};}
}
$cgi_url = $ENV{'SCRIPT_NAME'};
# Done customizing...
if ($ENV{'QUERY_STRING'} =~ /^terms=(.*)/i)
{
$terms = $1;
$terms =~ tr/+/ /;
$terms =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$saved_terms = $terms;
}
else
{
print "Location: $searchpage\n\n";
exit;
}
@directories = ($basedir);
$maxvar = 1;
for ($i=0;$i<$maxvar;$i++)
{
$directory = @directories[$i];
opendir(DIR,$directory);
@entries = readdir(DIR);
closedir(DIR);
foreach $entry (@entries)
{
next if (($entry eq ".") || ($entry eq ".."));
$full = $directory . $slash . $entry;
next if ($DMZ =~ /$full /i);
if (-d $full)
{
push(@directories,$full);
$maxvar++;
}
elsif ((-T $full) && ($full =~ /(.*)\.(.*)/))
{
$extension = "." . $2 . ".";
push(@FILES,$full) if ($extensions =~ /$extension/);
}
}
}
--
Scott Holmes
NYD2/New York Digital Design
ScottH@nyd2.com
(908)534-6780
------------------------------
Date: Tue, 24 Jun 1997 20:50:55 -0500
From: Mousheng Xu <mxu@eecs.ukans.edu>
Subject: Q: MacPerl, CGI
Message-Id: <Pine.ULT.3.96.970624205032.21670C-100000@mercury>
I am trying to run perl cgi scripts on a powermac.
I installed machttp and MacPerl and I have some unix perl scripts.
But how I don't know how to convert the unix perl to mac perl.
Suppose I have a unix perl script as the following:
#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
print "<html><head><title>A test</title></head>";
print "<body>";
print "This is a test.";
print "</body></html>";
But in a Mac, there is no such a thing as "/usr/local/bin/perl". I
tried "#!MacPerl", while my perl script and MacPerl are both in the
machttp directory, but it doesn't work.
I have spent a lot of time on it, but can't find a way out.
Those who know the answer please help me!
Thanks a lot in advance.
Mousheng Xu
------------------------------
Date: Tue, 24 Jun 1997 20:48:21 -0500
From: Mousheng Xu <mxu@eecs.ukans.edu>
Subject: Q: MacPerl, MacHTTP and CGI
Message-Id: <Pine.ULT.3.96.970624204735.21670B-100000@mercury>
I am trying to run perl cgi scripts on a powermac.
I installed machttp and MacPerl and I have some unix perl scripts.
But how I don't know how to convert the unix perl to mac perl.
Suppose I have a unix perl script as the following:
#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
print "<html><head><title>A test</title></head>";
print "<body>";
print "This is a test.";
print "</body></html>";
But in a Mac, there is no such a thing as "/usr/local/bin/perl". I
tried "#!MacPerl", while my perl script and MacPerl are both in the
machttp directory, but it doesn't work.
I have spent a lot of time on it, but can't find a way out.
Those who know the answer please help me!
Thanks a lot in advance.
Mousheng Xu
------------------------------
Date: 24 Jun 1997 17:32:24 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: recursive
Message-Id: <8cd8pbbjzb.fsf@gadget.cscaper.com>
>>>>> "Zenin" == Zenin <zenin@best.com> writes:
Zenin> bret bailey <bretb@engr.sgi.com> wrote:
>> Hello,
>> I'm writing a simple script to calculate the size of my website. How do
>> I make it work recursively?
>> Any response would be appreciated.
Zenin> Take a look at the File::Recurse module. It comes in the File::Tools
Zenin> package from CPAN. Something like:
Zenin> #!/usr/local/bin/perl -w
Zenin> use File::Recurse;
Zenin> recurse { $Total += (stat($_))[7] } shift();
Zenin> print "$Total\n";
Zenin> $ MyWebTotal /path/to/my/website
Or, to save yourself some download time from the CPAN, just use File::Find
that comes *with* Perl:
#!/usr/local/bin/perl -w
use File::Find;
my $sum = 0;
find sub { $sum += -s if -f }, shift;
print "Total is ", int(($sum + 1023)/1024), "Kbytes\n";
Of course, if you want something du-like, you can horse around with
(stat)[13] instead, but then you have to know the blocksize of the
filesystem.
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 435 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: 24 Jun 1997 22:22:07 GMT
From: dgd@nebula.is.rpslmc.edu (Daniel G. Drumm)
Subject: Re: recursive
Message-Id: <5ophaf$dl5@nebula.is.rpslmc.edu>
Randal Schwartz (merlyn@stonehenge.com) wrote:
: Or, to save yourself some download time from the CPAN, just use File::Find
: that comes *with* Perl:
: #!/usr/local/bin/perl -w
: use File::Find;
: my $sum = 0;
: find sub { $sum += -s if -f }, shift;
: print "Total is $total\n";
Last line should substitute $sum for $total, for those playing at home.
May wish to divide by 1024 for info in Kbytes.
: --
: Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
--
--
Daniel G. Drumm - ddrumm@rush.edu
Rush Presbyterian St. Luke's Medical Center - Chicago, IL
Network Division - Information Services
------------------------------
Date: 24 Jun 1997 13:50:04 -0700
From: luvisi@andru.sonoma.edu
To: overby@crl.com
Subject: Re: Request for Bids - Web Site Mirroring Script
Message-Id: <m267v3n2tf.fsf@andru.sonoma.edu>
overby@crl.com writes:
> The Internet Guide to Hostelling (www.hostels.com), is currently
> seeking assistance to develop a script that will be used to
> mirror web sites at other locations to our server.
have you checked out Wget from the fsf?
ftp://prep.ai.mit.edu/pub/gnu/wget*
not that I have anything against scripting (I make my living doing
it), but you might be better off just using a tool which already does
what you need...
andru
------------------------------
Date: 23 Jun 1997 08:09:41 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: Steve Hart <s.hart@unikix.com>
Subject: Re: Running out of memory in recursive subroutine
Message-Id: <8ck9jlbbka.fsf@gadget.cscaper.com>
>>>>> "Steve" == Steve Hart <s.hart@unikix.com> writes:
Steve> Here is part of my program showing the recursive subroutine:
Steve> undef $/;
Steve> foreach $arg (@ARGV) {
Steve> open (TEXTFILE, "<$arg");
Steve> $expanded_file = &expand (<TEXTFILE>);
Steve> }
Steve> sub expand {
Steve> my ($text) = @_;
Steve> foreach $line (split (/\n/, $text)) {
Steve> if ($line =~ /^EXPAND:(.+?)\s/) {
Steve> $expfile = $1;
Steve> open (EXPFILE, "<$expfile");
Steve> $text .= &expand (<EXPFILE>); # Recursive call
Steve> close EXPFILE;
Steve> }
Steve> }
Steve> return ($text);
Steve> }
For one, I wouldn't use recursion here... check this out:
use IO::File;
foreach $arg (@ARGV) {
$expanded_file = "";
@handles = new IO::File "$arg" or (warn "skipping $arg: $!"), next;
while (@handles) {
$_ = $handles[0]->getline;
if (/^EXPAND:(.+?)\s/) {
$expfile = $1;
$newhandle = new IO::File "$expfile" or
(warn "skipping $expfile: $!"), next;
unshift @handles, $newhandle;
} else {
$expanded_file .= $_;
}
}
}
The key here is to maintain a FIFO stack of filehandles, and just read
from the one on the top of the stack. When you get a request to
expand, push the new one on the stack top.
Works like a charm. Been there, done that, got the T-shirt.
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 435 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: 24 Jun 1997 22:27:32 GMT
From: dgd@nebula.is.rpslmc.edu (Daniel G. Drumm)
Subject: Re: socket programming
Message-Id: <5ophkk$dl5@nebula.is.rpslmc.edu>
David Dougal (ddougal@gte.net) wrote:
: I have a perl script with the following line:
: require "sockets.pl";
: I get the following error
: Can't locate sockets.pl in @INC at ./socket-demo1 line 3.
: The script is rather old
: has sockets.pl changed? I can't locate this module. What do I need for socket
: programming with Perl 5.003?
IO::Socket from CPAN.
--
--
Daniel G. Drumm - ddrumm@rush.edu
Rush Presbyterian St. Luke's Medical Center - Chicago, IL
Network Division - Information Services
------------------------------
Date: Sun, 22 Jun 1997 18:42:47 -0700
From: Clayton Weaver <cgweav@eskimo.com>
Subject: Re: stdin, stdout, exec
Message-Id: <Pine.SUN.3.96.970622183056.2449B-100000@eskimo.com>
Assume that we have opened a pipe instead of using STDIN and STDOUT
and FIFO_IN is fd 3 and FIFO_OUT is fd 4. Does this work?
fcntl(FIFO_IN, F_SETFD, 1); # set clone_on_exec yes
fcntl(FIFO_OUT, F_SETFD, 1); # ditto
$| = 1;
print FIFO_OUT "$somedata\n$somemoredata";
exec("progname", 3, 4);
and in the execed program (which might be C, but in perl terms):
open(FIFO_IN, ">&$ARGV[0]); # opens file descriptor 3
open(FIFO_OUT, "<&$ARGV[1]); # opens file descriptor 4
Filter the data, and then do the same thing with fcntl and exec the perl
script again with the filtered data readable on file descriptor 3. The
perl script just needs an "if ($ARGV ...)" check to see whether this is
the first time through the exec loop and whatever other conditions apply
to the specific task that the program is intended to accomplish.
Does perl's fcntl support Linux's FD_CLOEXEC flag (does the same thing as
F_SETFD 1)?
perl (5.003) said
$^F = 5;
was an error, so I assume that this has a value but isn't mutable?
Regards, Clayton Weaver cgweav@eskimo.com (Seattle)
------------------------------
Date: 23 Jun 1997 07:51:45 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: "Paul Denman" <pdenman@ims.ltd.uk>
Subject: Re: Strings to Associative Arrays
Message-Id: <8cvi35bce6.fsf@gadget.cscaper.com>
>>>>> "Paul" == Paul Denman <pdenman@ims.ltd.uk> writes:
Paul> I am receiving a string which I would like to assign to an associative
Paul> array as quickly
Paul> as possible (IE. without assigning individually)
We got tired of the seven syllable term. They're just "hash" now.
Cool. Saves me about 5 minutes total in a day-long class when I'm
teaching, and those 5 minutes can be used to answer 3 more email
messages!
Paul> I have read that you can define an associative array as the value of a
Paul> scalar eg;
Paul> $test = "One,1,Two,2,Three,3";
Paul> %testa = $test;
Try this:
%testa = split /,/, $test;
You can go from a list to a hash and back, but not a string to a hash,
which will be treated as a single element.
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 435 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Mon, 23 Jun 1997 13:11:03 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: System command
Message-Id: <EC8CMF.90o@world.std.com>
Petri Backstrom <petri.backstrom@icl.fi> writes:
>George M. Pieri wrote:
>>
>> Is it possible to output the contents of the
>> system command to an array "INSTEAD OF" a
>> file...
>Yes. Search your Perl documentation files for
>the word 'backtick' and you should have your
>answer within seconds.
I know that flaming novices is becoming an increasingly popular sport
here in comp.lang.perl.misc, but this isn't being at all useful. The
trick is to tell the novice a word or string to search for
_that_the_novice_already_knows_. This shows them that they could found
the answer by themself.
Suggesting that he looks up system in the perlfunc man page and notice
this passage:
This is NOT what you want to use to capture the
output from a command, for that you should use
merely backticks or qx//, as described in the
section on `STRING` in the perlop manpage.
That is being helpful. George knew he wanted something like the
system() function. He should know that it is in the man page. He
should be able to read the entry in the perlfunc man page. He should
have found the reference to `STRING`.
I wonder why he didn't.
--
Andrew Langmead
------------------------------
Date: 23 Jun 1997 07:54:16 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: s11976@net2.hkbu.edu.hk (Pui Ming WONG)
Subject: Re: to use flock, sysopen or open?
Message-Id: <8cradtbc9z.fsf@gadget.cscaper.com>
>>>>> "Pui" == Pui Ming WONG <s11976@net2.hkbu.edu.hk> writes:
Pui> I've been reading most other people's codes (incl those listed
Pui> in the perl FAQ) to learn different methods of locking a file
Pui> for updating.
Pui> The FAQ example opens the file using the sysopen statement.
Pui> Yet i notice someone simply use open (FH,......);
Pui> statment before they call the flock(FH,2)
Pui> Now are there any difference in using them in the flock context?
Pui> Do both ways work ? But which is better?
flock() works on a filehandle (or an IO::File, technically). Both
sysopen() and open() create IO::Files, but sysopen gives you a
lower-level interface, where you can set various mode bits (just like
with IO::File's interface).
So, both ways work, but the sysopen() is more flexible and therefore
slightly more work to type. :-)
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 435 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Tue, 24 Jun 1997 16:27:40 -0400
From: Scott Blanksteen <sibsib@hotmail.com>
Subject: Re: Uploading in Perl 5
Message-Id: <33B02DBC.E9C33E41@hotmail.com>
Matt wrote:
> Okay, I need to know how you can take a file that a user selects from
> his/her hard drive, and upload it to your internet site. This script
> will be run on the server. All I need is the way to access the users
Check out the CGI module at CPAN.
CPAN is at <http://www.perl.com/CPAN/>
Scott
--
Scott I. Blanksteen
sib (at) worldnet (dot) att (dot) net
------------------------------
Date: Tue, 24 Jun 1997 11:56:14 +0100
From: Simon Fairey <sfairey@adc.metrica.co.uk>
Subject: Re: Use Perl in C
Message-Id: <33AFA7CE.3F54@adc.metrica.co.uk>
Rick Brannan wrote:
>
> I know that the Perl Journal (http://www.tpj.com) had an article on this a
> few months back, but don't remember exact dates.
>
> Hope it helps.
Last one I got has it in...Volume 1 Issue 4 (Winter 1996)
Simon 'eagerly awaiting Issue 5'
------------------------------
Date: Tue, 24 Jun 1997 18:40:50 -0700
From: changhsu <changhsu@csua.berkeley.edu>
Subject: What is "exec format error"?
Message-Id: <33B07722.B216C21D@csua.berkeley.edu>
Hi, I'm having a CGI problem on my NT 4 running IIS 3. My CGI script
calls a Perl script which calls an .exe program. The intermediate CGI
script runs fine from the command line, but it fails to execute the .exe
program when its called from the web via CGI. I get the following error:
exec format error
Is this a Perl, IIS, or CGI error? I'm using CGI.pm also. I think all my
files and directories have the necessary permissions. And this setup
works fine on my Unix server. Does anyone know what's wrong?
Thanks in advance.
chang
changhsu@csua.berkeley.edu
------------------------------
Date: Mon, 23 Jun 1997 10:30:27 -0400
From: "James J. Heck" <jheck@merck.com>
Subject: XS: MakeMakefile & complex C makefile
Message-Id: <33AE8882.41C6@merck.com>
I have a very complicated C makefile for a library that I would
like to turn into a XSub library. However, I am uncertain how
to go about combining both the Makefile that is generated by
MakeMakefile.PL and the already existing one.
I looked at Example 4 in the perlxstut, however, I am
still uncertain.
Please mail any repsonses to jheck@acm.org.
TIA,
James
--------------------
James J. Heck
jheck@acm.org
http://www.bucknell.edu/~jheck
The contents of this message express only the sender's opinion.
This message does not necessarily reflect the policy or views of
my employer, Merck & Co., Inc. All responsibility for the statements
made in this Usenet posting resides solely and completely with the
sender.
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 656
*************************************