[30343] in Perl-Users-Digest
Perl-Users Digest, Issue: 1586 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 28 21:09:38 2008
Date: Wed, 28 May 2008 18:09:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 28 May 2008 Volume: 11 Number: 1586
Today's topics:
BYTE simulation. Was Re: Out of memory! Yet ... sln@netherlands.co
Re: FAQ 2.11 Perl Books (David Combs)
Re: FAQ 3.23 Can I write useful Perl programs on the co (David Combs)
Re: FAQ 4.17 How do I find yesterday's date? (David Combs)
Re: Out of memory! Yet ... sln@netherlands.co
Re: Turning a dir output into a webpage ?? <mdcarlile@googlemail.com>
Re: Turning a dir output into a webpage ?? <mdcarlile@googlemail.com>
Re: Variable remaining undef in one place but not anoth <rkb@i.frys.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 28 May 2008 16:11:13 -0700
From: sln@netherlands.co
Subject: BYTE simulation. Was Re: Out of memory! Yet ...
Message-Id: <p7pr34leceq1nehujd95vul9hdki0t116f@4ax.com>
I have some benchmark and memory usage numbers that you can guage performance with.
With the fixes, I have also included a small test bed that you can cut & paste.
I was going to make a perl module out of this but I have not seen any great demand for it.
In that case, I recommend to you that you use the inline versions of asignment/reads as
in the listing below.
I'm not sure why you would use Perl for this, however, since you are, the really good news
is the packing is scalable, and the performance isn't bad when using inline, and it will get
you what you wan't.
I encourage others to test this on a variety of machines and report time/memory usage.
GENERAL BENCHMARK DATA
----------------------
Data Set #1:
3 dimensional numeric array (10, 1600, 1200) of BYTE's, roughly 10 x 2MB of 8-bit data, 19,200,000 elements
Memory consumption from asignment:
Perl - 410 MB
Byte simulation (pack) - 112 MB
Asignment time:
Perl - 15 seconds
Byte simulation (inline) - 31 seconds
Byte simulation (fast function) - 45 seconds
Byte simulation (normal function) - 60 seconds
Read time:
Perl - 8 seconds
Byte simulation (inline) - 15 seconds
Byte simulation (fast function) - 20 seconds
Byte simulation (normal function) - 26 seconds
Data Set #2:
3 dimensional numeric array (100, 1600, 1200) of BYTE's, roughly 100 x 2MB of 8-bit data, 190,200,000 elements
Memory consumption from asignment:
Perl - N/A, > 3 GB
Byte simulation (pack) - 1.12 GB
Asignment time:
Perl - N/A
Byte simulation (inline) - 4 min's 20 seconds
Byte simulation (fast function) - 6 min's
Byte simulation (normal function) - 9 min's
Read time:
Perl - N/A
Byte simulation (inline) - 2 min's 30 seconds
Byte simulation (fast function) - not tested
Byte simulation (normal function) - not tested
CONCLUSIONS
-----------
Even though a numeric array of size (100, 1600, 1200) could not be conventionally asigned
with the limited memory I have (2 GB), it is apparent from the benchmarks, since it scales
linear, that this array would consume over 4 GB of memory.
In the BYTE simulation, it only consumes 1 GB's of memory.
And in a similar fashion, it would consume 2 GB's if using USHORT, or 16-bit asignment.
The speed would be of some concern. Inline usage roughly doubles the asignment and read speed.
Fast-function usage is even slower by %50, normal-function usage by %100.
But who cares. If everything is needed in ram, nothing will be faster.
I guess it depends if the overhead of repeatedly reading, and memory asignment from disk,
is faster than the bit-parsing. I would say its not.
BENCHMARK SAMPLE (cut/paste/run)
--------------------------------
use strict;
use warnings;
my ($val, $valout, $retval, $bitpos, $ref_element) = (0, 0, 0, 0, undef);
my @AAA = (); # test array
my ($ni, $nx, $ny) = (10, 1600, 1200); # size of test array (roughly 10 x 2MB)
my $test_inline = 1; # 1 = test using inline
my $test_reading = 0; # 0 = don't test reading
# Note - lower the test array size if reading & printing values ... (2,2,512) is good
my $print_reads = 0; # 0 = don't print out read results
for my $i(1..$ni)
{
print "$i - ",$i*($nx*$ny)/(1000000)," MB of raw data\n";
for my $x(1..$nx)
{
for my $y(1..$ny)
{
$val = $y;
if ($test_inline) # inline BYTE asignment (fastest)
{
$bitpos = ($y & 3) * 8;
$ref_element = \$AAA[$i][$x][$y >> 2];
$$ref_element = 0 if (!defined $$ref_element);
$$ref_element = ($$ref_element & ~(0xFF << $bitpos)) | (($val & 0xFF) << $bitpos);
}
else { # function call, BYTE asignment (slowest)
set_BYTeFast(\@{$AAA[$i][$x]}, $y, $val);
}
}
}
}
if ($test_reading)
{
print "\nStarting read test ... note time\n";
for my $i(1..$ni)
{
print "\n\n\ni=$i\n======================================\n" if ($print_reads);
for my $x(1..$nx)
{
print "\n\nx=$x\n++++++++++++++++++++++++++++++++++\n" if ($print_reads);
for my $y(1..$ny)
{
if ($test_inline) # inline BYTE read (fastest)
{
$bitpos = ($y & 3) * 8;
$ref_element = \$AAA[$i][$x][$y >> 2];
$$ref_element = 0 if (!defined $$ref_element);
$valout = ($$ref_element & (0xFF << $bitpos)) >> $bitpos;
print "$valout, " if ($print_reads);
}
else {
$valout = get_BYTeFast(\@{$AAA[$i][$x]}, $y);
print "$valout, " if ($print_reads);
}
}
}
}
}
#######################################################
# Note - Inline usage & Globals for "Fast" calls
#my ($val, $valout, $retval, $bitpos, $ref_element) = (0, 0, 0, 0, undef);
#
#
# Inline (fastest)
# =====================================
#
# Inline BYTE Writing: $AAA[$i][$x][$y]
#{
# # $val is what to asign
# $bitpos = ($y & 3) * 8;
# $ref_element = \$AAA[$i][$x][$y >> 2];
# $$ref_element = 0 if (!defined $$ref_element);
# $$ref_element = ($$ref_element & ~(0xFF << $bitpos)) | (($val & 0xFF) << $bitpos);
#}
#
# Inline BYTE Reading: $AAA[$i][$x][$y]
#{
# # $valout is the the real value in the element
# $bitpos = ($y & 3) * 8;
# $ref_element = \$AAA[$i][$x][$y >> 2];
# $$ref_element = 0 if (!defined $$ref_element);
# $valout = ($$ref_element & (0xFF << $bitpos)) >> $bitpos;
#}
# Functions (slowest)
# ===============================================
# writing: set_xxx(\@{$AAA[$i][$x]}, $y, $val);
# reading: $valout = get_xxx(\@{$AAA[$i][$x]}, $y);
## Not thread safe -----------
##
sub set_BYTeFast
{
$bitpos = ($_[1] & 3) * 8;
$ref_element = \${$_[0]}[$_[1] >> 2];
$$ref_element = 0 if (!defined $$ref_element);
$$ref_element = ($$ref_element & ~(0xFF << $bitpos)) | (($_[2] & 0xFF) << $bitpos);
}
sub get_BYTeFast
{
$bitpos = ($_[1] & 3) * 8;
$ref_element = \${$_[0]}[$_[1] >> 2];
$$ref_element = 0 if (!defined $$ref_element);
return (($$ref_element & (0xFF << $bitpos)) >> $bitpos);
}
sub get_CHArFast
{
$bitpos = ($_[1] & 3) * 8;
$ref_element = \${$_[0]}[$_[1] >> 2];
$$ref_element = 0 if (!defined $$ref_element);
$retval = ($$ref_element & (0xFF << $bitpos)) >> $bitpos;
return ($retval & 0x80 ? $retval-0x100 : $retval);
}
sub set_USHORtFast
{
my $bitpos = ($_[1] & 1) * 16;
$ref_element = \${$_[0]}[$_[1] >> 1];
$$ref_element = 0 if (!defined $$ref_element);
$$ref_element = ($$ref_element & ~(0xFFFF << $bitpos)) | (($_[2] & 0xFFFF) << $bitpos);
}
sub get_USHORtFast
{
my $bitpos = ($_[1] & 1) * 16;
$ref_element = \${$_[0]}[$_[1] >> 1];
$$ref_element = 0 if (!defined $$ref_element);
return (($$ref_element & (0xFFFF << $bitpos)) >> $bitpos);
}
sub get_SHORtFast
{
my $bitpos = ($_[1] & 1) * 16;
$ref_element = \${$_[0]}[$_[1] >> 1];
$$ref_element = 0 if (!defined $$ref_element);
$retval = ($$ref_element & (0xFFFF << $bitpos)) >> $bitpos;
return ($retval & 0x8000 ? $retval-0x10000 : $retval);
}
## Thread safe --------
##
sub set_BYTe
{
my ($RefArray, $Index, $Value) = @_;
my $bitpos = ($Index & 3) * 8;
my $element = $Index >> 2;
my $ref_element = \${$RefArray}[$element];
$$ref_element = 0 if (!defined $$ref_element);
$$ref_element = ($$ref_element & ~(0xFF << $bitpos)) | (($Value & 0xFF) << $bitpos);
}
sub get_BYTe
{
my ($RefArray, $Index) = @_;
my $bitpos = ($Index & 3) * 8;
my $element = $Index >> 2;
my $ref_element = \${$RefArray}[$element];
$$ref_element = 0 if (!defined $$ref_element);
return (($$ref_element & (0xFF << $bitpos)) >> $bitpos);
}
sub get_CHAr
{
my ($RefArray, $Index) = @_;
my $bitpos = ($Index & 3) * 8;
my $element = $Index >> 2;
my $ref_element = \${$RefArray}[$element];
$$ref_element = 0 if (!defined $$ref_element);
my $retval = ($$ref_element & (0xFF << $bitpos)) >> $bitpos;
return ($retval & 0x80 ? $retval-0x100 : $retval);
}
sub set_USHORt
{
my ($RefArray, $Index, $Value) = @_;
my $bitpos = ($Index & 1) * 16;
my $element = $Index >> 1;
my $ref_element = \${$RefArray}[$element];
$$ref_element = 0 if (!defined $$ref_element);
$$ref_element = ($$ref_element & ~(0xFFFF << $bitpos)) | (($Value & 0xFFFF) << $bitpos);
}
sub get_USHORt
{
my ($RefArray, $Index, $Value) = @_;
my $bitpos = ($Index & 1) * 16;
my $element = $Index >> 1;
my $ref_element = \${$RefArray}[$element];
$$ref_element = 0 if (!defined $$ref_element);
return (($$ref_element & (0xFFFF << $bitpos)) >> $bitpos);
}
sub get_SHORt
{
my ($RefArray, $Index) = @_;
my $bitpos = ($Index & 1) * 16;
my $element = $Index >> 1;
my $ref_element = \${$RefArray}[$element];
$$ref_element = 0 if (!defined $$ref_element);
my $retval = ($$ref_element & (0xFFFF << $bitpos)) >> $bitpos;
return ($retval & 0x8000 ? $retval-0x10000 : $retval);
}
__END__
-sln
robic(at)adelphia.net
------------------------------
Date: Wed, 28 May 2008 23:43:43 +0000 (UTC)
From: dkcombs@panix.com (David Combs)
Subject: Re: FAQ 2.11 Perl Books
Message-Id: <g1kqnf$pai$1@reader2.panix.com>
In article <240520081140581251%brian.d.foy@gmail.com>,
brian d foy <brian.d.foy@gmail.com> wrote:
>In article <g18i62$fdm$1@reader2.panix.com>, David Combs
><dkcombs@panix.com> wrote:
>
>> In article <200520081213523682%brian.d.foy@gmail.com>,
>> brian d foy <brian.d.foy@gmail.com> wrote:
>> >In article <g0qr8h$cte$1@reader2.panix.com>, David Combs
>> ><dkcombs@panix.com> wrote:
>> >
>> >
>> >> ----
>> >>
>> >> Well, I've tried. Breaking into a clique is really hard.
>> >>
>> >
>> >If you want to accuse me of something, just come out and say it. That
>> >you had to invoke some "clique" twice in your *first* message about the
>> >subject.
>>
>> Hey, brian, I wasn't talking about you -- I was simply setting
>
>> All I ask is that a few trustworthy people have a look at
>> this thing I'm talking about.
>>
>> And it'd be best it it were Perl AUTHORS who did the
>> looking, so that if any gave it a thumbs-up, you'd
>> know, I think, that the opinion wasn't B.S.
>
>Again, what are you acusing me of? I'm the guy that maintains the FAQ,
>and I'm a Perl Author. I'm not trustworthy? My opinion is bullshit?
>
>I read all the Perl books that come out. Publishers already send me the
>books as they are published (and often before they are published).
>
>
>I still have nio idea what you are proposing, but it sure looks like
>you're trying to say that I have an ethical problem maintaining the
>FAQ. If you have a problem or a patch, follow the instructions at the
>end of each FAQ posting.
Brian --
Yes, indeed, without much difficulty at all, you can read what
I say to be an attack on you. Although that is absolutely NOT
the intent.
I've always had a hard time getting words down on paper, at least
one that reflect what I really think.
What I seem to you to be saying is actually opposite or orthogonal
or something to what I'm *intending* to impart.
Instead of continuing this thread in a one one-way msg per 24-hours,
how about a quick phone conversation? Here's my phone number:
914-632-1883, I work at home, so am usually here.
(Tonight, since I'm now listening to the hacker/ex-phon-phreak "off the hook"
WBAI-radio-program ("2600") until
8pm est, not til then -- or you give me your phone no and a time
to call.)
Also realize that I access the internet via a "shell account" that I
get into via kermit, modem, and phone line (at least no viruses, etc),
and thus no windows-like pop-up the instant email arrives -- I generally
look at email (likewise for newsgroup posts) only once every day or two -----
Let me close with this: there is NO WAY WHATSOEVER that it pays me
to get on the wrong side of *anyone* in this group! Like most people
here, I very much rely on the info you guys put out in your warnings,
solutions, and suggestions!
And no, I am not accusing you of anything.
Nor until your last post did I know that *you* were the faq maintainer --
I thought it was some kind of group effort, no one person having the
responsibility for doing whatever additions or fixes got made.
Anyway, give me a ring!
David
------------------------------
Date: Thu, 29 May 2008 00:32:46 +0000 (UTC)
From: dkcombs@panix.com (David Combs)
Subject: Re: FAQ 3.23 Can I write useful Perl programs on the command line?
Message-Id: <g1ktje$iod$1@reader2.panix.com>
>In article
><43a75974-ec4c-41d3-8912-4a8b873190e3@u12g2000prd.googlegroups.com>,
>Ben Bullock <benkasminbullock@gmail.com> wrote:
>
>> On May 4, 1:59 pm, Sherman Pendley <spamt...@dot-app.org> wrote:
>> > Ben Bullock <benkasminbull...@gmail.com> writes:
>> > > On Sat, 03 May 2008 12:03:02 -0700, PerlFAQ Server wrote:
>> >
>> > >> 3.23: Can I write useful Perl programs on the command line?
>> >
>> > > Has anybody ever, even once, asked this question, or even something
>> > > similar to it? I just can't imagine anybody asking that kind of question.
>> >
usefulness? Maybe as part of aliases?
David
------------------------------
Date: Thu, 29 May 2008 00:54:59 +0000 (UTC)
From: dkcombs@panix.com (David Combs)
Subject: Re: FAQ 4.17 How do I find yesterday's date?
Message-Id: <g1kut3$34b$1@reader2.panix.com>
In article <481e54c4$0$33218$815e3792@news.qwest.net>,
Andrew DeFaria <Andrew@DeFaria.com> wrote:
>-=-=-=-=-=-
>
>brian d foy wrote:
>> In article <fvknfp026so@news4.newsguy.com>, szr
>> <szrRE@szromanMO.comVE> wrote:
>>
>>>> Most people try to use the time rather than the calendar to figure
>>>> out dates, but that assumes that days are twenty-four hours each.
>>>> For most people, there are two days a year when they aren't: the
>>>> switch to and from summer time throws this off. Let the modules do
>>>> the work.
>>> So according to the last part, that makes time - 86400 unreliable?
>>>
>>> E.G.,
>>> $ perl -e 'print scalar localtime(time - 86400), "\n";'
>>>
>>> Or is it safe to use that?
>> Well, that last paragraph explains why that won't work. There are two
>> days where it breaks. On one you'll get the date from two days ago,
>> and the other the same day. So, no, it's not safe.
>Actually no, you won't get a day 2 days ago or the same date unless
>you're within a certain time of day. For example, if you are trying to
>find out what day was before the DST changing day at say 5 Pm you'll
>come up with the previous day @ 4 Pm, wouldn't you?
>
>Besides - 86400 is reliable here! Here in Arizona that is! Wish you guys
>would wise up and stop changing your clocks all the time. It's damn
>annoying! ;-)
>--
>Andrew DeFaria <http://defaria.com>
>Please, God, deliver us from your followers!
>
>-=-=-=-=-=-
>[Alternative: text/html]
>-=-=-=-=-=-
I'm still not sure, from what you guys have discovered,
what the faq *should* say?
Eg suggested explanations for a boss who complains
about how it works on those two days or not within a certain
part of the day?
I wonder how the finance and legal worlds handle this
stuff, eg in a contract?
David
------------------------------
Date: Wed, 28 May 2008 16:02:29 -0700
From: sln@netherlands.co
Subject: Re: Out of memory! Yet ...
Message-Id: <4ujr34lmed1bscche0m9qi12tgsei2263t@4ax.com>
On Wed, 28 May 2008 07:07:05 -0700 (PDT), "alexxx.magni@gmail.com" <alexxx.magni@gmail.com> wrote:
--<snip>--
>
>Thanks a lot for your help, that's what I needed!
>Here is the result from top of the memory occupation on my system
>(176 pgm images, 2.1MB each):
>
>without byte array simulation: 82.5% MEM
>with byte array simulation: 8% MEM !!!!!
>
>It is certainly slower to process (dont know exactly how much, I didnt
>timed), but now memory space is used soooooo better!
>
>THANK YOU!
>
>Alessandro
Well if it worked for you, then you must have FIXED my code errors.
Notably, on asignment/reads, the element must be checked for undef.
AND the bit-wise "&" to find the packed element should not be there.
I have some benchmark and memory usage numbers that you can guage performance with.
With the fixes, I have also included a small test bed that you can cut & paste.
I was going to make a perl module out of this but I have not seen any great demand for it.
In that case, I recommend to you that you use the inline versions of asignment/reads as
in the listing below.
I'm not sure why you would use Perl for this, however, since you are, the really good news
is the packing is scalable, and the performance isn't bad when using inline, and it will get
you what you wan't.
I encourage others to test this on a variety of machines and report time/memory usage.
GENERAL BENCHMARK DATA
----------------------
Data Set #1:
3 dimensional numeric array (10, 1600, 1200) of BYTE's, roughly 10 x 2MB of 8-bit data, 19,200,000 elements
Memory consumption from asignment:
Perl - 410 MB
Byte simulation (pack) - 112 MB
Asignment time:
Perl - 15 seconds
Byte simulation (inline) - 31 seconds
Byte simulation (fast function) - 45 seconds
Byte simulation (normal function) - 60 seconds
Read time:
Perl - 8 seconds
Byte simulation (inline) - 15 seconds
Byte simulation (fast function) - 20 seconds
Byte simulation (normal function) - 26 seconds
Data Set #2:
3 dimensional numeric array (100, 1600, 1200) of BYTE's, roughly 100 x 2MB of 8-bit data, 190,200,000 elements
Memory consumption from asignment:
Perl - N/A, > 3 GB
Byte simulation (pack) - 1.12 GB
Asignment time:
Perl - N/A
Byte simulation (inline) - 4 min's 20 seconds
Byte simulation (fast function) - 6 min's
Byte simulation (normal function) - 9 min's
Read time:
Perl - N/A
Byte simulation (inline) - 2 min's 30 seconds
Byte simulation (fast function) - not tested
Byte simulation (normal function) - not tested
CONCLUSIONS
-----------
Even though a numeric array of size (100, 1600, 1200) could not be conventionally asigned
with the limited memory I have (2 GB), it is apparent from the benchmarks, since it scales
linear, that this array would consume over 4 GB of memory.
In the BYTE simulation, it only consumes 1 GB's of memory.
And in a similar fashion, it would consume 2 GB's if using USHORT, or 16-bit asignment.
The speed would be of some concern. Inline usage roughly doubles the asignment and read speed.
Fast-function usage is even slower by %50, normal-function usage by %100.
But who cares. If everything is needed in ram, nothing will be faster.
I guess it depends if the overhead of repeatedly reading, and memory asignment from disk,
is faster than the bit-parsing. I would say its not.
BENCHMARK SAMPLE (cut/paste/run)
--------------------------------
use strict;
use warnings;
my ($val, $valout, $retval, $bitpos, $ref_element) = (0, 0, 0, 0, undef);
my @AAA = (); # test array
my ($ni, $nx, $ny) = (10, 1600, 1200); # size of test array (roughly 10 x 2MB)
my $test_inline = 1; # 1 = test using inline
my $test_reading = 0; # 0 = don't test reading
# Note - lower the test array size if reading & printing values ... (2,2,512) is good
my $print_reads = 0; # 0 = don't print out read results
for my $i(1..$ni)
{
print "$i - ",$i*($nx*$ny)/(1000000)," MB of raw data\n";
for my $x(1..$nx)
{
for my $y(1..$ny)
{
$val = $y;
if ($test_inline) # inline BYTE asignment (fastest)
{
$bitpos = ($y & 3) * 8;
$ref_element = \$AAA[$i][$x][$y >> 2];
$$ref_element = 0 if (!defined $$ref_element);
$$ref_element = ($$ref_element & ~(0xFF << $bitpos)) | (($val & 0xFF) << $bitpos);
}
else { # function call, BYTE asignment (slowest)
set_BYTeFast(\@{$AAA[$i][$x]}, $y, $val);
}
}
}
}
if ($test_reading)
{
print "\nStarting read test ... note time\n";
for my $i(1..$ni)
{
print "\n\n\ni=$i\n======================================\n" if ($print_reads);
for my $x(1..$nx)
{
print "\n\nx=$x\n++++++++++++++++++++++++++++++++++\n" if ($print_reads);
for my $y(1..$ny)
{
if ($test_inline) # inline BYTE read (fastest)
{
$bitpos = ($y & 3) * 8;
$ref_element = \$AAA[$i][$x][$y >> 2];
$$ref_element = 0 if (!defined $$ref_element);
$valout = ($$ref_element & (0xFF << $bitpos)) >> $bitpos;
print "$valout, " if ($print_reads);
}
else {
$valout = get_BYTeFast(\@{$AAA[$i][$x]}, $y);
print "$valout, " if ($print_reads);
}
}
}
}
}
#######################################################
# Note - Inline usage & Globals for "Fast" calls
#my ($val, $valout, $retval, $bitpos, $ref_element) = (0, 0, 0, 0, undef);
#
#
# Inline (fastest)
# =====================================
#
# Inline BYTE Writing: $AAA[$i][$x][$y]
#{
# # $val is what to asign
# $bitpos = ($y & 3) * 8;
# $ref_element = \$AAA[$i][$x][$y >> 2];
# $$ref_element = 0 if (!defined $$ref_element);
# $$ref_element = ($$ref_element & ~(0xFF << $bitpos)) | (($val & 0xFF) << $bitpos);
#}
#
# Inline BYTE Reading: $AAA[$i][$x][$y]
#{
# # $valout is the the real value in the element
# $bitpos = ($y & 3) * 8;
# $ref_element = \$AAA[$i][$x][$y >> 2];
# $$ref_element = 0 if (!defined $$ref_element);
# $valout = ($$ref_element & (0xFF << $bitpos)) >> $bitpos;
#}
# Functions (slowest)
# ===============================================
# writing: set_xxx(\@{$AAA[$i][$x]}, $y, $val);
# reading: $valout = get_xxx(\@{$AAA[$i][$x]}, $y);
## Not thread safe -----------
##
sub set_BYTeFast
{
$bitpos = ($_[1] & 3) * 8;
$ref_element = \${$_[0]}[$_[1] >> 2];
$$ref_element = 0 if (!defined $$ref_element);
$$ref_element = ($$ref_element & ~(0xFF << $bitpos)) | (($_[2] & 0xFF) << $bitpos);
}
sub get_BYTeFast
{
$bitpos = ($_[1] & 3) * 8;
$ref_element = \${$_[0]}[$_[1] >> 2];
$$ref_element = 0 if (!defined $$ref_element);
return (($$ref_element & (0xFF << $bitpos)) >> $bitpos);
}
sub get_CHArFast
{
$bitpos = ($_[1] & 3) * 8;
$ref_element = \${$_[0]}[$_[1] >> 2];
$$ref_element = 0 if (!defined $$ref_element);
$retval = ($$ref_element & (0xFF << $bitpos)) >> $bitpos;
return ($retval & 0x80 ? $retval-0x100 : $retval);
}
sub set_USHORtFast
{
my $bitpos = ($_[1] & 1) * 16;
$ref_element = \${$_[0]}[$_[1] >> 1];
$$ref_element = 0 if (!defined $$ref_element);
$$ref_element = ($$ref_element & ~(0xFFFF << $bitpos)) | (($_[2] & 0xFFFF) << $bitpos);
}
sub get_USHORtFast
{
my $bitpos = ($_[1] & 1) * 16;
$ref_element = \${$_[0]}[$_[1] >> 1];
$$ref_element = 0 if (!defined $$ref_element);
return (($$ref_element & (0xFFFF << $bitpos)) >> $bitpos);
}
sub get_SHORtFast
{
my $bitpos = ($_[1] & 1) * 16;
$ref_element = \${$_[0]}[$_[1] >> 1];
$$ref_element = 0 if (!defined $$ref_element);
$retval = ($$ref_element & (0xFFFF << $bitpos)) >> $bitpos;
return ($retval & 0x8000 ? $retval-0x10000 : $retval);
}
## Thread safe --------
##
sub set_BYTe
{
my ($RefArray, $Index, $Value) = @_;
my $bitpos = ($Index & 3) * 8;
my $element = $Index >> 2;
my $ref_element = \${$RefArray}[$element];
$$ref_element = 0 if (!defined $$ref_element);
$$ref_element = ($$ref_element & ~(0xFF << $bitpos)) | (($Value & 0xFF) << $bitpos);
}
sub get_BYTe
{
my ($RefArray, $Index) = @_;
my $bitpos = ($Index & 3) * 8;
my $element = $Index >> 2;
my $ref_element = \${$RefArray}[$element];
$$ref_element = 0 if (!defined $$ref_element);
return (($$ref_element & (0xFF << $bitpos)) >> $bitpos);
}
sub get_CHAr
{
my ($RefArray, $Index) = @_;
my $bitpos = ($Index & 3) * 8;
my $element = $Index >> 2;
my $ref_element = \${$RefArray}[$element];
$$ref_element = 0 if (!defined $$ref_element);
my $retval = ($$ref_element & (0xFF << $bitpos)) >> $bitpos;
return ($retval & 0x80 ? $retval-0x100 : $retval);
}
sub set_USHORt
{
my ($RefArray, $Index, $Value) = @_;
my $bitpos = ($Index & 1) * 16;
my $element = $Index >> 1;
my $ref_element = \${$RefArray}[$element];
$$ref_element = 0 if (!defined $$ref_element);
$$ref_element = ($$ref_element & ~(0xFFFF << $bitpos)) | (($Value & 0xFFFF) << $bitpos);
}
sub get_USHORt
{
my ($RefArray, $Index, $Value) = @_;
my $bitpos = ($Index & 1) * 16;
my $element = $Index >> 1;
my $ref_element = \${$RefArray}[$element];
$$ref_element = 0 if (!defined $$ref_element);
return (($$ref_element & (0xFFFF << $bitpos)) >> $bitpos);
}
sub get_SHORt
{
my ($RefArray, $Index) = @_;
my $bitpos = ($Index & 1) * 16;
my $element = $Index >> 1;
my $ref_element = \${$RefArray}[$element];
$$ref_element = 0 if (!defined $$ref_element);
my $retval = ($$ref_element & (0xFFFF << $bitpos)) >> $bitpos;
return ($retval & 0x8000 ? $retval-0x10000 : $retval);
}
__END__
-sln
robic(at)adelphia.net
------------------------------
Date: Wed, 28 May 2008 15:25:10 -0700 (PDT)
From: mdcarlile <mdcarlile@googlemail.com>
Subject: Re: Turning a dir output into a webpage ??
Message-Id: <25fbe0aa-971c-4342-83c8-2d541a2ea313@y38g2000hsy.googlegroups.com>
On 28 May, 22:24, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
> mdcarlile <mdcarl...@googlemail.com> wrote in news:0d5cf532-77ce-4bff-
> 93b3-9e8d0d67f...@f36g2000hsa.googlegroups.com:
>
> > I want to automatically run a script that will output the directory
> > listing and then output a .html page with the directory listing and
> > the links constructed.
>
> OK. Give it a shot.
>
> > Is this possible in perl??
>
> Of course it is.
>
> > =A0I have been unsuccessful using c.
>
> s/c/C/
>
> I don't see much of a chance of you succeeding in solving this problem
> in Perl either (I am assuming you know C and do not know Perl, otherwise
> the inclusion of the statement above does not make any sense).
>
> > Any pointers would be great, as I have challenged myself to do this.
>
> It looks to me like you are on the market for free fish without admiting
> such.
>
> The method, regardless of language is trivial:
>
> * Read the list of all files in a location.
>
> * For each file in list, create an HTML link.
>
> * Of course, surround the whole thing with the appropriate HTML.
>
> I would recommend using HTML::Template.
>
> Sinan
>
> --
> A. Sinan Unur <1...@llenroc.ude.invalid>
> (remove .invalid and reverse each component for email address)
>
> comp.lang.perl.misc guidelines on the WWW:http://www.rehabitation.com/clpm=
isc/
Thanks for the reply (I think!!)
Maybe I did not make myself clear - I realise that I can do the HTML
manually -but whats the un in that.
I want a script that will run once a day and generate the new content
- which will be additions to the directory (captured by the dir
command [or likewise]).
You are right I am a newbie to perl - but will spend time learning if
the problem is solvable in perl.
When you say i have littel chance of solving the problem was that me
personally or via perl? i think it's important to know which you
mean.
Cheers
Mark
------------------------------
Date: Wed, 28 May 2008 15:31:22 -0700 (PDT)
From: mdcarlile <mdcarlile@googlemail.com>
Subject: Re: Turning a dir output into a webpage ??
Message-Id: <a5706b3b-e057-4041-8fc7-8bd4b1776a27@m73g2000hsh.googlegroups.com>
On 28 May, 23:25, mdcarlile <mdcarl...@googlemail.com> wrote:
> On 28 May, 22:24, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
>
>
>
>
>
> > mdcarlile <mdcarl...@googlemail.com> wrote in news:0d5cf532-77ce-4bff-
> > 93b3-9e8d0d67f...@f36g2000hsa.googlegroups.com:
>
> > > I want to automatically run a script that will output the directory
> > > listing and then output a .html page with the directory listing and
> > > the links constructed.
>
> > OK. Give it a shot.
>
> > > Is this possible in perl??
>
> > Of course it is.
>
> > > =A0I have been unsuccessful using c.
>
> > s/c/C/
>
> > I don't see much of a chance of you succeeding in solving this problem
> > in Perl either (I am assuming you know C and do not know Perl, otherwise=
> > the inclusion of the statement above does not make any sense).
>
> > > Any pointers would be great, as I have challenged myself to do this.
>
> > It looks to me like you are on the market for free fish without admiting=
> > such.
>
> > The method, regardless of language is trivial:
>
> > * Read the list of all files in a location.
>
> > * For each file in list, create an HTML link.
>
> > * Of course, surround the whole thing with the appropriate HTML.
>
> > I would recommend using HTML::Template.
>
> > Sinan
>
> > --
> > A. Sinan Unur <1...@llenroc.ude.invalid>
> > (remove .invalid and reverse each component for email address)
>
> > comp.lang.perl.misc guidelines on the WWW:http://www.rehabitation.com/cl=
pmisc/
>
> Thanks for the reply (I think!!)
>
> Maybe I did not make myself clear - I realise that I can do the HTML
> manually -but whats the un in that.
> I want a script that will run once a day and generate the new content
> - which will be additions to the directory (captured by the dir
> command [or likewise]).
>
> You are right I am a newbie to perl - but will spend time learning if
> the problem is solvable in perl.
>
> When you say i have littel chance of solving the problem was that me
> personally or via perl? =A0i think it's important to know which you
> mean.
>
> Cheers
>
> Mark- Hide quoted text -
>
> - Show quoted text -
Just realised what you were saying ---- Cheers :-)
------------------------------
Date: Wed, 28 May 2008 15:24:20 -0700 (PDT)
From: Ron Bergin <rkb@i.frys.com>
Subject: Re: Variable remaining undef in one place but not another.
Message-Id: <1ae627e6-0be9-46c4-8f57-6c460661a0a1@w8g2000prd.googlegroups.com>
On May 28, 7:58 am, Justin C <justin.0...@purestblue.com> wrote:
> I have a perl program which generates a web-page. It is supposed to pass
> the cwd on to part that starts the HTML, so that the cwd can be used in
> the HTML title tag. It doesn't. My logs tell me it is undefined.
> However, when I pass it on to another program it is defined. I'm sure
> I'm just not seeing the wood for the trees... either that, or perl is
> running ahead of itself and not getting an answer to the "getPage()"
> subroutine.
>
> #!/usr/bin/perl
>
> use warnings;
> use strict;
> use CGI qw/:standard/;
> use CGI::Carp qw/fatalsToBrowser/;
>
> my $page = getPage();
> htmlStart();
> LeftNav();
>
> sub getPage{
> my $rv = `../docs/getCwd.pl`;
> return $rv;}
>
> sub htmlStart{
> my @args = ("../docs/htmlStart.pl", $page);
> system(@args);}
>
> sub LeftNav{
> my @args = ("../docs/navLeft.pl", $page);
> system(@args);
>
> }
>
> ----
> Here is getCwd.pl:
>
> #!/usr/bin/perl
>
> use warnings;
> use strict;
> use Cwd;
>
> my $path = (cwd() =~ /^\/+.*\/(.*)$/);# get just the last part of the path
> print "$1";
>
> ----
> Here is htmlStart.pl:
>
> #!/usr/bin/perl
> use warnings;
> use strict;
> use CGI qw/:standard/;
> use CGI::Carp qw/fatalsToBrowser/;
>
> my $page = pop @ARGV;
>
> # Define the page title
> my $title = "Masons Music - $page";
>
> # Start the html document
> print header;
> print start_html(
> -title=>$title,
> -style=>{'src'=>'/docs/style.css'},
> );
>
> ----
> Here is navLeft.pl, where $page is passed successfully, and doesn't
> throw up and undef warning:
>
> #!/usr/bin/perl
> use warnings;
> use strict;
>
> my @links = qw/contact about sales news/;
> my $page = pop @ARGV;
>
> foreach ( @SiteLinks::sequence ) {
> firstPart($_);
>
> }
>
> sub firstPart{
> if ( $page eq (pop @links) ) {
> print " class=\"thisPage2\"";
> }
>
> }
>
> ----
>
> Sorry there isn't less code, but I couldn't find a way of demonstrating
> the problem with fewer lines.
>
> As you can see, $page is passed to both of the external programs, yet in
> the first it's passed to it remains undef while the second (and third,
> for there is another I've not shown here) gets the value.
>
> Any ideas what's going on? I have reduced the code above for conciseness,
> I hope it's not now beyond understanding.
>
> I thank you for any help you can give with this.
>
> Justin.
That seams a little inefficient to me. Why not combine those scripts
and use HTML::Template? If needed, you could easily split up the
template files into header.tmpl, footer.tmpl, leftnav.tmpl, etc
http://search.cpan.org/~samtregar/HTML-Template-2.9/Template.pm
------------------------------
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 1586
***************************************