[24969] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 7219 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 7 11:07:20 2004

Date: Thu, 7 Oct 2004 08:05:07 -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, 7 Oct 2004     Volume: 10 Number: 7219

Today's topics:
        GD::Graph - Can it create a stock chart <jarsonk@nospam.com>
    Re: GD::Graph - Can it create a stock chart <nospam@bigpond.com>
    Re: How to prevent the removal of \ from pairs of \\? <tadmc@augustmail.com>
    Re: Is PHP still slower than Perl? <postmaster@castleamber.com>
        Module::Install (Trime)
    Re: Regex gurus question <someone@example.com>
    Re: second question today. eak. use array, hash or somt <mritty@gmail.com>
        Storable.pm size limit? <karlUNDERSCOREkramsch@yahooPERIODcom.invalid>
    Re: Top 10 list algorithm <fatted@gmail.com>
    Re: Top 10 list algorithm <postmaster@castleamber.com>
    Re: Top 10 list algorithm <someone@example.com>
    Re: Top 10 list algorithm <fatted@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 7 Oct 2004 09:42:02 -0400
From: "Jarson" <jarsonk@nospam.com>
Subject: GD::Graph - Can it create a stock chart
Message-Id: <LIb9d.31745$HO1.1234831@news20.bellglobal.com>

I would like to know if GD::Graph can be used to create a "Stock Chart". 
This is a series of lines with three data points representing the 
high/low/close. Perhaps there is a more correct name for this type of chart, 
but it is referred to this in MS Excel.  My application is NOT for tracking 
stocks, and I will use it for the high/low/average for several days.

Thanks,
Jarson (jarson) from Sygration.
That's a dot com company (you can figure out the e-mail address if needed).





------------------------------

Date: Fri, 08 Oct 2004 01:03:31 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: GD::Graph - Can it create a stock chart
Message-Id: <2sl464F1m4qf8U1@uni-berlin.de>

Jarson wrote:

> I would like to know if GD::Graph can be used to create a "Stock Chart".
> This is a series of lines with three data points representing the
> high/low/close. Perhaps there is a more correct name for this type of
> chart,
> but it is referred to this in MS Excel.  My application is NOT for
> tracking stocks, and I will use it for the high/low/average for several
> days.

Yes. In fact many online charting applications use Perl.

http://ipo-australia.com/scgi-bin/beta/graph.cgi?graph=XAO_year_550x350
(This uses plain GD & is not in production yet).

gtoomey


------------------------------

Date: Thu, 7 Oct 2004 09:11:15 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: How to prevent the removal of \ from pairs of \\?
Message-Id: <slrncmajk3.akq.tadmc@magna.augustmail.com>

Bernie Cosell <bernie@fantasyfarm.com> wrote:
> Uri Guttman <uri@stemsystems.com> wrote:
> 
>} >>>>> "PL" == Paul Lalli <mritty@gmail.com> writes:
> 
> }   PL> Note that I don't especially understand why this works.  Why would
> }   PL> single-quoted heredocs not work the same as 'normal' single-quoted
> }   PL> strings?
> } 
> } because in single quoted strings \ is needed to escape ' and \. 


> Why does that apply if you use 'q' with an explicit terminator?  


For the same reason as when using single quotes, to escape the terminator.


> Is there a need to scan for '\' if
> I'm doing:  q{stuff} ?


Yes, as you might need a

   \}

in there somewhere.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: 7 Oct 2004 13:54:18 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Is PHP still slower than Perl?
Message-Id: <Xns957B5A956333Fcastleamber@130.133.1.4>

"Tony Marston" <tony@NOSPAM.demon.co.uk> wrote in
> "John Bokma" <postmaster@castleamber.com> wrote in message 

[ snip ]

>>> People should always be writing wrapper functions or classes to
>>> handle db connections, to remove such stuff as addslashes()ing. Use
>>> func_num_args() to find out the number of arguments passed to a php
>>> function and func_get_arg([number]) to get the [number]th argument
>>> passed. I've written such a function for myself.
>>
>> Yes, and everybody has to write wrapper functions. You get the point
>> now, or do you want it spelled out?
> 
> But different developers will write wrapper functions in different
> ways. Whish one should I choose? Why?

The one that solves your problem the most efficient.

Imagine everybody writing wrapper functions all the time instead of 
doing real work...

>> Yes, in Perl that is called DBI. You don't have to write it yourself.
> 
> Yes, but what happens if I don't like the way it works?

In that rare case you can write a wrapper, and make it available on 
CPAN. 

>> Programming shouldn't be about reinventing wheels, and worse
>> reinventing bugs.
> 
> But it is about reinventing wheels. A pram wheel is no good for a
> sports car, so you have to invent one that works under those
> circumstances.

If you want to screw something in the wall, do you make your own custom 
screws or do you go to the hardware store?

> I have stopped using other people's solutions for the following
> reasons: (a) There are too many solutions from too many people. The
> people have various skill levels (from pathetic to passable), and the
> solutions are tailored for specific purposes.

With PHP, Perl or in general?

> (b) It takes too much time to go though all the possible solutions to
> find one that is applicable to the problem in hind. I find it much
> quicker to use my decades of experience in devising my own solution.

I use my decades of experience to select a library or module, or consult 
the right people. It has always saved me a lot of time and trouble.

-- 
John                               MexIT: http://johnbokma.com/mexit/
                           personal page:       http://johnbokma.com/
        Experienced programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html


------------------------------

Date: 7 Oct 2004 07:34:07 -0700
From: trime4you@yahoo.com (Trime)
Subject: Module::Install
Message-Id: <12363781.0410070634.f5a7bb7@posting.google.com>

Hi,
I'm trying to use Module install for installing some dependencies that
I don't want the users of the module to have.  On my side when I do
perl Makefile.PL it
goes over to CPAN and downloads all my bundle requirements.  
I'm using the bundle_deps() defined in Module::Install::bundle but on
the client side it doesn't do anything with the dependencies that are
in the inc/
directory. 

Is there anyone here that has made it work.  My Makefile.PL has
nothing besides
some basic Module (name, license ...) and few bundle_deps().  

Please help.

Thanks


------------------------------

Date: Thu, 07 Oct 2004 13:14:05 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Regex gurus question
Message-Id: <xib9d.39064$223.10796@edtnps89>

Shawn Corey wrote:
> Eric Bohlman wrote:
> 
>> The philosophy of "defensive programming" suggests that you should write
>>
>> ($justTheNumbers) = $test =~ /^[[:alpha:]](/d+)$/ or die "unexpected 
>> format in \$test: [$test]";
>>
>> It may *look* like a lot of extra effort, but scores of programmers 
>> have found that the few extra minutes of coding that such techniques 
>> entail saved them many *hours* of time wasted tracking down subtle bugs.
> 
> I guess I'm a sloppy programmer. I would have written it as:
> 
> ( my $just_digits = $test ) =~ s/\D//g;

That will work fine if the OP's actual data is the same as the example he 
presented ($test = "x12345";) however if the actual data looks something like 
"x12345 y12345 z12345" then that will not produce a correct result.


John
-- 
use Perl;
program
fulfillment


------------------------------

Date: Thu, 07 Oct 2004 13:25:27 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: second question today. eak. use array, hash or somthing else?
Message-Id: <btb9d.1375$sa.198@trndny07>

"Dan Vesma" <daninbrum@hotmail.com> wrote in message
news:14c7b35.0410070431.182e4ec0@posting.google.com...

> Which brings me to 3d arrays... I can't for the life of me work out
> how to sort them. I've looked at PerlFAQ and perdoc perllol, but
> appear not to be able to find a solution. Is my brain just feeble?
>
> This is obviously linchpin to the whole bloomin' thing. I've been
> thinking for hours trying to work out code to sort a 3D array, but
> can't do it.

What have you tried so far, what didn't work?

> Arg! This must have been done before. I take it that you
> can't sort a hash of arrays by one of the array values!?!

A hash of arrays is not a 3D array.  Which structure are you actually
using?

#!/usr/bin/perl
#HASH OF ARRAYS
use strict;
use warnings;
my %HoA = (
     'foo' => [qw/1 gamma M/],
     'bar' => [qw/4 alpha Z/],
     'baz' => [qw/2 omega A/],
);

#In each of these sort routines, $a and $b are
#keys of the hash.  The values of the hash
#are array references.
#$HoA{$a}[0] could be more explicitly written
#as $HoA{$a}->[0]
sub by_num {
  $HoA{$a}[0] <=> $HoA{$b}[0]
}

sub by_greek {
  $HoA{$a}[1] cmp $HoA{$b}[1]
}

sub by_let {
  $HoA{$a}[2] cmp $HoA{$b}[2]
}

foreach my $order (\&by_num, \&by_greek, \&by_let){
  foreach my $key (sort $order keys %HoA){
    print "$key: @{$HoA{$key}}\n";
  }
  print "\n";
}
__END__

#!/usr/bin/perl
use strict;
use warnings;
#3D ARRAY
my @ThreeD = (
              [
               [qw/A1a A1b A1c/],
               [qw/A2a A2b A2c/],
               [qw/A3a A3b A3c/],
              ],
              [
               [qw/B1a B1b B1c/],
               [qw/B2a B2b B2c/],
               [qw/B3a B3b B3c/],
              ],
              [
               [qw/C1a C1b C1c/],
               [qw/C2a C2b C2c/],
               [qw/C3a C3b C3c/],
              ],
             );

#In this sort routine, $a and $b will be two members
#of @ThreeD, that is, two arrayrefs.
#$a->[1] is the 2nd element of the array referenced by $a,
#and $a->[1][1] is the 2nd element of the array referenced by $a->[1]
sub by_center {
  $a->[1][1] cmp $b->[1][1];
}

foreach my $plane (sort by_center @ThreeD){
  foreach my $row (@$plane){
    print "@$row\n";
  }
  print "\n";
}
#Here, I visualize the array as a cube, and assume you want to sort
#each 'layer' of the cube by their center elements
#This actually isn't an especially good example, because the elements
#are already sorted.  I'm hoping you can extrapolate.
__END__


Hope you find this useful,
Paul Lalli




------------------------------

Date: Wed, 6 Oct 2004 14:52:41 +0000 (UTC)
From: KKramsch <karlUNDERSCOREkramsch@yahooPERIODcom.invalid>
Subject: Storable.pm size limit?
Message-Id: <ck10rp$mdr$1@reader2.panix.com>



  I'm running a script that builds a hash over time, and periodically
saves it using Storable.  I use a command-line Perl one-liner to
check the number of keys in the hash so far:

  perl -MStorable -e '$h = retrieve "mongo"; printf "%d\n", scalar keys %$h'

  As of 6 pm last night the one-liner above would print a positive
integer, increasing with every invocation (as expected), but this
morning (the script has been running all night and it's still
running now) the one-liner prints 0.  In fact, another one-liner
reveals that the result of the call to retrieve is now undefined.
The file in question is now 33 MB (and growing).  Is there a limit
on the size of an object stored with Storable?

  I don't understand why the retrieve operation is now failing,
but from looking at the file with a text editor I can see that
there's a *ton* of valuable info in the file that I'd hate to lose.
Is there any way to recover it?  Is there a way to truncate the
file to retrieve at least a subset of the keys with their associated
values?

  Thanks!

	Karl


-- 
Sent from a spam-bucket account; I check it once in a blue moon.  If
you still want to e-mail me, cut out the extension from my address,
and make the obvious substitutions on what's left.


------------------------------

Date: Thu, 07 Oct 2004 15:41:02 +0200
From: Fatted <fatted@gmail.com>
Subject: Re: Top 10 list algorithm
Message-Id: <2skvbeF1ivps9U1@uni-berlin.de>

Anno Siegel wrote:
> Fatted  <fatted@gmail.com> wrote in comp.lang.perl.misc:
> 
>>Is there a better (faster) way of implementing my top_sort function? 
>>(Creating a top 10 list of the highest numbers from a large set).
>>Or did I get lucky? :)
> 
> 
> The standard approach to selection of the top k of n elements is
> to use a heap.
> 

<snip>

 > If n is much larger than k, you can even use a simple list instead
 > of a heap. You either sort it after each insertion, or insert each
> element in its place (straight insertion sort).

What do you mean by a straight insertion sort?

(Thanks for explanation by the way).


------------------------------

Date: 7 Oct 2004 13:59:42 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Top 10 list algorithm
Message-Id: <Xns957B5B7F277A6castleamber@130.133.1.4>

Fatted <fatted@gmail.com> wrote in news:2skvbeF1ivps9U1@uni-berlin.de:

> Anno Siegel wrote:
>> Fatted  <fatted@gmail.com> wrote in comp.lang.perl.misc:
>> 
>>>Is there a better (faster) way of implementing my top_sort function? 
>>>(Creating a top 10 list of the highest numbers from a large set).
>>>Or did I get lucky? :)
>> 
>> 
>> The standard approach to selection of the top k of n elements is
>> to use a heap.
>> 
> 
> <snip>
> 
> > If n is much larger than k, you can even use a simple list instead
> > of a heap. You either sort it after each insertion, or insert each
>> element in its place (straight insertion sort).
> 
> What do you mean by a straight insertion sort?

Since the list is sorted (because you insert in the right place) you can 
use binary search to find the elements location, O(log k), and insert it.

Or I am wrong :-)


-- 
John                               MexIT: http://johnbokma.com/mexit/
                           personal page:       http://johnbokma.com/
        Experienced programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html


------------------------------

Date: Thu, 07 Oct 2004 14:44:44 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Top 10 list algorithm
Message-Id: <wDc9d.39383$223.9122@edtnps89>

Fatted wrote:
> Is there a better (faster) way of implementing my top_sort function? 
> (Creating a top 10 list of the highest numbers from a large set).
> Or did I get lucky? :)
> 
> -- 
> #!/usr/bin/perl
> use strict;
> use warnings;
> 
> my @top10 = (0,0,0,0,0,0,0,0,0,0);
> 
> for(my $i = 0;$i < 10000; $i++)
> {
>     my $num = rand();
>     @top10 = @{top_sort(\@top10, $num)};
> }
> 
> # PRINT RESULTS
> foreach (@top10)
> {
>         print $_."\n";
> }
> 
> sub top_sort
> {
>     my $array = shift;
>     my $val = shift;
> 
>     my @top;
> 
>     # IF THE VALUE IS LESS THAN THE LAST VALUE IN THE TOP LIST,
>     # NO PROCESSING REQUIRED
>     if(defined($val) && $val >= 0)
>     {
>         if($val < $array->[$#$array])
>         {
>             return($array);
>         }
>     }
> 
>     for(my $i = 0; $i < $#$array; ++$i)
>     {
>         if($val > $array->[$i])
>         {
>             # MAKE NEW TOP10 BY TAKING HIGHER MATCHES PLUS THE NEW
>             # VALUE, PLUS THE LOWER MATCHES UP TO THE LIMIT OF THE
>             # ARRAY.
>             @top = @$array[0..($i-1)];
>             push(@top, $val);
>             push(@top, @$array[$i..($#$array-1)]);
>             last;
>         }
>     }

Your algorithm is flawed because you don't compare $val to the last element of 
@$array so under certain conditions the last element of @top will be incorrect.

What's that saying about premature optimization?  :-)

>     # IN CASE OF PROBLEMS
>     if(!defined($top[0]))
>     {
>         @top = @$array;
>     }
>     return(\@top);
> }


John
-- 
use Perl;
program
fulfillment


------------------------------

Date: Thu, 07 Oct 2004 16:59:11 +0200
From: Fatted <fatted@gmail.com>
Subject: Re: Top 10 list algorithm
Message-Id: <2sl3tvF1mmv1nU1@uni-berlin.de>

John W. Krahn wrote:
> Fatted wrote:
> 
>> Is there a better (faster) way of implementing my top_sort function? 
>> (Creating a top 10 list of the highest numbers from a large set).
>> Or did I get lucky? :)
> 
> Your algorithm is flawed because you don't compare $val to the last 
> element of @$array so under certain conditions the last element of @top 
> will be incorrect.

Yeah, good spot. I created the above as a simplification of some of my 
code for comments in c.l.p.m. Kinda got carried away with the 
simplification...

> 
> What's that saying about premature optimization?  :-)
> 

But it would be faster :)
 .
 .

:(


------------------------------

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 V10 Issue 7219
***************************************


home help back first fref pref prev next nref lref last post