[22988] in Perl-Users-Digest
Perl-Users Digest, Issue: 5208 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 10 03:05:56 2003
Date: Thu, 10 Jul 2003 00:05:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 10 Jul 2003 Volume: 10 Number: 5208
Today's topics:
comparing floating point numbers <thens@nospam.com>
Re: Creating macros in VISIO? <bwalton@rochester.rr.com>
Re: Fastest way to build a hash <REMOVEsdnCAPS@comcast.net>
Re: Fastest way to build a hash <mgjv@tradingpost.com.au>
Re: Fastest way to build a hash <ben.goldberg@hotpop.com>
Help request for CDO/OLE Perl program <drabels@hotmail.com>
Re: Help request for CDO/OLE Perl program <drabels@hotmail.com>
Re: Help request for CDO/OLE Perl program <bwalton@rochester.rr.com>
hi people (Irfan Shaikh)
Re: info <bwalton@rochester.rr.com>
Re: Odd open but no warning <bwalton@rochester.rr.com>
Re: perl restaurant menu <mreed@reedassociates.com>
Re: Prototyping C programs using Perl <cwilbur@mithril.chromatico.net>
Re: Remove line <noreply@gunnar.cc>
Re: Remove line <cwilbur@mithril.chromatico.net>
Request for help in using GD::Graph module (y label and (deepak p)
Re: Request for help in using GD::Graph module (y label <mgjv@tradingpost.com.au>
string question john62@electronmail.com
Re: string question <charlie_baratski@yahoo.com>
Re: string question <grazz@pobox.com>
Re: string question (Sam Holden)
Re: Total Butt Heads in this news group (Sara)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 10 Jul 2003 10:12:39 +0530
From: Thens <thens@nospam.com>
Subject: comparing floating point numbers
Message-Id: <20030710101239.5a111e91.thens@nospam.com>
Hi,
I have a problem comparing floating point numbers. After a lot of googling and docs I found the issue to be because of the internal floating point representation.
Here is a sample program that explains that
#!/usr/local/bin/perl
use strict;
use warnings;
my ( $num, $num1, $num2 );
$num = 1.8;
$num1 = ( $num * (1 + (10/100) ) ); # $num + 10% $num => 1.98
print "Number :", sprintf "%2.20f \n" , $num;
print "Number +10% :", sprintf "%2.20f \n", $num1;
$num2 = 1.98;
print "Number +10% :", sprintf "%30.20f \n", $num2;
if ( $num1 != $num2 ) {
print "FIRST PASS >> $num1 is not equal to $num2 !! \n";
}
if ( ($num1+0.1) != ($num2+.1) ) {
print "SECOND PASS >> $num1 is not eqaul to $num2 !!\n";
}
This prints
FIRST PASS >> 1.98 is not equal to 1.98 !!
I understand this is because of the floating point representation. Then I tried to solve it by adding 0.1 at both the ends and then comparing the numbers. THis seems to have solved the problem. My question is, Is this a reliable solution.
While searching the group archive, I found this can be achieved by checking for a small delta like
$delta = 0.0001
if ( abs ( $num1 - $num2 ) < $delta ) {
# Now they are eual
}
..
I wanted to know under what circumstances may adding 0.1 at both ends can fail.
Thanks and Regards,
Thens.
------------------------------
Date: Thu, 10 Jul 2003 03:11:46 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Creating macros in VISIO?
Message-Id: <3F0CD96D.6010907@rochester.rr.com>
Chad Johnson wrote:
> I am trying to write a PERL script to set certain printing attributes
> for VISIO documents. Someone gave me the advice that I should create a
> macro in VISIO and then translate the source ove to PERL script. The
> problem is that I don't know how to create macros in VISIO. I am
> trying to set the printing attributes to "download as soft font" and
> "set as truetype font".
...
> Chad
You'll probably have to ask your question in a Visio newsgroup, as the
chances of finding someone here who even knows what Visio is is slim,
let alone the chances of finding a Visio expert. Maybe Visio's help
would help?
--
Bob Walton
------------------------------
Date: Wed, 09 Jul 2003 20:31:33 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Fastest way to build a hash
Message-Id: <Xns93B3DAF493414sdn.comcast@206.127.4.25>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
"Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote in
news:Xns93B3D20B7EA76sdn.comcast@206.127.4.25:
>
> fischerlaender@gmx.de (Stefan Fischerländer) wrote in
> news:ff9bee6c.0307091528.5d0b71a1@posting.google.com:
>
>> I've got the following situation:
>>
>> My data is stored in a file; 5 bytes form one record. The bytes 0 to 3
>> are a long integer, which is regarded as the key, wheras byte 4 is the
>> value. I have to read this data structure into a hash.
>>
>> What I'm doing at the moment is:
>> open(IN,"<file");
>> while(read(IN, $buf, 5))
>> {
>> $hash{unpack("L", substr($buf,0,4))} = substr($buf,4,1);
>> }
>> close(IN);
>>
>> This takes about 5 seconds to read a file with about 100.000 records,
>> which is to long for my needs. (Celeron 800, IDE 7200rpm)
>
> Untested, but my first thought is:
>
> $/ = undef;
> $raw = <IN>; # slurp whole file
> %hash = $raw =~ /(....)(.)/gs; # split into 4, 1 byte pairs
On second thought, splitting the whole file up into pairs and then
assigning it to a hash is a waste, I think. Perhaps:
$/ = undef;
$raw = <IN>;
$hash{$1} = $2 while $raw =~ /(....)(.)/gs;
(again, untested).
- --
Eric
$_ = reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBPwzB6GPeouIeTNHoEQIU4ACeMHYALFq/lwuPglJ+0hfPmx7wcKIAn3Sf
vV6dH8uXJfGEGtYnoy+/PXKN
=TsTT
-----END PGP SIGNATURE-----
------------------------------
Date: Thu, 10 Jul 2003 11:59:28 +1000
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Fastest way to build a hash
Message-Id: <slrnbgpi40.rlm.mgjv@martien.heliotrope.home>
On 9 Jul 2003 16:28:10 -0700,
Stefan Fischerländer <fischerlaender@gmx.de> wrote:
> I've got the following situation:
>
> My data is stored in a file; 5 bytes form one record. The bytes 0 to 3
> are a long integer, which is regarded as the key, wheras byte 4 is the
> value. I have to read this data structure into a hash.
>
> What I'm doing at the moment is:
> open(IN,"<file");
> while(read(IN, $buf, 5))
> {
> $hash{unpack("L", substr($buf,0,4))} = substr($buf,4,1);
> }
> close(IN);
[OP also states that IO is not the bottleneck]
Maybe this is faster (all code untested, mainly because I didn't feel
like creating a test data set):
my ($key, $val) = unpack "La1", $buf;
$hash{$key} = $val;
or maybe
%hash = %hash, unpack "La1", $buf;
Alternatively, you could read in more records at once:
my $n_buf = 10; # Adjust to needs
my $pack_template = "La1" x $n_buf;
while(IN, $buf, 5 * $n_buf)
{
%vals = unpack $pack_template, $buf;
%hash{keys %vals} = values %vals;
}
Or in the loop body, something like:
%hash = %hash, unpack $pack_template, $buf;
If you do this, you might need to make sure that your boundary
conditions (the last group of things read from the file) are ok.
You could of course read the whole file in memory in one go. get the
file size, divide by 5, and use the result as the value for $n_buf up
there. No need to loop, or incrementally change %hash then:
open(IN, "file") or die $!;
my $n_bytes = -s IN;
my $pack_template = "La1" x ($n_bytes/5);
read(IN, $buf, $n_bytes); # do error checking
%hash = unpack $pack_template, $buf;
Or maybe something like: (again, this is untested)
%hash = do {
local ($/, *IN);
open(IN, "file") or die $!;
my $n_bytes = -s IN;
my $pack_template = "La1" x ($n_bytes/5);
unpack $pack_template, <IN>;
};
Martien
--
|
Martien Verbruggen | That's not a lie, it's a terminological
| inexactitude.
|
------------------------------
Date: Wed, 09 Jul 2003 22:49:56 -0400
From: Benjamin Goldberg <ben.goldberg@hotpop.com>
Subject: Re: Fastest way to build a hash
Message-Id: <3F0CD454.F9F30C23@hotpop.com>
Stefan Fischerländer wrote:
>
> I've got the following situation:
>
> My data is stored in a file; 5 bytes form one record. The bytes 0 to 3
> are a long integer, which is regarded as the key, wheras byte 4 is the
> value. I have to read this data structure into a hash.
[snip]
> Does anyone have any ideas how to build this hash faster?
How about doing the following before populating the hash:
keys(%hash) = (-s IN)/5;
This will allocate as many buckets as you have key/value pairs.
Under most conditions, if you allocate more buckets than you've got
key/value pairs, it will be faster, unless perl's hash function just by
chance hashes each of your keys to different values.
I'm not sure what's the optimum, though. If you allocate *too* many
buckets, you're merely wasting memory, and not benefiting your
program...)
How fast/slow is the following program:
open(IN,"<file") or die;
keys(%hash) = (-s IN) / 5; # try /4, /3, /2, /1 instead of /5.
while(read IN, $buf, 4) {
$hash{$buf} = getc IN;
}
close(IN);
__END__
Note that I left out the unpack(), since doing so makes the hash keys
smaller, and thus use less memory, and also, they're'll be fewer hash
collisions, which should also speed up the program.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Thu, 10 Jul 2003 11:20:19 +1000
From: "Daniel" <drabels@hotmail.com>
Subject: Help request for CDO/OLE Perl program
Message-Id: <3f0cbee8$0$59955$c30e37c6@lon-reader.news.telstra.net>
Hi everyone,
I would like to pick some of your brains regarding the following
piece of code. Essentially, I'm trying to connect to an Exchange
information store and discover it's size. I have done this successfully
in VBScript, but I would rather have it in Perl (I have my reasons :-) )
So far, the Perl code can connect to the server as any user, and
cycle through the available information stores. However, I am
having trouble retrieving the information store size (the result is
always: Win32::OLE=HASH(<hex address>) )
I am using the InfoStore.Fields.Item property (the default operation
in VBScript, I believe) using PR_MESSAGE_SIZE (I'll try the
EXTENDED version later on for mailboxes bigger than 4gig.)
Any help would be greatly appreciated!
Thanks,
Daniel
Here is the Perl code so far (the VBScript code follows)
---
(mailboxsize.pl - some of the error checking removed to reduce
the post size on usenet.)
---
use Win32::OLE;
use Win32::OLE::Variant;
use Strict;
Win32::OLE->Initialize(Win32::OLE::COINIT_OLEINITIALIZE);
$mapi = Win32::OLE->new('MAPI.Session') or die Win32::OLE->LastError();
$Servername = "servername goes here";
$Username = "username goes here";
%Profile = ("ProfileInfo"=>"$Servername\n$Username");
$mapi->logon(\%Profile);
$InfoStores = $mapi->InfoStores();
$InfoCount = $InfoStores->{COUNT};
$PR_MESSAGE_SIZE = hex(E080003);
$LookFor = "Mailbox - ";
for ($i = 1; $i <= $InfoCount; $i++)
{
$item = $InfoStores->Item($i);
$name = $item->{NAME};
if ($name =~ /$LookFor/i)
{
$fields = $item->Fields;
$size = $item->Fields->Item($PR_MESSAGE_SIZE);
print "Store: $name\n";
print " Size: $size\n";
}
}
$mapi->Logoff();
exit();
---
(mailboxsize.vbs VBScript code, using cscript to execute)
---
sServername = "servername goes here"
sUsername = "username goes here"
Set oSession = CreateObject("MAPI.Session")
strProfileInfo = sServerName & vbLf & sUserName
oSession.Logon , , False, True, , True, strProfileInfo
Set oInfoStores = oSession.InfoStores
For Each oInfoStore In oInfoStores
If InStr(1, oInfoStore.Name, "Mailbox - ", 1) <> 0 Then
StoreName = oInfoStore.Name
StorageUsed = oInfoStore.Fields(&HE080003) ' = PR_MESSAGE_SIZE
WScript.Echo "Store: " & StoreName
WScript.Echo " Size: " & StorageUsed
End If
Next
oSession.Logoff
------------------------------
Date: Thu, 10 Jul 2003 11:58:21 +1000
From: "Daniel" <drabels@hotmail.com>
Subject: Re: Help request for CDO/OLE Perl program
Message-Id: <3f0cca64$0$59952$c30e37c6@lon-reader.news.telstra.net>
Looks like I've shot off again too quickly ...
The variable returned needs to be dereferenced.
For those interested, here's the fix:
Replace:
$size = $item->Fields->Item($PR_MESSAGE_SIZE);
With:
$data_ref = $item->Fields->Item($PR_MESSAGE_SIZE);
$size = $data_ref->{"Value"};
(Thanks to the resident sysadmin for picking this one ... I really need to
learn more about Perl!)
Daniel
"Daniel" <drabels@hotmail.com> wrote in message
news:3f0cbee8$0$59955$c30e37c6@lon-reader.news.telstra.net...
> Hi everyone,
>
> I would like to pick some of your brains regarding the following
> piece of code. Essentially, I'm trying to connect to an Exchange
> information store and discover it's size. I have done this successfully
> in VBScript, but I would rather have it in Perl (I have my reasons :-) )
>
> So far, the Perl code can connect to the server as any user, and
> cycle through the available information stores. However, I am
> having trouble retrieving the information store size (the result is
> always: Win32::OLE=HASH(<hex address>) )
>
> I am using the InfoStore.Fields.Item property (the default operation
> in VBScript, I believe) using PR_MESSAGE_SIZE (I'll try the
> EXTENDED version later on for mailboxes bigger than 4gig.)
>
> Any help would be greatly appreciated!
>
> Thanks,
>
> Daniel
>
> Here is the Perl code so far (the VBScript code follows)
>
> ---
> (mailboxsize.pl - some of the error checking removed to reduce
> the post size on usenet.)
> ---
>
> use Win32::OLE;
> use Win32::OLE::Variant;
> use Strict;
>
> Win32::OLE->Initialize(Win32::OLE::COINIT_OLEINITIALIZE);
> $mapi = Win32::OLE->new('MAPI.Session') or die Win32::OLE->LastError();
> $Servername = "servername goes here";
> $Username = "username goes here";
> %Profile = ("ProfileInfo"=>"$Servername\n$Username");
> $mapi->logon(\%Profile);
> $InfoStores = $mapi->InfoStores();
> $InfoCount = $InfoStores->{COUNT};
> $PR_MESSAGE_SIZE = hex(E080003);
> $LookFor = "Mailbox - ";
> for ($i = 1; $i <= $InfoCount; $i++)
> {
> $item = $InfoStores->Item($i);
> $name = $item->{NAME};
> if ($name =~ /$LookFor/i)
> {
> $fields = $item->Fields;
> $size = $item->Fields->Item($PR_MESSAGE_SIZE);
> print "Store: $name\n";
> print " Size: $size\n";
> }
> }
> $mapi->Logoff();
> exit();
>
> ---
> (mailboxsize.vbs VBScript code, using cscript to execute)
> ---
>
> sServername = "servername goes here"
> sUsername = "username goes here"
> Set oSession = CreateObject("MAPI.Session")
> strProfileInfo = sServerName & vbLf & sUserName
> oSession.Logon , , False, True, , True, strProfileInfo
> Set oInfoStores = oSession.InfoStores
> For Each oInfoStore In oInfoStores
> If InStr(1, oInfoStore.Name, "Mailbox - ", 1) <> 0 Then
> StoreName = oInfoStore.Name
> StorageUsed = oInfoStore.Fields(&HE080003) ' = PR_MESSAGE_SIZE
> WScript.Echo "Store: " & StoreName
> WScript.Echo " Size: " & StorageUsed
> End If
> Next
> oSession.Logoff
>
>
------------------------------
Date: Thu, 10 Jul 2003 02:40:22 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Help request for CDO/OLE Perl program
Message-Id: <3F0CD211.8070100@rochester.rr.com>
Daniel wrote:
...
> I would like to pick some of your brains regarding the following
> piece of code. Essentially, I'm trying to connect to an Exchange
> information store and discover it's size. I have done this successfully
> in VBScript, but I would rather have it in Perl (I have my reasons :-) )
>
> So far, the Perl code can connect to the server as any user, and
> cycle through the available information stores. However, I am
> having trouble retrieving the information store size (the result is
> always: Win32::OLE=HASH(<hex address>) )
>
> I am using the InfoStore.Fields.Item property (the default operation
> in VBScript, I believe) using PR_MESSAGE_SIZE (I'll try the
> EXTENDED version later on for mailboxes bigger than 4gig.)
...
> Daniel
...
> use Win32::OLE;
> use Win32::OLE::Variant;
> use Strict;
This should be:
use strict;
While
use Strict;
may not generate an error on Windoze, it doesn't work, either. It is a
case-insensitivity thing -- Windoze is not case sensitive, and Perl is.
So Windoze finds file strict.pm, and then Perl tries to work with the
Strict module, which doesn't fly. I guess Perl already thought it
loaded the module, since the OS reported success in reading it -- but
then it can't find it. The moral of the story is that on Windoze,
you've got to get the case of your module names correct, and Perl
doesn't help you with that. Sigh.
>
> Win32::OLE->Initialize(Win32::OLE::COINIT_OLEINITIALIZE);
> $mapi = Win32::OLE->new('MAPI.Session') or die Win32::OLE->LastError();
> $Servername = "servername goes here";
> $Username = "username goes here";
> %Profile = ("ProfileInfo"=>"$Servername\n$Username");
> $mapi->logon(\%Profile);
> $InfoStores = $mapi->InfoStores();
> $InfoCount = $InfoStores->{COUNT};
> $PR_MESSAGE_SIZE = hex(E080003);
The constant E080003 should be quoted. While warnings doesn't flag this
one, it probably should??. strict would have nabbed it, had you
actually been using it correctly. But I think your code is probably
putting the correct integer into $PR_MESSAGE_SIZE despite this. An
easier way would be:
$PR_MESSAGE_SIZE = 0xE080003;
> $LookFor = "Mailbox - ";
> for ($i = 1; $i <= $InfoCount; $i++)
> {
> $item = $InfoStores->Item($i);
> $name = $item->{NAME};
> if ($name =~ /$LookFor/i)
> {
> $fields = $item->Fields;
> $size = $item->Fields->Item($PR_MESSAGE_SIZE);
This statement is probably returning some VB object (with appropriate
Perlification), rather than the float or string you were expecting. I
recommend that you:
use Data::Dumper;
and then:
print Dumper($size);
to see what is actually being returned. From there you can probably
figure out what to do with it. Data::Dumper is your big-time debug
friend when working with Win32::OLE. Of course, you could run the Perl
debugger, too :-).
> print "Store: $name\n";
> print " Size: $size\n";
> }
> }
> $mapi->Logoff();
> exit();
>
...
HTH.
--
Bob Walton
------------------------------
Date: 9 Jul 2003 23:54:34 -0700
From: irfan381@netscape.net (Irfan Shaikh)
Subject: hi people
Message-Id: <2fe2f716.0307092254.68f99070@posting.google.com>
can some body tell me confiduring newsgroup in my netscape outlook.
I added this site in newsgroup but when I am saying subscribe it give
me an error saying that cant reach to host?
kindly if any body nos then help me out..
Thax
------------------------------
Date: Thu, 10 Jul 2003 03:06:37 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: info
Message-Id: <3F0CD837.3000308@rochester.rr.com>
yoman wrote:
> hello there !
> can someone give me an explanation of the following :
> let s have a script named test.pl :
>
> #!/usr/bin/perl -w
> $i=pack "h1" , "1a";
> print "$i\n";
>
> then let s do :
>
> bash$ ./test.pl |hexdump -C
> 00000000 01 0a |..|
> 00000002
>
> let s change the script :
> #!/usr/bin/perl -w
> $i=pack "h2" , "1a";
> print "$i\n";
>
> let s do :
> bash$ ./test.pl |hexdump -C
> 00000000 c2 a1 0a |...|
> 00000003
>
> so the question is :
> why the 'c2' byte is here ?
...
Hmmmm...it doesn't do that on my system (Windoze 98SE, AS Perl build
806). Of course, I don't have a hexdump command, either (someday I'll
start using an OS for my newsgroup reading, but not today), so I'm
directing the output to a file and looking at the file with a dump
program I wrote in Perl. I get the expected behavior with no extra
byte. Might be worth investigating if your hexdump program has a bug,
perhaps by writing out known bytes and seeing what it says you sent?
--
Bob Walton
------------------------------
Date: Thu, 10 Jul 2003 02:00:19 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Odd open but no warning
Message-Id: <3F0CC8AE.9070504@rochester.rr.com>
Colin Campbell wrote:
> In article <3F0B6A72.6080407@rochester.rr.com>, Bob Walton wrote:
>
>>>open FH, "|$external_program|";
>>>
>>See the docs for open() and IPC::Open2, which explain a bit about this.
>>
> Not really the question I was trying to ask. (I'd already replaced it
> with Open2 while cursing its author). But, the answer is that you only
> get the warning when running with warnings, not by doing a compile with
> warnings. (Hangs head in shame as he should of tried that before
> posting).
> Colin
>
Well, one of the things I was trying to say is that at compile time, all
the compiler checks for is a syntactically valid string for the second
argument of open(). Any string will suffice for compilation purposes.
It is only when execution is attempted that the string is evaluated and
the open is actually attempted to see if it works or not. Any garbagy
string will compile:
perl -wc -e 'open X,"|||~!@#$%^&*()_+|||" or die;print X "a"'
will nicely output
-e syntax OK
--
Bob Walton
------------------------------
Date: Thu, 10 Jul 2003 03:10:37 -0000
From: Mark Reed <mreed@reedassociates.com>
Subject: Re: perl restaurant menu
Message-Id: <Xns93B3EBC5AEB1Amreedreedassociatesc@216.168.3.44>
Im basically looking for the ability to have one public page where it
displays the menu by category. For example:
Appetizers-----
item 1 description Price
item 2 etc...
Lunch
Item 1 etc...
it would be a simple display of a restaurants menu.
The second part would be an admin back end where the restaurant owner can
manage the menu - add items, change items, delete items... etc..
The only experience i have with Perl or MySql is setting up canned
scripts from the net - and after searching everywhere, to my surprise, I
cannot find any canned scripts for this.
Where would you suggest I start? I assume a book on Perl basics, or
would PHP be better for this?
thanks
mmr
johndageek@yahoo.com (John D) wrote in
news:c608545f.0307080925.458c0db1@posting.google.com:
> Mark Reed <mreed@reedassociates.com> wrote in message
> news:<Xns93B1C8BA3E302mreedreedassociatesc@216.168.3.44>...
>> Does anyone have a perl script that can be used to manage an online
>> restaurant menu?
>>
>> Im looking for examples to study and cant find any on the net at the
>> popular archives.
>>
>> thanks
> Please take a shot at it and we can help you out with any perl
> probelms you may encounter.
>
> A little more definition might help also.
> "Manage an online resteraunt menu"
> -do you want code to run an online store?
> -do you want code to display a menu only
> -do you want a page to be displayed based upon a database
> (implying a method to maintain the database entries)
> -do you have experience with databases, cgi, javascript and web
> servers?
>
> Good luck
> JD
>
--
---------------
Mark M. Reed
mreed@reedassociates.com
------------------------------
Date: Thu, 10 Jul 2003 05:43:30 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: Prototyping C programs using Perl
Message-Id: <8765mbj6dd.fsf@mithril.chromatico.net>
"Sandy" <sandy@fafasite.com> writes:
> Thanks a lot :)
>
> Actually, I plan to write the program in pure C eventually.
>
> BTW, is there any feature of Perl that can effectively be employed for the
> purpose of prototyping a pure C program in particular?
What do you hope to accomplish by building a prototype in Perl?
This is a serious question; if the goal is to deal with complex data
structures without having to worry about memory management, we'll give
different advice than if the goal is to make a perl fan in upper
management happy.
Charlton
------------------------------
Date: Thu, 10 Jul 2003 03:14:42 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Remove line
Message-Id: <beif1t$5kq6t$1@ID-184292.news.dfncis.de>
Benjamin Goldberg wrote:
> You aren't restoring @testing after each test, so it will be faster
> than it would be RL.
Damned! Thanks, btw... It seems as if I didn't do anything right. :(
> The following code gives different results:
<snip>
> [Windows 95] C:\WINDOWS\TEMP>perl test.pl
> Benchmark: running Grep, Splice_1, Splice_2, each for at least 5 CPU
> seconds...
> Grep: 6 wallclock secs (5.44 CPU) @ 8575.00/s (n=46648)
> Splice_1: 4 wallclock secs (5.11 CPU) @ 6118.40/s (n=31265)
> Splice_2: 5 wallclock secs (5.17 CPU) @ 5684.91/s (n=29391)
> Rate Splice_2 Splice_1 Grep
> Splice_2 5685/s -- -7% -34%
> Splice_1 6118/s 8% -- -29%
> Grep 8575/s 51% 40% --
>
> PS: I just copied the "$#testing - 1" ... why do you have *that*,
> instead of $#testing directly?
Just another of my stupid mistakes. Furthermore, the auto-decrement of
$i within the for-loop was incorrect as well.
Actually, when I run Benchmark on my W98 box and Perl 5.8.0, Grep is
still the slowest and Splice_1 the fastest, but now I guess you can
say that the differences are negligible:
Rate Grep Splice_2 Splice_1
Grep 15395/s -- -10% -17%
Splice_2 17029/s 11% -- -9%
Splice_1 18644/s 21% 9% --
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 10 Jul 2003 05:28:32 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: Remove line
Message-Id: <87adbnj6om.fsf@mithril.chromatico.net>
Gunnar Hjalmarsson <noreply@gunnar.cc> writes:
> Well, I don't agree on that. IMO it is a straight-forward code that
> explicitly shows you what it does, and I find it very hard to
> understand why you seem to claim that grep is 'good' and splice is
> 'bad' code.
It took you three tries to get it right. How is that
"straightforward", compared to the grep solution, which is easier to
get right on the first try? Sure, you don't see the iteration through
the list, but that's implicit in the grep function; you don't *need*
to see the iteration.
Further, this is the sort of thing that grep does: filtering out the
elements of a list that match a certain condition. Using splice
instead of grep is foolish; it's the same sort of foolishness as
saying something like @string = split '', $string; and then doing
operations on the individual letters in @string: it's an approach that
will get you the result you want in the end; but you're fighting
against Perl to do it, and you'll confuse your maintenance programmers
for no good reason.
Charlton
------------------------------
Date: 9 Jul 2003 20:20:58 -0700
From: deepak10000@hotmail.com (deepak p)
Subject: Request for help in using GD::Graph module (y label and undef related)
Message-Id: <9e77c6b2.0307091920.511f06cf@posting.google.com>
Hello,
I'm writing perl scripts that utilize GD::Graph module to generate 3
types of graphs: bar, lines, linespoint and my question is specific to
this wonderful module. These 3 types of graphs are similar in that
they all have x-y axis and I'm running into difficulty in 2 areas.
1. In setting label for the ‘y axis' all 3 types of graphs, if I don't
include the method ‘set_y_label_font' in my graph generation data
structure, the y label appears as one would expect i.e. its
approximately centered in the y axis and oriented such that one would
read it bottom to top as illustrated in the URL below. (See y label –
"Revenue…")
http://wdvl.internet.com/Authoring/Languages/Perl/Weave/chart1-3.html
If however, I specify the font type and size for the y label as shown
below, the y label's orientation and placement gets messed up.
$graph->set_y_label_font('/usr/openwin/lib/X11/fonts/TrueType/CourierNew-Bold.ttf',
12);
What happens is 1) Y Label text gets automatically rotated 180 degrees
(hence, instead of it appearing from bottom to top along the y axis,
now its top to bottom). 2) Text is no longer centered along the y
axis, rather its gets shifted towards the bottom such that the last
letter of the y label ends at the start of y axis. I want to be able
to specify the y_label_font's type and size such that it does not
rotate and shift the text.
Incidentally when I specify the x_label_font, it does not mess its
orientation or placement. Why would x_label_font render fine while
y_label_font gets messed..its puzzling to me and don't know how to
fix.
2. In creating line graphs, if my data set is missing some data
points, I would expect to see breaks in the line. For example, if my
data set is as shown below
my @data = (['Jan', 'Feb', 'Mar', 'Apr', 'May', ‘Jun', ‘Jul'],
[50, 60, undef, 90, 50, undef, 80],
I would like to see a line segment connecting 50 to 60, then a break,
then a new segment connecting 90 to 50. The line graph however appears
to connect 50 to 60, then 60 to 90, then 90 to 50 and 50 to
80..ignoring the undef points. How can I specify GD::Graph::lines to
have breaks in the line segments when it encounters undefs?
I really appreciate and would like to thank in advance, if anyone can
help me overcome the difficulties. My env. if it matters is perl 5.61
running on Solaris 5.6 and we're using the latest GD::Graph module
(1.43).
Thank you for your time.
Best wishes,
Deepak
------------------------------
Date: Thu, 10 Jul 2003 15:58:55 +1000
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Request for help in using GD::Graph module (y label and undef related)
Message-Id: <slrnbgq04v.rlm.mgjv@martien.heliotrope.home>
On 9 Jul 2003 20:20:58 -0700,
deepak p <deepak10000@hotmail.com> wrote:
> If however, I specify the font type and size for the y label as shown
> below, the y label's orientation and placement gets messed up.
>
> $graph->set_y_label_font('/usr/openwin/lib/X11/fonts/TrueType/CourierNew-Bold.ttf',
> 12);
>
> What happens is 1) Y Label text gets automatically rotated 180 degrees
> (hence, instead of it appearing from bottom to top along the y axis,
> now its top to bottom). 2) Text is no longer centered along the y
> axis, rather its gets shifted towards the bottom such that the last
> letter of the y label ends at the start of y axis. I want to be able
> to specify the y_label_font's type and size such that it does not
> rotate and shift the text.
Looks like your text is, for some reason or other, also being rotated by
180 degrees. None of this happens for me. In fact, samples 14 and 71 in
the distribution do exactly this, without problems. Could you check
those examples in the distribution, just to see whether they do the same
thing?
If not, could you post (or email me) the full code for a program, as
small as possible, that displays the problem, together with its data
set? Could you also include the versions of GD, GD::Graph and GD::Text
you use? Run the following to find out:
#!/usr/local/bin/perl
use GD;
use GD::Text;
use GD::Graph;
print "GD: $GD::VERSION\n";
print "GD::Text: $GD::Text::VERSION\n";
print "GD::Graph: $GD::Graph::VERSION\n";
print "Perl: $]\n";
Alternatively, you can run 'make info' in the samples directory of a
recent GD::Graph distribution.
> Incidentally when I specify the x_label_font, it does not mess its
> orientation or placement. Why would x_label_font render fine while
> y_label_font gets messed..its puzzling to me and don't know how to
> fix.
It's puzzling me as well, which is why I'd like that information above,
so I can see whether there's some problem with GD::graph or something
else.
> 2. In creating line graphs, if my data set is missing some data
> points, I would expect to see breaks in the line. For example, if my
> data set is as shown below
That's on my todo list.
> My env. if it matters is perl 5.61
> running on Solaris 5.6 and we're using the latest GD::Graph module
> (1.43).
Ok.. Could you also include the version numbers of GD and GD::Text? And
if you know which libgd and which freetype GD were linked against, that
could also help. There used to be some bugs in the freetype library
that entirely screwed up rotations. This happened several times.
I'd actually say that that is the most likely cause, without knowing
more.
Martien
--
|
Martien Verbruggen | prepBut nI vrbLike adjHungarian! qWhat's
| artThe adjBig nProblem? -- Alec Flett
|
------------------------------
Date: 9 Jul 2003 23:40:11 -0500
From: john62@electronmail.com
Subject: string question
Message-Id: <3f0cee2b$1_2@127.0.0.1>
i am a perl novice, and i have a really simple question.
what is the easiest way to tell if a string begins with "Re:
" (without the quotes)?
thx.
--------------------------------------------------------------------
For free web access to newsgroups, please visit
http://www.coldmail.us/. Thanks
--------------------------------------------------------------------
------------------------------
Date: Thu, 10 Jul 2003 01:18:09 -0500
From: "J. Smith" <charlie_baratski@yahoo.com>
Subject: Re: string question
Message-Id: <vgq18tb113gmf4@corp.supernews.com>
while($string =~ /^Re:/) {
print "$string contains \"$&\"\n";
# Do other stuff...
last;
}
<john62@electronmail.com> wrote in message news:3f0cee2b$1_2@127.0.0.1...
> i am a perl novice, and i have a really simple question.
> what is the easiest way to tell if a string begins with "Re:
> " (without the quotes)?
>
> thx.
>
>
>
>
> --------------------------------------------------------------------
> For free web access to newsgroups, please visit
> http://www.coldmail.us/. Thanks
> --------------------------------------------------------------------
------------------------------
Date: Thu, 10 Jul 2003 06:43:40 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: string question
Message-Id: <wW7Pa.39410$U23.8581@nwrdny01.gnilink.net>
J. Smith <charlie_baratski@yahoo.com> wrote:
[ TOFU patiently rearranged ]
> <john62@electronmail.com> wrote:
> > what is the easiest way to tell if a string begins with
> > "Re: " (without the quotes)?
> >
> while($string =~ /^Re:/) {
>
> print "$string contains \"$&\"\n";
> # Do other stuff...
>
> last;
>
> }
That's kind of bizarre. Why don't you just use "if"?
--
Steve :: "Save the Whiles"
------------------------------
Date: 10 Jul 2003 07:01:17 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: string question
Message-Id: <slrnbgq3pt.h76.sholden@flexal.cs.usyd.edu.au>
On Thu, 10 Jul 2003 01:18:09 -0500,
J. Smith <charlie_baratski@yahoo.com> wrote:
> while($string =~ /^Re:/) {
>
> print "$string contains \"$&\"\n";
> # Do other stuff...
>
> last;
>
> }
Why use "while/last" when you mean "if"?
Why use "$&" when by definition its value is "Re:"?
Especially considering the notes in the perlvar documentation
about this var.
TIMTOWTDI and all, that method is just madness.
Why use \" in a ""ed string, when you could use qq{} or similar?
snip TOFU - please don't do that.
--
Sam Holden
------------------------------
Date: 9 Jul 2003 21:13:42 -0700
From: genericax@hotmail.com (Sara)
Subject: Re: Total Butt Heads in this news group
Message-Id: <776e0325.0307092013.60abeb47@posting.google.com>
johndageek@yahoo.com (John D) wrote in message news:<c608545f.0307080945.48de471c@posting.google.com>...
> tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnbgk749.3f2.tadmc@magna.augustmail.com>...
> > Robert <yyyy@yyy.com> wrote:
> >
> > > Subject: Total Butt Heads in this news group
> >
> >
> > That is true.
> >
> > History has shown that you don't hang around here for long though.
>
>
> if this is going to be one of those entertaining flame wars, please
> refer to original post so the rest of us "Total Butt Heads" can see
> what we are being insulted/complimented for doing or not doing?
>
> Thanks in advance for your help ;}
> JD
Not to disparage any Butthead fans out there, but if you do that,
please include "Total Beavis" as well. He's actually my favorite of
the two..
Gx
------------------------------
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.
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 V10 Issue 5208
***************************************