473,387 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

If conditionals to execute blocks of text

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
1 1414
miller
1,089 Expert 1GB
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

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

Similar topics

1
by: FHuang | last post by:
Ok, I'm having some trouble with conditionals, for some reason PHP is screwing them up. First off, here is the code: <?php $username = "fred"; $userdata = "./$username.txt"; $fp =...
14
by: J.S. | last post by:
In a Windows Form application, which is the better method to concatenate large blocks of code? 1. Reading the text from text files. 2. Adding the text to the VB file itself? Thanks! J.S. ...
11
by: .Net Sports | last post by:
I need to convert some C# ?Conditionals over to vb.net (most likely in vb.net using If..Then statements), but the C#2VBNETconverter by KamalPatel isn't converting them: string PurchaseType =...
7
by: Nick Keighley | last post by:
Hi, I took a quick look for a FAQ (apparently this ng doesn't have "a" FAQ). And the resources I've checked are contradictory. I want two blocks of text to appear next to on another. HTML...
26
by: brenocon | last post by:
Hi all -- Compared to the Python I know and love, Ruby isn't quite the same. However, it has at least one terrific feature: "blocks". Whereas in Python a "block" is just several lines of...
6
by: chopin | last post by:
I am working in Access 2003 in Windows XP. I am using Visual Basic for Applications, using DAO to write my modules. What I need to do is write a module that will compare each row to see if they are...
2
by: flyzone | last post by:
Goodmorning people :) I have just started to learn this language and i have a logical problem. I need to write a program to parse various file of text. Here two sample: --------------- trial...
12
by: Michael7 | last post by:
Hi Everyone, I've been trying to get two blocks of text to be aligned, one left, one right, on the same line. What I'm trying to mimic is what I did with tables here: ...
5
by: Hul Tytus | last post by:
comp.lang.c c programs & shell conditionals How is a unix shell script made to respond to the value returned by a program compiled from c code? The shell script below is my current effort,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.