By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,182 Members | 1,422 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,182 IT Pros & Developers. It's quick & easy.

If conditionals to execute blocks of text

P: 1
Hi

A colleague of mine helped me develop the tool on http://www.coolinvestor.com/stockscan2.html

It works and runs correlations on data - and if the datafeed is yahoo it uses data from yahoo; and if datafeed is database it uses data from an internally constructed database.

However, the problem is that although it works the GUI has been constructed so that it is directed to two different perl scripts (with a bit of javascript i think - see GUI extract below) depending on what user chooses. One with this block:

Expand|Select|Wrap|Line Numbers
  1. $comp_url = "http://finance.yahoo.com/q/cp?s=%5E".$sector;
  2. my $v = get ($comp_url);
  3. my @components = get_comps($v);
  4. #print join(',',@components),"<BR>";
  5.  
  6. ...and one with this block:
  7.  
  8. $comp_url = "http://www.coolinvestor.com/grab_cpn2.php?s=".$sector;
  9. my $v = get ($comp_url);
  10. @components = split(",", $v);
  11.  
...rather than using some type of if statement in one script.


I am not a programmer myself although I understand (sort of ) what to do. But I can't get anything to work - probably because my handling of variables is very bad!

Any help to make the blocks execute properly according to the users choice rather than having two scripts would be appreciated.

Jonmy

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

Here is the fuller context from the script that uses the database - the yahoo bit is simply hashed out here.


Expand|Select|Wrap|Line Numbers
  1. $sector = "XBD"; # default sector
  2. $threshold = 0.7; #default threshold
  3. $duration = 6; #default duration
  4. $periods = 0; #default duration
  5. @dur_array = (0,0,0,0,0,0);
  6.  
  7.  
  8. # Determine which sector the user wants
  9. @fields = split(/&/,$combo_value);
  10. foreach $f (@fields) {
  11.     if ($f =~ m/(.*)=(.*)/) {
  12.         if ($1 eq "sector") { $sector = $2;}
  13.         if ($1 eq "threshold") { $threshold = $2;}
  14.         if ($1 eq "duration")
  15.         {
  16.          $periods++;    
  17.             if ($2 eq "1") { $dur_array[0] = 1;}
  18.             elsif ($2 eq "2") { $dur_array[1] = 1;}    
  19.             elsif ($2 eq "4") { $dur_array[2] = 1;}    
  20.             elsif ($2 eq "12") { $dur_array[3] = 1;}    
  21.             elsif ($2 eq "24") { $dur_array[4] = 1;}
  22.             elsif ($2 eq "48") { $dur_array[5] = 1;}
  23.             else { print "previous case not true";}    
  24.         }
  25.     }
  26. }
  27.  
  28. # now find out the components in the sector (from component text file)
  29.  
  30. $comp_url = "http://www.coolinvestor.com/grab_cpn2.php?s=".$sector;
  31. my $v = get ($comp_url);
  32. @components = split(",", $v);
  33.  
  34. #$comp_url = "http://finance.yahoo.com/q/cp?s=%5E".$sector;
  35. #my $v = get ($comp_url);
  36. #my @components = get_comps($v);
  37. #print join(',',@components),"<BR>";
  38.  
  39. print "<center><h1>Correlations between components of $sector</h1></center>\n";
  40. $siz = $#components+1;
  41. print "<br>\n";
  42. print "<center><h5>There are ",$siz," components in this sector. This gives ",($siz*($siz-1))/2," possible pairwise correlations.</h5></center>\n";
  43. print "<br></br>\n";
  44. print "<center> <h3>Scan results for stock pairs with correlations at or stronger than the threshold of ", $threshold, "</h3></center>";
  45. print "<br>\n";
  46.  
--------------------------------------------------------------------------------------------------------

HTML GUI page

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

Expand|Select|Wrap|Line Numbers
  1. <HEAD>
  2.  
  3.  
  4.  
  5. <TITLE>Sector Correlation Scan</TITLE>
  6. <META http-equiv=Content-Type content="text/html; charset=windows-1252">
  7. <META content="MSHTML 5.50.4134.600" name=GENERATOR>
  8.  
  9. <script type="text/javascript">
  10. <!--
  11. function submitForm()
  12. {
  13. datafeed = document.scanform.datafeed.value;
  14.  
  15. if(datafeed == "database")
  16. {
  17.     document.scanform.action = "http://www.coolinvestor.com/cgi-bin/corrscan/stockscan2.pl";
  18. document.scanform.submit();
  19. }
  20.  
  21. if(datafeed == "Yahoo")
  22. {
  23.     document.scanform.action = "http://www.coolinvestor.com/cgi-bin/corrscan/stockscan.pl";
  24. document.scanform.submit();
  25. }
  26.  
  27.  
  28.  
  29. }
  30.  
  31. window.onload = function()
  32. {
  33.     document.scanform.onsubmit = submitForm;
  34. }
  35.  
  36. //-->
  37. </script>
  38. </HEAD>
  39. <BODY>
  40.  
  41. <FORM method=post name=scanform>
  42. <TABLE style="HEIGHT: 197px" cellSpacing=2 cellPadding=2 align=center
  43. bgColor=#0a1666 border=2>
  44. <TBODY>
  45.  
Jul 4 '07 #1
Share this Question
Share on Google+
1 Reply


miller
Expert 100+
P: 1,089
Greetings jonmy,

I noticed how you've now asked your question on TT. Please note that is is normally beyond the interest of experts to volunteer time in helping a poster decypher someone else's code, let alone code that is this long.

If you have a specific question issue feel free to pose it here. But I at least do not have the time or interest to help with your greater debugging or designing issues.

- Miller
Jul 9 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.