[12043] in Perl-Users-Digest
Perl-Users Digest, Issue: 5644 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 13 03:07:18 1999
Date: Thu, 13 May 99 00:02:00 -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 Thu, 13 May 1999 Volume: 8 Number: 5644
Today's topics:
Re: Finding Total Directory Size in Perl. (Larry Rosler)
Re: Finding Total Directory Size in Perl. <gary@rdss.com>
Re: Finding Total Directory Size in Perl. <gellyfish@gellyfish.com>
Re: Finding Total Directory Size in Perl. <gary@rdss.com>
Re: Finding Total Directory Size in Perl. <dgris@moiraine.dimensional.com>
Re: Finding Total Directory Size in Perl. (Sam Holden)
Re: Finding Total Directory Size in Perl. (Larry Rosler)
Re: Finding Total Directory Size in Perl. (Sam Holden)
Getting perl to use 64-bit integers <rune.froysa@usit.uio.no>
Re: HASH AND ARRAY <swarren@www.wwwdotorg.org>
Re: Here documents and indention. (Tad McClellan)
Re: Here documents and indention. (Andrew Allen)
Re: How can i create DLL from perl script ? <collin.starkweather@colorado.edu>
How can IE and Netscape support SSI(.shtml file)? <michael.shiah@cdc.com>
Re: How can IE and Netscape support SSI(.shtml file)? (Charles R. Thompson)
Re: How do I get a hash slice as a hash in a Perlish wa (Bart Lateur)
Re: How do I get a hash slice as a hash in a Perlish wa (Larry Rosler)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 12 May 1999 12:05:07 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Finding Total Directory Size in Perl.
Message-Id: <MPG.11a370bfca537939989a41@nntp.hpl.hp.com>
In article <3739C34E.D1F0878F@rdss.com> on Wed, 12 May 1999 14:07:14 -
0400, Gary Ebert <gary@rdss.com> says...
...
> #!/usr/bin/perl
Missing '-w'!
> use strict;
>
> my $size = 0;
> my $dir = $main::ARGV[0];
Superfluous use of 'main::'. No test for nonexistent argument.
> # note that the directory is passed in on the command line
> # instead of hard coded into the script
>
> opendir (FILE, $dir) or die "could not open $_\n";
$_ is undefined at this point. Do you mean $! ?
> while ($_ = readdir FILE) {$size += -s unless (/^\.{1,2}?$/)}
So you are adding up the sizes of things in the current directory that
happen to have the same name as things in $dir. Hmmm...
By the way, what's with the '?' after the quantifier???
> # the unless statement insures that you do not count the . and .. files
>
> print "Total file size for $dir = $size bytes\n";
>
> # END
>
> And I am sure that this could be trimmed down even more.
It could be trimmed *up* by chdir($dir) or by testing "$dir/$_".
You might consider doing some testing next time before posting code.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 12 May 1999 17:06:12 -0400
From: Gary Ebert <gary@rdss.com>
Subject: Re: Finding Total Directory Size in Perl.
Message-Id: <3739ED3D.4C45FC81@rdss.com>
Larry Rosler wrote:
>
> In article <3739C34E.D1F0878F@rdss.com> on Wed, 12 May 1999 14:07:14 -
> 0400, Gary Ebert <gary@rdss.com> says...
> ...
> > #!/usr/bin/perl
>
> Missing '-w'!
granted but the error "use of uninitialized variable at line . . . really
annoys me because we all can see that I have initialized the variable.
>
> > use strict;
> >
> > my $size = 0;
> > my $dir = $main::ARGV[0];
>
> Superfluous use of 'main::'.
True but I prefer to include the package name -- just personal taste.
> No test for nonexistent argument.
No I did not. I do not think that level of detail was necessary for a brief
example to show a different way to do something.
>
> > # note that the directory is passed in on the command line
> > # instead of hard coded into the script
> >
> > opendir (FILE, $dir) or die "could not open $_\n";
>
> $_ is undefined at this point. Do you mean $! ?
oops that should have been $dir not $_.
>
> > while ($_ = readdir FILE) {$size += -s unless (/^\.{1,2}?$/)}
>
> So you are adding up the sizes of things in the current directory that
> happen to have the same name as things in $dir. Hmmm...
What?
I am adding up the size of all of the files in $dir that are not '.' or '..'
>
> By the way, what's with the '?' after the quantifier???
Hmmm you are giving me crap about my script and you do not know the purpose of
the '?' modifier . . . interesting.
For the record the "?" is for minimal matching it is probably not needed --
again just personal preference.
>
> > # the unless statement insures that you do not count the . and .. files
> >
> > print "Total file size for $dir = $size bytes\n";
> >
> > # END
> >
> > And I am sure that this could be trimmed down even more.
>
> It could be trimmed *up* by chdir($dir)
Yes it could I do not understand what you think will be gained by that but
that could be done.
> or by testing "$dir/$_".
Let's see you want me to test $dir/$_.
First I open the directory if the directory does not exist or the user does
not have the correct permissions the script is exited.
Then I read the first file of the directory. All directories (in unix at
least wh/ is obviously what the original poster is using) have at least two
files '.' and '..' so I implicitly know that there are files in this
directory.
If the file is not the . or the .. file I check to see if the file has
non-zero size (and return the file size) the '-s' operator does this.
Then I add the size to the to the size of the previous files. If -s fails
then a zero is returned and added to the total doing nothing.
Exactly what else would you have me test the file for?
>
> You might consider doing some testing next time before posting code.
I did (as you pointed out) forget to test the case where the directory either
did not exist or could not be opened before I posted. However, other than
that the code works fine -- it adds up the size of each file in the passed in
directory. If you tested my script before sending this you would have
realized that.
Apparently either you are way more anal than I am (hence all of this testing
nonsence :-) or you do not understand the script that I submitted. If it is
the former good for you I was just trying to quickly show the original poster
another way of doing what he asked about. If it is the latter then just say
"I do not understand what you are doing here please explain" and I will.
For the record I do believe that testing variables is in general a good thing
to do; however, I was trying to write a short script that demonstrated a
different way to go about adding up the sizes of files in a given directory I
was not submitting a fool proof program -- if I gave that impression I apologize.
Gary
>
> --
> (Just Another Larry) Rosler
> Hewlett-Packard Company
> http://www.hpl.hp.com/personal/Larry_Rosler/
> lr@hpl.hp.com
--
Gary Ebert Operations Administrator
Voice: (301) 428-2115 Comtech Mobile Datacom Corporation
Fax: (301) 428-1004 19540 Amaranth Drive
Pager: (800) 777-4681 PIN: 3981842 Germantown, MD 20875-2126
------------------------------
Date: 12 May 1999 20:35:59 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Finding Total Directory Size in Perl.
Message-Id: <7hconf$l5$1@gellyfish.btinternet.com>
On Wed, 12 May 1999 14:07:14 -0400 Gary Ebert wrote:
> "Charles R. Thompson" wrote:
>> In article <37388967.BB5B4BD5@auger.net>, nick says...
>> > How do you go about finding the total size of a directory (including all
>> > subdirectories), I have tried the "du" command with the backticks, but
>> > it always times out on my server... Is there another way to do it?
>>
>> egads. Yes. :) Using File::Find will make this a snap for you. It's
>> included with the standard distribution, so it should be on your machine.
>> If this script balks at you about it, you'll have to get it and install
>> it from CPAN. File find can work wonders on directory trees. I've only
>> been using it for about a week now and can't figure out how I ever did it
>> before. :)
>>
>> dirfind.pl follows....
> [snip]
>
> You could also do it without using File::Find (not that there is anything
> wrong with that :-) like this:
>
Except of course that will only work on the current directory properly
and doesnt do the subdirectories as the original poster requested ;-{
I think what you were thinking of was something more like :
#!/usr/bin/perl -w
use strict;
my $input_dir = $ARGV[0] || '.' ;
my $size = 0;
my $item;
&dodir ($input_dir);
sub dodir
{
my $thedir = shift ;
opendir DIR, $thedir || die "Couldnt open $thedir - $!\n";
my @entries = map { $thedir . '/' . $_ } grep !/^\.{1,2}$/, readdir(DIR);
closedir (DIR);
foreach $item (@entries)
{
if ( -d $item )
{
dodir ( $item);
}
else
{
$size += -s $item;
}
}
}
print $size,"\n";
Of course on a particularly deep directory structure you are very likely
to run out of stack space and heaven knows what will happen if one of your
directories is a symbolic link but hey .. !
On balance I think I'd probably go for File::Find ;-}
/J\
--
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Wed, 12 May 1999 17:17:19 -0400
From: Gary Ebert <gary@rdss.com>
Subject: Re: Finding Total Directory Size in Perl.
Message-Id: <3739EFD7.C06E33FA@rdss.com>
Jonathan Stowe wrote:
>
> On Wed, 12 May 1999 14:07:14 -0400 Gary Ebert wrote:
> > "Charles R. Thompson" wrote:
> >> In article <37388967.BB5B4BD5@auger.net>, nick says...
> >> > How do you go about finding the total size of a directory (including all
> >> > subdirectories), I have tried the "du" command with the backticks, but
> >> > it always times out on my server... Is there another way to do it?
> >>
> >> egads. Yes. :) Using File::Find will make this a snap for you. It's
> >> included with the standard distribution, so it should be on your machine.
> >> If this script balks at you about it, you'll have to get it and install
> >> it from CPAN. File find can work wonders on directory trees. I've only
> >> been using it for about a week now and can't figure out how I ever did it
> >> before. :)
> >>
> >> dirfind.pl follows....
> > [snip]
> >
> > You could also do it without using File::Find (not that there is anything
> > wrong with that :-) like this:
> >
>
> Except of course that will only work on the current directory properly
> and doesnt do the subdirectories as the original poster requested ;-{
[snip]
I did realize that however I thought (for reasons that are no longer clear to
me) that the original poster requested the size for just files (not the
directories) -- oops. Having said all of that I agree your way is easier
*and* better!
Gary
--
Gary Ebert Operations Administrator
Voice: (301) 428-2115 Comtech Mobile Datacom Corporation
Fax: (301) 428-1004 19540 Amaranth Drive
Pager: (800) 777-4681 PIN: 3981842 Germantown, MD 20875-2126
------------------------------
Date: 12 May 1999 15:29:35 -0600
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: Finding Total Directory Size in Perl.
Message-Id: <m37lqe0yf4.fsf@moiraine.dimensional.com>
Gary Ebert <gary@rdss.com> writes:
> You could also do it without using File::Find (not that there is anything
> wrong with that :-) like this:
You can do it without using File::Find, but you lose the
recursive processing of subdirectories. If you only
want the stuff out of the current directory this is surely
easier-
% perl -le '$_ = shift;
opendir (d,$_) && chdir $_ || die $!;
-f && ($t += -s) for (readdir (d));
$t' ..
7748
%
Notice that chdir() does something stupid if you leave off
the argument, so don't do that.
> # note that the directory is passed in on the command line
> # instead of hard coded into the script
>
> opendir (FILE, $dir) or die "could not open $_\n";
^^^ ^^^^
Why do you call your directory FILE? Doesn't that confuse you? It
would confuse me--especially 300 lines farther along in the program,
after the call to opendir() is no longer visible in my editor.
dgris
--
Daniel Grisinger dgris@moiraine.dimensional.com
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'
------------------------------
Date: 12 May 1999 22:08:46 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Finding Total Directory Size in Perl.
Message-Id: <slrn7jjuvd.ggl.sholden@pgrad.cs.usyd.edu.au>
On Wed, 12 May 1999 17:06:12 -0400, Gary Ebert <gary@rdss.com> wrote:
>
>
>Larry Rosler wrote:
>>
>> In article <3739C34E.D1F0878F@rdss.com> on Wed, 12 May 1999 14:07:14 -
>> 0400, Gary Ebert <gary@rdss.com> says...
>> ...
>> > #!/usr/bin/perl
>>
>> Missing '-w'!
>
>granted but the error "use of uninitialized variable at line . . . really
>annoys me because we all can see that I have initialized the variable.
The idea is to fix the code so that the warnings go away, not to disable
warnings. Do you do this in other areas as well. No need to have a smoke
detector, after all it goes off wean I know there is no fire often when
I cook. No need for a low fuel warning light on my car, since sometimes
it lights up for no reason when I drive up hill...
>>
>> > use strict;
>> >
>> > my $size = 0;
>> > my $dir = $main::ARGV[0];
>>
>> Superfluous use of 'main::'.
>
>True but I prefer to include the package name -- just personal taste.
>
>> No test for nonexistent argument.
>
>No I did not. I do not think that level of detail was necessary for a brief
>example to show a different way to do something.
>
>>
>> > # note that the directory is passed in on the command line
>> > # instead of hard coded into the script
>> >
>> > opendir (FILE, $dir) or die "could not open $_\n";
>>
>> $_ is undefined at this point. Do you mean $! ?
>
>oops that should have been $dir not $_.
>
>>
>> > while ($_ = readdir FILE) {$size += -s unless (/^\.{1,2}?$/)}
>>
>> So you are adding up the sizes of things in the current directory that
>> happen to have the same name as things in $dir. Hmmm...
>
>What?
>
>I am adding up the size of all of the files in $dir that are not '.' or '..'
No your not, your doing what Larry said you were. Why don't you actually
run the code and see...
>
>>
>> By the way, what's with the '?' after the quantifier???
>
>Hmmm you are giving me crap about my script and you do not know the purpose of
>the '?' modifier . . . interesting.
I assume he does in fact...
>
>For the record the "?" is for minimal matching it is probably not needed --
>again just personal preference.
But that's useless in this context. You aren't capturing for one. You are
between ^ and $ for another, so all that could possibly do is slow
the regex match down... And confuse the reader with extra crap that has
no positive effect...
>
>>
>> > # the unless statement insures that you do not count the . and .. files
>> >
>> > print "Total file size for $dir = $size bytes\n";
>> >
>> > # END
>> >
>> > And I am sure that this could be trimmed down even more.
>>
>> It could be trimmed *up* by chdir($dir)
>
>Yes it could I do not understand what you think will be gained by that but
>that could be done.
It would make the code have more resemblence to code that works...
>
>> or by testing "$dir/$_".
>
>Let's see you want me to test $dir/$_.
>
>First I open the directory if the directory does not exist or the user does
>not have the correct permissions the script is exited.
>
>Then I read the first file of the directory. All directories (in unix at
>least wh/ is obviously what the original poster is using) have at least two
>files '.' and '..' so I implicitly know that there are files in this
>directory.
>
>If the file is not the . or the .. file I check to see if the file has
>non-zero size (and return the file size) the '-s' operator does this.
>
>Then I add the size to the to the size of the previous files. If -s fails
>then a zero is returned and added to the total doing nothing.
>
>Exactly what else would you have me test the file for?
Testing $dir/$_ would actually test stat the file in the directory instead
of in the current directory. Which would stop your code from always
returning zero in most cases.
You should really test if it a directory and if so, then you need to add
up the sizes of all the files in that diorectory as well. Your code doesn't
do that, so your code doesn't have any chance of working. Once you modified
it to do that, you might se why intelligent poeple would use File::Find.
>
>>
>> You might consider doing some testing next time before posting code.
>
>I did (as you pointed out) forget to test the case where the directory either
>did not exist or could not be opened before I posted. However, other than
>that the code works fine -- it adds up the size of each file in the passed in
>directory. If you tested my script before sending this you would have
>realized that.
I doesn't. I did actually test your miserable excuse for a script..
(I stored it in test.pl) Here's some of its output...
[sholden@mrmph sholden]$ perl test.pl echo
Total file size for echo = 0 bytes
[sholden@mrmph sholden]$ du -ks echo
34 echo
[sholden@mrmph sholden]$ perl test.pl cd
Total file size for cd = 0 bytes
[sholden@mrmph sholden]$ du -ks cd
192263 cd
[sholden@mrmph sholden]$ cd ..
[sholden@mrmph /home]$ perl ~/test.pl sholden
Total file size for sholden = 0 bytes
[sholden@mrmph /home]$ du -ks sholden
[ the command is still running and I can't be bothered waiting...
I'm guessing the answer should be 1.5Gb or so]
You must have a different definition of works then I do...
0 bytes is the wrong answer in _all_ of those tests, yet the script that
you claim works gives this output.
>
>Apparently either you are way more anal than I am (hence all of this testing
>nonsence :-) or you do not understand the script that I submitted. If it is
>the former good for you I was just trying to quickly show the original poster
>another way of doing what he asked about. If it is the latter then just say
>"I do not understand what you are doing here please explain" and I will.
I seriously doubt you could explain much (I dare say anything) about perl
to Larry that he doesn't know. He on the other hand could probably explain
a large amount to you, but I suspect you may be going to get plonked by those
people that can actually help you in the future if you keep posting like this.
>
>For the record I do believe that testing variables is in general a good thing
>to do; however, I was trying to write a short script that demonstrated a
>different way to go about adding up the sizes of files in a given directory I
>was not submitting a fool proof program -- if I gave that impression I apologize.
A program that actually had a chance of working would have been OK. You have two
major errors (one not mentioned by Larry) and seem to fail to grasp that in
this case you are wrong and someone else is right...
--
Sam
In case you hadn't noticed, Perl is not big on originality.
--Larry Wall
------------------------------
Date: Wed, 12 May 1999 14:49:48 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Finding Total Directory Size in Perl.
Message-Id: <MPG.11a397547b9b099c989a4e@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <3739ED3D.4C45FC81@rdss.com> on Wed, 12 May 1999 17:06:12 -
0400, Gary Ebert <gary@rdss.com> says...
> Larry Rosler wrote:
> > In article <3739C34E.D1F0878F@rdss.com> on Wed, 12 May 1999 14:07:14 -
> > 0400, Gary Ebert <gary@rdss.com> says...
> > ...
> > > #!/usr/bin/perl
> >
> > Missing '-w'!
>
> granted but the error "use of uninitialized variable at line . . . really
> annoys me because we all can see that I have initialized the variable.
If you have initialized a variable, then why would you get a warning?
...
> > > opendir (FILE, $dir) or die "could not open $_\n";
> >
> > $_ is undefined at this point. Do you mean $! ?
>
> oops that should have been $dir not $_.
The '-w' flag would have warned you about that! The diagnostic should
include *both* $dir and $!, which tells you the reason for failure to
open the directory.
> > > while ($_ = readdir FILE) {$size += -s unless (/^\.{1,2}?$/)}
> >
> > So you are adding up the sizes of things in the current directory that
> > happen to have the same name as things in $dir. Hmmm...
>
> What?
>
> I am adding up the size of all of the files in $dir that are not '.' or '..'
NO!!!! Names returned by readdir() are simple names, which means they
refer to files relative to the current directory. When you then do an
operation such as '-s' (which means '-s $_'), the file referred to is $_
in the current directory, not the file $_ in $dir. That is why you must
either chdir $dir or use "$dir/$_".
> > By the way, what's with the '?' after the quantifier???
>
> Hmmm you are giving me crap about my script and you do not know the purpose of
> the '?' modifier . . . interesting.
>
> For the record the "?" is for minimal matching it is probably not needed --
> again just personal preference.
'Match as few as possible of one or two dots between the start and end
of the string.' The ? makes no sense before an end anchor. Your
personal preference leaves something to be desired in terms of
rationality.
<SNIP> long presentation revealing a lack of understanding of relative
vs absolute file names.
> > You might consider doing some testing next time before posting code.
>
> I did (as you pointed out) forget to test the case where the directory either
> did not exist or could not be opened before I posted. However, other than
> that the code works fine -- it adds up the size of each file in the passed in
> directory. If you tested my script before sending this you would have
> realized that.
If I had tested it and it worked, it would be because I was testing it
in the current directory, which would then have to be the same directory
as $dir. By coincidence!
The '-w' flag would have told you each time you tried to add in the size
of a nonexistent file. But you don't believe in using it.
> Apparently either you are way more anal than I am (hence all of this testing
> nonsence :-) or you do not understand the script that I submitted. If it is
> the former good for you I was just trying to quickly show the original poster
> another way of doing what he asked about. If it is the latter then just say
> "I do not understand what you are doing here please explain" and I will.
I do understand. You needn't explain. It is wrong, with or without
your explanation.
> For the record I do believe that testing variables is in general a good thing
> to do; however, I was trying to write a short script that demonstrated a
> different way to go about adding up the sizes of files in a given directory I
> was not submitting a fool proof program -- if I gave that impression I apologize.
The tenor of the newsgroup seems to be that unless otherwise noted,
snippets posted should serve as good examples to relatively
inexperienced programmers. You were doing that when you used 'use
strict;' Why stop there?
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 12 May 1999 22:10:25 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Finding Total Directory Size in Perl.
Message-Id: <slrn7jjv2h.ggl.sholden@pgrad.cs.usyd.edu.au>
On Wed, 12 May 1999 17:17:19 -0400, Gary Ebert <gary@rdss.com> wrote:
>
>>
>> Except of course that will only work on the current directory properly
>> and doesnt do the subdirectories as the original poster requested ;-{
>[snip]
>I did realize that however I thought (for reasons that are no longer clear to
>me) that the original poster requested the size for just files (not the
>directories) -- oops. Having said all of that I agree your way is easier
>*and* better!
You might also notice his way also includes the $dir/$_ test that you
claimed wasn't needed in your reply to Larry.
--
Sam
It has been discovered that C++ provides a remarkable facility for
concealing the trival details of a program--such as where its bugs are.
--David Keppel
------------------------------
Date: 12 May 1999 21:56:45 +0200
From: Rune Froysa <rune.froysa@usit.uio.no>
Subject: Getting perl to use 64-bit integers
Message-Id: <svl90auysci.fsf@myrddraal.uio.no>
I have a bunch of perl-scripts that only works on our 64-bit alpha
machines due to large integers. From the source-code it seems like
integers in perl is a long, which on most systems is 32-bit. Looking
at "perl.h", I see some reference from 1996 that perl does not yet
support the use of long long on most systems.
Is there any trick that can be used to get perl to run propperly with
64-bit integers under linux/solaris, using long longs or something
similar? (Math::BigInt would require a lot of recoding and is not a
prefered option.)
--
Rune Frxysa, unix-drift, USIT, UiO Private e-mail: runefr@ifi.uio.no
UNIX evangelist Work e-mail: rune.froysa@usit.uio.no
<URL:http://www.ifi.uio.no/%7Erunefr/> Pb 1059 Blindern, 0316 Oslo
"Where do your encryption keys want to go today?" - Peter Gutmann
------------------------------
Date: Wed, 12 May 1999 20:36:18 GMT
From: "Stephen Warren" <swarren@www.wwwdotorg.org>
Subject: Re: HASH AND ARRAY
Message-Id: <6Dl_2.602$6x6.156@news.rdc1.sfba.home.com>
OK, so how about the best way to over-ride a hash with defaults?
I've got a piece of code that does:
-w, use strict...
foreach my $elem ( @cpuInstructions )
{
TYPE:
if ( exists $$elem{ "type" } )
{
my $instructionType = $$elem{ "type" } ;
last TYPE if ! exists $cpuInstructionTypes{ $instructionType } ;
my $instructionTypeInfo = $cpuInstructionTypes{ $instructionType } ;
foreach my $k ( keys %$instructionTypeInfo )
{
if ( ! exists $$elem{ $k } )
{
$$elem{ $k } = $$instructionTypeInfo{ $k } ;
}
}
}
}
I'm thinking there has to be a much nicer way to perform the inner
foreach?
I can't just do:
@$elem{ @keys } = @$instructionTypeInfo{ @keys } ;
since that'd over-ride the data that's already there...
Perhaps I could
%temp = %$instructionTypeInfo ;
@temp{ @keys } = @$elem{ @keys } ;
# and then replace the value in @cpuInstructions.... Hmm...
But I'm not sure about that... Perhaps it's efficient enough already - the
run-time's certainly short enough, but maybe the typing/reading isn't:-)
--
Stephen Warren, Snr Systems Engineer, Technology House, San Francisco
mailto:swarren@techhouse.com http://www.techhouse.com/
mailto:swarren@wwwdotorg.org http://www.wwwdotorg.org/
MIME, S/MIME and HTML mail are acceptable
------------------------------
Date: Wed, 12 May 1999 11:27:38 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Here documents and indention.
Message-Id: <al6ch7.dog.ln@magna.metronet.com>
Charles R. Thompson (design@raincloud-studios.com) wrote:
: The only *real* reason I point it out is for the sake of readable code.
: Let's say you had a nested structure like so...
: foreach(@thing){
: if(!$_){
: while($stuff){
: &dothing;
: print <<END_OF_HTML;
: <blah>
: de lots of stuff and lines
: </blah>
: END_OF_HTML
: }
: }
: }
: From the point of legibility, this is way off base and while it *works*
: fine it does nothing but 'hiccup' the reading of the code, especially if
: you have a run of complex structures.
You can always make some leading space be part of the terminator:
foreach(@thing){
&dothing;
print <<" END_OF_HTML";
<blah>
de lots of stuff and lines
</blah>
END_OF_HTML
: Who really cares if the end result HTML source itslef is totally whacked
: out? Anyone looking in there anyway is trying to figure out what you did
: to achieve a certain layout. I say make um work for it. :)
Good. Since the above "whacks out" the output (it is all indented)
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 12 May 1999 20:22:48 GMT
From: ada@fc.hp.com (Andrew Allen)
Subject: Re: Here documents and indention.
Message-Id: <7hcnuo$7ok$2@fcnews.fc.hp.com>
Charles R. Thompson (design@raincloud-studios.com) wrote:
: [This followup was posted to comp.lang.perl.misc and a copy was sent to
: the cited author.]
: In article <373c9cdd.16909759@news.skynet.be>, Bart Lateur says...
: > >If Perl doesn't really care that much about whitespace, why do here
: > >document terminators have to be flush left in scripts?
: > Seriously, I too don't really understand why Perl couldn't be patched to
: > disregard any whitespace (and only whitespace, both before and after) on
: > those lines. Any time sacrifice would only be once, at compile-time. It
: > probably would even be minimal. That doesn't seem so bad.
: The only *real* reason I point it out is for the sake of readable code.
: Let's say you had a nested structure like so...
: foreach(@thing){
: if(!$_){
: while($stuff){
: &dothing;
: print END_OF_HTML;
: <blah>
: de lots of stuff and lines
: </blah>
: END_OF_HTML
: }
: }
: }
I peeked in perldoc overload, and unfortunately, in the "Overloading
Constants" section, it says:
Note that the initial string form does not contain string delimiters
(thus apparently no way of distinguishing HERE docs from other
strings). But we could write a function indent_here:
# takes a string, and removes the from each line the same number of
# leading spaces that occur on the first line. If the first line is
# only spaces, it is removed. A leading newline is stripped before
# processing.
sub unindent_here {
my $string=shift;
$string=~s/\A\n//;
my $ind=$1 if $string=~/\A( *)/;
$string=~s/^$ind//gm;
$string=~s/\A\n//;
$string;
}
now all you have to do is:
print indent_here(<<HEREDOC);
this is an indented here-doc
HEREDOC
but unfortunately, the closing still needs to be in column 1, unless you're willing to do this:
print indent_here(<<" HEREDOC");
this is an indented here-doc
HEREDOC
and I'd probably be just as likely to do, say:
print indent_here(qq
{
some indented text
});
(which is indent_here strips leading newlines :)
Andrew
------------------------------
Date: Wed, 12 May 1999 13:33:54 -0600
From: Collin Starkweather <collin.starkweather@colorado.edu>
Subject: Re: How can i create DLL from perl script ?
Message-Id: <3739D7A2.AD42C2E0@colorado.edu>
This is a multi-part message in MIME format.
--------------29F6624F4987B999DD8D4ACB
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Purchase the ActiveState (http://www.activestate.com) Perl Developer's
Kit (PDK) and read the docs on PerlCtrl.
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Collin Starkweather (303) 492-4784
University of Colorado collin.starkweather@colorado.edu
Department of Economics http://ucsu.colorado.edu/~olsonco
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
feketeroland11@my-dejanews.com wrote:
>
> Help me! Help me!
> Can i create windows 95/NT .dll from a perl script?
> If it's possible, how ???
> Thanks for the time,
> Roland
>
> --== Sent via Deja.com http://www.deja.com/ ==--
> ---Share what you know. Learn what you don't.---
--------------29F6624F4987B999DD8D4ACB
Content-Type: text/x-vcard; charset=us-ascii;
name="collin.starkweather.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Collin Starkweather
Content-Disposition: attachment;
filename="collin.starkweather.vcf"
begin:vcard
n:Starkweather;Collin
tel;work:(303) 492-4784
x-mozilla-html:FALSE
url:http://ucsu.colorado.edu/~olsonco
org:University of Colorado;Department of Economics
version:2.1
email;internet:collin.starkweather@colorado.edu
title:Research Assistant
adr;quoted-printable:;;University of Colorado=0D=0ACampus Box 0256;Boulder;Colorado;80309-0256;USA
fn:Collin Starkweather
end:vcard
--------------29F6624F4987B999DD8D4ACB--
------------------------------
Date: Wed, 12 May 1999 17:19:28 +0800
From: "michael.shiah" <michael.shiah@cdc.com>
Subject: How can IE and Netscape support SSI(.shtml file)?
Message-Id: <3739479F.431D0755@cdc.com>
I prepared a .shtml file with the following statement:
<!--#echo var="REMOTE_HOST"-->
But I got a save file window. That means Netscape don't know .shtml
file.
How can Netscape support SSI function(.shtml file)?
------------------------------
Date: Wed, 12 May 1999 20:17:13 GMT
From: design@raincloud-studios.com (Charles R. Thompson)
Subject: Re: How can IE and Netscape support SSI(.shtml file)?
Message-Id: <MPG.11a3ad1d4a4b9ab59896ab@news>
[This followup was posted to comp.lang.perl.misc and a copy was sent to
the cited author.]
In article <3739479F.431D0755@cdc.com>, michael.shiah says...
> I prepared a .shtml file with the following statement:
> <!--#echo var="REMOTE_HOST"-->
> But I got a save file window. That means Netscape don't know .shtml
> file.
> How can Netscape support SSI function(.shtml file)?
Wrong forum. comp.infosystems.www.authoring.cgi
This has absolutly NADA to do with Perl.
--
Charles R. Thompson
RainCloud Studios
"That? That's no script. That's your attempt at a rather complex README
file."
------------------------------
Date: Wed, 12 May 1999 20:00:30 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: How do I get a hash slice as a hash in a Perlish way?
Message-Id: <373edbfb.5495630@news.skynet.be>
Dwayne Retsky wrote:
>> my @vowels = qw/a e i o u/;
>>
>> @nerfherder{@vowels} = @gundark{@vowels};
>
>That is what I asked for, but it's not what I wanted. Sorry!
>
>Is it possible to do it without naming the other hash?
Yes, if you don't mind an array-like intermediate step.
sub hashslice {
my ($hash,@keys) = @_;
return map { $_ => $hash->{$_} } @keys;
}
%nerfherder = hashslice(\%gundark, qw/a e i o u/);
A nicer syntax is probably possible when using function prototypes.
As Larry R. would say: pretty slow. As I would say: fast enough if you
don't need to do this too often.
p.s. This will create hash entries that weren't in the original hash, if
those were requested. I don't know if you mind.
Bart.
------------------------------
Date: Wed, 12 May 1999 13:50:22 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: How do I get a hash slice as a hash in a Perlish way?
Message-Id: <MPG.11a389671f0475ef989a4c@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <373edbfb.5495630@news.skynet.be> on Wed, 12 May 1999
20:00:30 GMT, Bart Lateur <bart.lateur@skynet.be> says...
> Dwayne Retsky wrote:
> >> my @vowels = qw/a e i o u/;
> >>
> >> @nerfherder{@vowels} = @gundark{@vowels};
> >
> >That is what I asked for, but it's not what I wanted. Sorry!
> >
> >Is it possible to do it without naming the other hash?
>
> Yes, if you don't mind an array-like intermediate step.
>
> sub hashslice {
> my ($hash,@keys) = @_;
> return map { $_ => $hash->{$_} } @keys;
> }
>
> %nerfherder = hashslice(\%gundark, qw/a e i o u/);
>
> A nicer syntax is probably possible when using function prototypes.
Why the function call at all?
my %nerfherder = map { $_ => $gundark{$_} } qw/a e i o u/;
By the way, thanks to all who clued me in on the variable names. The
Force rules!
> As Larry R. would say: pretty slow. As I would say: fast enough if you
> don't need to do this too often.
For sure. But hash slices are so cute, they need all the exposure they
can get.
> p.s. This will create hash entries that weren't in the original hash, if
> those were requested. I don't know if you mind.
>From an earlier post of his:
> ... It will make 'u' into a key of %nerfherder
> all the time, though, even when it isn't a key of %gundark, doesn't
> it? That's OK for my purposes, though, since all the vowels should be
> there. But it's not quite right.
So:
my %nerfherder = map { exists $gundark{$_} ?
($_ => $gundark{$_}) : () } qw/a e i o u/;
It takes more code with a hash slice (but still cute :-):
my %nerfherder;
my @vowels = grep exists $gundark{$_} => qw/a e i o u/;
@nerfherder{@vowels} = @gundark{@vowels};
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 5644
**************************************