Modify $0 in Perl embedded in C

2004-05-21 Thread JupiterHost.Net
Hello group!
Maybe a bit much for a beginners list (I looked and looked and couldn't 
find any specific lists) but Perhaps a guru or two will know the answer :)

I've been playing with embedding Perl code into a C program that can
interpret the code.
 (as per http://www-h.eng.cam.ac.uk/help/mjg17/perldoc/pod/perlembed.html
http://search.cpan.org/~krishpl/pod2texi-0.1/perlembed.pod
http://search.cpan.org/~nwclark/perl-5.8.4/pod/perlembed.pod
)
This example works great: (I realize @ARGV is clobbered but that isn't 
the point right now, its for another sleepless night ;p)

  (compiled with: gcc -o compiled_version simple.c `perl
-MExtUtils::Embed -e ccopts -e ldopts`)
#include 
#include 
static PerlInterpreter *my_perl;
main (int argc, char **argv, char **env)
{
char *embedding[] = { "", "-e", "0" };
my_perl = perl_alloc();
perl_construct(my_perl);
perl_parse(my_perl, NULL, 3, embedding, NULL);
perl_run(my_perl);
perl_eval_pv("print qq(Hello World - I come from the planet
C and i am -$0-\n);", TRUE);
perl_destruct(my_perl);
perl_free(my_perl);
}
But the problems I've found is:
 1) $0 is -e since we're not making just another copy of perl but
running internal code internally by specifying -e
   1.a) If I change -e to the file name (IE C's argv[0]), it errors out 
because it tries to open the file to execute as perl code like doing 
perl file.pl
   1.b) If i try to set $0 myself I get a bus error (Try it :add $0 =
'actual_file.name';) Which, while a bad idea generally, still works with
regular Perl.

#include 
#include 
static PerlInterpreter *my_perl;
main (int argc, char **argv, char **env)
{
char *embedding[] = { "", "-e", "0" };
my_perl = perl_alloc();
perl_construct(my_perl);
perl_parse(my_perl, NULL, 3, embedding, NULL);
perl_run(my_perl);
perl_eval_pv("print qq(Zero is -$0-\n);$0 =
'realnamefromargv[0]here';print qq(Zero is -$0-\n);", TRUE);
perl_destruct(my_perl);
perl_free(my_perl);
}
So does anyone have any insigth as to why it flops and/or how to set $0 
with another value in those examples?

TIA
Lee.M - JupiterHost.Net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



help with Expect

2004-05-21 Thread Yi Chu
Does anyone know the mailing list for beginners for Expect?  Or some of you may know 
the answer to my question, I just ask the question here.
 
How to send function key in Expect program?
 
Example:
send "Tab()\r"
would send the tab character.  But how to send in F5 key?
 
Tried 
send "PF5()\r"
with no luck.
 
Apologize for asking non-perl question, but I just can not find a good mailing list 
for Expect.  Had good experiences with perl list, so try my luck here.
 
yi


-
Do you Yahoo!?
Yahoo! Domains - Claim yours for only $14.70/year

Re: array output

2004-05-21 Thread Paul D. Kraus
Not completely sure what you are trying to do but you can join all the
elements like this 

my $mystring = join " ", @myarray;
this will join each elements into one string seperated by a space. 

Paul
On Fri, May 21, 2004 at 02:07:56PM -0400, [EMAIL PROTECTED] wrote:
> All, 
> 
> I have an array of 40 elements and I want to run a system app command 
> against all the elements simultaneously ...well not line by line as in a 
> for loop.
> I have tried 
> 
> 
> does anyone know how to spit out all 40 elements so the app command does 
> not eject tapes one by one?
> thanks
> 
> Derek B. Smith
> OhioHealth IT
> UNIX / TSM / EDM Teams
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




array output

2004-05-21 Thread DBSMITH
All, 

I have an array of 40 elements and I want to run a system app command 
against all the elements simultaneously ...well not line by line as in a 
for loop.
I have tried 


does anyone know how to spit out all 40 elements so the app command does 
not eject tapes one by one?
thanks

Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams



Re: excel

2004-05-21 Thread Jeff Westman
I just did this in fact using CSV.pm, worked great!  See:

http://search.cpan.org/~alancitt/Text-CSV-0.01/CSV.pm




--- "DiGregorio, Dave" <[EMAIL PROTECTED]> wrote:
> Does anyone know, what is the best way to retrieve text data from
> an Excel
> Spreadsheet?  I have tried the code below and it returns errors. 
> I can not
> even get the name of the file to print!
> 
>  
> 
>  
> 
>  
> 
> #! usr/bin/perl -w
> 
>  
> 
> use strict ;
> 
> use Spreadsheet::ParseExcel ;
> 
> my $oExcel = new Spreadsheet::ParseExcel::Workbook ;
> 
>  
> 
> my $oBook = $oExcel->Parse('Excel/Test.xls') ;
> 
>  
> 
> print "File   :" , $oBook->{File} , "\n" ; 
> 
> print "Count  :" , $oBook->{SheetCount} , "\n" ; 
> 
> print "Author :" , $oBook->{Author} , "\n" ;
> 
> I
> 
>  
> 
> Thanks
> 
>  
> 
> David 
> 
> 





__
Do you Yahoo!?
Yahoo! Domains – Claim yours for only $14.70/year
http://smallbusiness.promotions.yahoo.com/offer 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Net::Google

2004-05-21 Thread Mandar Rahurkar
How do I make a force install using mcpan ?

Thanks
Mandar

 Original message 
>Date: Fri, 21 May 2004 15:04:10 +1000 (EST)
>From: Owen Cook <[EMAIL PROTECTED]>  
>Subject: Re: Net::Google  
>To: [EMAIL PROTECTED]
>
>
>On Thu, 20 May 2004, Mandar Rahurkar wrote:
>
>> I am trying to install the net::google module in order to use the google api 
>> however I get following error:
>> 
>> 
>> Failed Test  Stat Wstat Total Fail  Failed  List of Failed
>> ---
>> t/002-spelling.t1   256 51  20.00%  5
>> Failed 1/4 test scripts, 75.00% okay. 1/18 subtests failed, 94.44% okay.
>> make: *** [test_dynamic] Error 29
>>  /usr/bin/make test -- NOT OK
>> Running make install
>>  make test had returned bad status, won't install without force
>> 
>> I am using mcpan to install the modules...whats wrong ?? :(
>
>
>If you read the doco you will see that the TODO has some refinement for
>the those without Test::Make(I think) 
>
>Just force install and see what happens
>
>
>Owen
>
>
>-- 
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
> 
>
>
---
Mandar Rahurkar
ECE,   UIUC
---

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: A MySQL Question

2004-05-21 Thread Rob Dixon
Lrmk wrote:
>
> I am developing a web site traffic rating system. using a combination og
> perl and java (PERL in serverside, Java Applets in cliend side - My attempt
> to create dynamic images was not that successfull so I use a java applet to
> view the rating info on the site)
>
> Here is my question The rating system is now working but every day I have to
> run a hevy SQL statement to recalculate the traffic ranks of web sites
>
>
> Something similer to this
>
> $DBC is the connection to the mysql database
>
> my $q = $DBC->prepare("
>   SELECT
> domainname,
> (viewcount/(($now - startedTime)/86400)) AS views_per_day
>   FROM site
>   WHERE startedTime < ($now - 48hours)
>   ORDER BY views_per_day
>   DESC
>  ")
>
> my $rank = 0;
>
> $q->execute();
>
> while (my $ref = $q->fetchrow_hashref()){
> $rank++;
> my %hash = %{$ref};
> $DBC->do("UPDATE site SET rank = $rank WHERE domainname=" .
> $DBC->quote($hash{'domainname'}));
>
> }
>
> $q->finish();
>
> $DBC->do("COMMIT");
>
>
>
>
> the problem is if there are 1500 qualified records in the table there going
> to 1501 queries (there going to be lots mor records than 1500 in the real
> system)
>
> Question 1 ) Is there a more efficiant way of doing this, atleast to reduce
> the number of queries?
>
> I know if I use Oracle db i can make a PL/SQL procedure but my web host only
> give MySql
>
> Question 2 ) Can I make functions with mySQL if yes where can I find a
> tutorial?

Hi.

I would keep the rank values in a separate table with just two columns: the
domain name and its rank. You could obviously pretend that it's part of the
main table by setting up a view. The all you need to do is

  INSERT INTO rank (domainname, rank)
  VALUES ($domainname, $rank)
  ON DUPLICATE KEY UPDATE rank = $rank

As for the functions,take a look here:

  http://dev.mysql.com/doc/mysql/en/CREATE_FUNCTION.html

HTH,

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Using SCP and CGI

2004-05-21 Thread John Pretti
All,
 
I have been assigned the task of promoting files from one server to another.
I have broken this down into two components: file upload and then the actual
file promotion. I have a great upload script that I have developed with you
all's assistance but now I am kind of stuck. Basically I have a form
generated by CGI that will prompt the user for a directory selection and
when they press the Promote button it would copy the files from the local
server to a specific directory on three remote servers. I understand what I
need to do and the components that I want to use (Net::SCP), but I still am
having trouble understanding the logic and what the best way to do it would
be. Any help would be greatly appreciated. The code that I have is listed
below:
 
#!/usr/bin/perl -w
 
# perlPromote.cgi by John Pretti
# Comments/Questions john[at]web-connected.com
# Last modified 05/17/04
 
# Load needed Perl modules
use strict;
use diagnostics;
use CGI; #Make HTML east to deal with
use CGI::Carp 'fatalsToBrowser'; # Report errors to Browser
 
# Promotion directories
my @rem_hosts = ('x.x.x.x', 'y.y.y.y', 'z.z.z.z');
$working_dir = "/home/rdwebadmin/support_docs";
my @rem_dirs = ('HW', 'NW', 'SW');
my @sub_rem_dirs = ('/SW/Unifi', '/SW/MFIS', '/SW/WEBCAAF_eforms');
 
# Create New CGI Object
my $q = new CGI;
 
my %label = ('hw'=>'..support_docs/HW',
 'nw'=>'..support_docs/NW',
 'sw'=>'..support_docs/SW',
 'swmfis'=>'..support_docs/SW/MFIS',
 'swunifi'=>'..support_docs/SW/Unifi',
 'swwebcaaf'=>'..support_docs/SW/WEBCAAF_eforms');
 
print   $q->header,
$q->start_html,
$q->br,
$q->start_multipart_form,
$q->p("Select a  promotion directory:"),
$q->radio_group (
-name=>'promdir',
-values=>
['hw','nw','sw','swmfis','swunifi','swwebcaaf'],
-labels=>\%label,
-default=>'selected',
-linebreak=>'true'),
$q->br,
$q->submit('Promote'),
$q->end_form,
$q->end_html;
 
Thanks in advance. I am slowly starting to understand some of this.
 
John


Re: pointer to another list?

2004-05-21 Thread JupiterHost.Net

Jose Alves de Castro wrote:
For a list of lists, you might want to try http://lists.perl.org/
First place I went and none of them seemd to be about it :)
On Thu, 2004-05-20 at 18:58, JupiterHost.Net wrote:
Hello group!
Anyone have any idea of a mailing list or more resources about embedding 
Perl in C like is discussed here:
 http://www-h.eng.cam.ac.uk/help/mjg17/perldoc/pod/perlembed.html)

TIA
Lee.M -JupiterHost.Net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: perlglob on Windows platform

2004-05-21 Thread Satya_Devarakonda
Thank you sir,

I corrected my code.

Regards,
satya




"John W. Krahn" <[EMAIL PROTECTED]>
05/20/2004 05:28 PM

 
To: [EMAIL PROTECTED]
cc: (bcc: Satya Devarakonda/HAM/AM/HONDA)
Subject:Re: perlglob on Windows platform


Satya Devarakonda wrote:
> 
> Hi,

Hello,

> I am trying to delete zero byte files using the following code:
> 
> for ($i=0; $i<[EMAIL PROTECTED];$i++) {
   ^^
You are accessing a nonexistent element of the array.  If your array
contains ten elements then that will also use the eleventh element.  Why
not just loop over the elements of the array itself instead of using an
index variable?  If you really need an index variable then the perlish
way to do it is:

for my $i ( 0 .. $#filelst ) {


> $filelst[$i] =~ s/\s//;

You are removing a single whitespace character from the variable
$filelst[$i].  Is that what you really want to do?


> #Process creates zero byte file if nothing was found in
> the mailbox
> #Hence delete zero byte files
> if ( -z "$indir\\${filelst[$i]}" )
> {
> print " $indir\\$filelst[$i] \n";
> unlink <"$indir\\$filelst[$i]">;

You are enclosing "$indir\\$filelst[$i]" in <> which is a fileglob.  You
can also use / instead of \\ for path separators.

if ( -z "$indir/$filelst[$i]" )
{
print " $indir/$filelst[$i]\n";
unlink "$indir/$filelst[$i]";


> next;
> }..


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 






ref(Total newbiesh5) and XML::Simple and pseudo-hashes rhapsody ;

2004-05-21 Thread Etienne Robillard
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Hi,
Here's my first post on this list :)
For fun, I did a small TODO file in XML and then im attempting to,
err, read from it via XML::Simple (and XML::Parser).
the docs in XML::Simple says that it is possible to
reach objects in such a way:
print $foo->{ bar }->{ baz }->[1];
The assumption I made is that 'bar' and 'baz' meant different
'structures' inside the XML file.
I would love to do just that :)
But things seems not so clever, so I get something like:
none>perl test-xml.pl
Pseudo-hashes are deprecated at test-xml.pl line 10.
Out of memory during "large" request for 1073745920 bytes, total
sbrk() is 2957312 bytes at test-xml.pl line 10.
Perhaps the latter error message is void, simply because my system
limits (FreeBSD) are wrongly tuned.. However, the pseudo-hashes thingie
is quite a medium-pita for my humble knowledge :)
Is their a relative explanation for this behavior ?
Moreover, if I do the DUmper($thingie) shrub, its works and gives back
the structure I wants.
Here's the 'whole' source of it:
#!/usr/bin/perl -w
use strict;
use XML::Simple qw(:strict);
use Data::Dumper;
my $xml_file = '/home/erob/dev/perl/TODO.pietra.xml';
my $in = XMLin( $xml_file,  ForceArray  =>  1, KeyAttr  =>  [ ],  );
print $in->{ require }->{ item }->[1];
#print Dumper($in);
1;
some more snippets of schwig:
perl --version:
none>perl --version
This is perl, v5.8.2 built for i386-freebsd
Copyright 1987-2003, Larry Wall
Perl may be copied only under the terms of either the Artistic License
or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'.  If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.
p.s
Btw, I DO love perl5 very much.
For me, it's (perl) very much like a soup (err, is that self, or is that
my visual representation is so sluggish that I need some kind of visual
paradigm for it .)
I was wondering how perl6 would be, since it can't() be soup-like ?
Thanks and happy perlesh (pronounced something like 'eash') :)
erob
-BEGIN PGP SIGNATURE-
Comment: quork teht!
iD8DBQFAredlfhO/J4JSDfYRAq6yAJ4kPymzkbKRAl3tjPTO6DXBzuLYZACeNupa
E1NmW3s7iJnQCkEqtWZzCQ8=
=VOvA
-END PGP SIGNATURE-
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: matrix solving

2004-05-21 Thread Jose Alves de Castro
Try using Math::Matrix (you can find it on CPAN)


On Fri, 2004-05-21 at 11:18, Boon Chong Ang wrote:
> Hi,
> I want to use perl to do the matrix solving such as matrix inversion and and matrix 
> multiplication, matrix addition and matrix substraction. However, i have no idea how 
> to do it in perl. Any there anyone who can give me some suggestion how to solve this?
>  
> 
> Thank you & best regards,
> 
> ABC
> 
>  
-- 
Josà Alves de Castro <[EMAIL PROTECTED]>
Telbit - Tecnologias de InformaÃÃo


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




matrix solving

2004-05-21 Thread Boon Chong Ang
Hi,
I want to use perl to do the matrix solving such as matrix inversion and and matrix 
multiplication, matrix addition and matrix substraction. However, i have no idea how 
to do it in perl. Any there anyone who can give me some suggestion how to solve this?
 

Thank you & best regards,

ABC

 

 


Re: pointer to another list?

2004-05-21 Thread Jose Alves de Castro

For a list of lists, you might want to try http://lists.perl.org/


On Thu, 2004-05-20 at 18:58, JupiterHost.Net wrote:
> Hello group!
> 
> Anyone have any idea of a mailing list or more resources about embedding 
> Perl in C like is discussed here:
>   http://www-h.eng.cam.ac.uk/help/mjg17/perldoc/pod/perlembed.html)
> 
> TIA
> 
> Lee.M -JupiterHost.Net
-- 
Josà Alves de Castro <[EMAIL PROTECTED]>
Telbit - Tecnologias de InformaÃÃo


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: regex alternation question

2004-05-21 Thread Jose Alves de Castro
On Thu, 2004-05-20 at 21:22, Rich Fernandez wrote:
> I'm unclear about how alternation works in a regex.
>  
> Say I want to find either "foo" or "bar" within a string. I don't care which
> one I match, only that I make a match.
> Would this be correct:  /foo|bar/
>  
> Should they be grouped thusly: /(foo|bar)/
>  
> What about /(?:foo|bar)/   ?
>  
> Specifically, I know that the second one remembers which one is found and
> the third one doesn't. But is the first example wrong? 


The first one also remembers what is found. It's the variable $&
 

> TIA
>  
> richf
-- 
Josà Alves de Castro <[EMAIL PROTECTED]>
Telbit - Tecnologias de InformaÃÃo


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: combining data from more than one file...

2004-05-21 Thread philipp traeder
On Wednesday 19 May 2004 05:25 pm, Michael Robeson wrote:
> Sorry, I meant to upload this script (see below). However, I have one
> last question. Why can't I use
>
> s/\n//g;# instead of
>
> tr/A-Za-z-//cd;
>
>
>
> in the script below? I thought it would be simpler to remove the
> newline characters from $_ which is all I really want to do. However,
> most of the time all I will see are "-" and letters which is why I set
> the tr function the way I did.

Hi Mike,

I'm not sure if I understand exactly what you want to do here, but if you want 
to remove trailing newlines only, I'd use 
chomp;

>
> I just couldn't figure out why the substitution function wouldn't work
> in this case. How am I setting it up wrong?

Just guessing - could it be that you need to assign the return value of s///?
Something like
  my $var_without_newlines = s/\n//g;
?

HTH,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Array with unique elements only

2004-05-21 Thread Mark Martin
Thanks Ramprasad - that works.
At 17:29 20/05/2004 +0530, Ramprasad A Padmanabhan wrote:
Wow,
unique items is surely an FAQ.
But here you dont need to filter the array, just see the answer inline
On Thu, 2004-05-20 at 17:07, Mark Martin wrote:
> Hi,
> I'm moving database data from table to table and want to make sure I'm
> getting only unique records.
>
> Only want unique $field1 and was looking at the cookbook code, but for 
that
> I have to populate a hash and then re-inspect through before inserting
> uniques, something like :
>
> %ucnt = ();
> while (my @row = $sth->fetchrow) {
>
>   $field1 = $row[0];
>   push(@list,$field1 );
>   $ucnt{$_}++;
>   $field2 = $row[3];
> }
>

Change that to
%ucnt = ();
while (my @row = $sth->fetchrow) {
$field1 = $row[0];
push(@list,$field1 );
$field2 = $row[3];
next if($ucnt{$_}++);
POPULATE TABLE ...
}
> Surely I can avoid the "foreach" and inspect $field1 in the while loop for
> uniqueness before pushing it to an array.
>
> Cheers,
> Mark
>

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: A MySQL Question

2004-05-21 Thread Dani Pardo
On Fri, 21 May 2004, LRMK wrote:

> I dont like to remove the RANK field onless there is no other solution
> becouse this Rating system going to be used by a community of people to
> messure the performance of their web sites compaired to others the RANK must
> be there.
>
> I am thinking about calculating RANK once  a more longer interval like once
> a 7 days.
>
>
> This method of updating will be bit faster if there is a way i  can write
> this as a function in the DBMS  "Like a PL/SQL Function in Oracle" is this
> possible in MySQL
>

  You can use CREATE FUNCTION. But these functions are created in C (i
guess), and are compiled in a dynamic library (.so) into mysql.

---
Dani Pardo, [EMAIL PROTECTED]
Enplater S.A

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: A MySQL Question

2004-05-21 Thread LRMK
I dont like to remove the RANK field onless there is no other solution
becouse this Rating system going to be used by a community of people to
messure the performance of their web sites compaired to others the RANK must
be there.

I am thinking about calculating RANK once  a more longer interval like once
a 7 days.


This method of updating will be bit faster if there is a way i  can write
this as a function in the DBMS  "Like a PL/SQL Function in Oracle" is this
possible in MySQL



Rakhitha Karunarathne
Web Master
www.Ad-Man.tk - Free Unlimited Banner Rotators




- Original Message - 
From: "Dani Pardo" <[EMAIL PROTECTED]>
To: "LRMK" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Friday, May 21, 2004 1:06 PM
Subject: Re: A MySQL Question


> On Fri, 21 May 2004, LRMK wrote:
>
> > Probably this is not relavent to this mailing list... But any way I ll
ask..
> >
> > I am developing a web site traffic rating system. using a combination og
> > perl and java (PERL in serverside, Java Applets in cliend side - My
attempt
> > to create dynamic images was not that successfull so I use a java applet
to
> > view the rating info on the site)
> >
> > Here is my question The rating system is now working but every day I
have to
> > run a hevy SQL statement to recalculate the traffic ranks of web sites
> >
> > Something similer to this
> >
> > $DBC is the connection to the mysql database
> >
> >
> > my $q = $DBC->prepare("SELECT domainname, (viewcount/(($now -
> > startedTime)/86400)) AS views_per_day " .
> > "FROM site WHERE
startedTime<($now -
> > 48hours) " .  # I do not give ranks for the sites registered withing
> > last 48 hours
> > "ORDER BY views_per_day DESC")
> >
> > my $rank = 0;
> >
> > $q->execute();
> >
> > while (my $ref = $q->fetchrow_hashref()){
> > $rank++;
> > my %hash = %{$ref};
> > $DBC->do("UPDATE site SET rank = $rank WHERE domainname=" .
> > $DBC->quote($hash{'domainname'}));
> >
> > }
> >
> > $q->finish();
> >
> > $DBC->do("COMMIT");
> >
> >
> >
> >
> > the problem is if there are 1500 qualified records in the table there
going
> > to 1501 queries (there going to be lots mor records than 1500 in the
real
> > system)
> >
> > Question 1 ) Is there a more efficiant way of doing this, atleast to
reduce
> > the number of queries?
>
>   I guess you are updating filed RANK, so that the domain that has more
> visits per day gets value 1, the second gets value 2, etc..
>   Can you just omit this fileld? So you don't need to the script that
> recalculates :)
>   I mean, can you forget about the rank filed and only work with
> (viewcount/(($now - startedTime)/86400)) (wiews per day)?
>
> ---
> Dani Pardo, [EMAIL PROTECTED]
> Enplater S.A
>
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: A MySQL Question

2004-05-21 Thread Dani Pardo
On Fri, 21 May 2004, LRMK wrote:

> Probably this is not relavent to this mailing list... But any way I ll ask..
>
> I am developing a web site traffic rating system. using a combination og
> perl and java (PERL in serverside, Java Applets in cliend side - My attempt
> to create dynamic images was not that successfull so I use a java applet to
> view the rating info on the site)
>
> Here is my question The rating system is now working but every day I have to
> run a hevy SQL statement to recalculate the traffic ranks of web sites
>
> Something similer to this
>
> $DBC is the connection to the mysql database
>
>
> my $q = $DBC->prepare("SELECT domainname, (viewcount/(($now -
> startedTime)/86400)) AS views_per_day " .
> "FROM site WHERE startedTime<($now -
> 48hours) " .  # I do not give ranks for the sites registered withing
> last 48 hours
> "ORDER BY views_per_day DESC")
>
> my $rank = 0;
>
> $q->execute();
>
> while (my $ref = $q->fetchrow_hashref()){
> $rank++;
> my %hash = %{$ref};
> $DBC->do("UPDATE site SET rank = $rank WHERE domainname=" .
> $DBC->quote($hash{'domainname'}));
>
> }
>
> $q->finish();
>
> $DBC->do("COMMIT");
>
>
>
>
> the problem is if there are 1500 qualified records in the table there going
> to 1501 queries (there going to be lots mor records than 1500 in the real
> system)
>
> Question 1 ) Is there a more efficiant way of doing this, atleast to reduce
> the number of queries?

  I guess you are updating filed RANK, so that the domain that has more
visits per day gets value 1, the second gets value 2, etc..
  Can you just omit this fileld? So you don't need to the script that
recalculates :)
  I mean, can you forget about the rank filed and only work with
(viewcount/(($now - startedTime)/86400)) (wiews per day)?

---
Dani Pardo, [EMAIL PROTECTED]
Enplater S.A

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]