0

Hello All,

I am getting the infamous Argument ___ isn't numeric in sprintf. I've looked around but I can't seem to fix the issue. It seems to occur if it has a 0. in front of the numeric pattern that causes it. Does anyone have any idea of what I need to alter to fix it?

Here are the results from the perl script:

C:\XAMPP\perl\bin>perl reddrill.pl
Content-type: text/html

<html>          <!-- start tag for the HTML page -->
<head>  <!-- header data like the window title -->
<title>Wonu LLC</title>
#Cascading Style Sheet(CSS)definitions (and/or links) go here JavaScript or VBSc
ript function definitions and/or links.
</head>
<body>  <!-- the page's main HTML code -->
<h3>Stock Quotes</h3>
<table border ='1' cellpadding='5' cellspacing='0'>
<tr>
 <th>Name</th>
 <th>Last</th>
 <th>Previous</th>
 <th>High</th>
 <th>Low</th>
 <th>Change</th>
 <th>%Change
</th>
 </tr>
<tr>/n          <td>Apollo Group</td>
                <td align='right'>91.86</td>
                <td align='right'>92.07</td>
                <td align='right'>92.71</td>
                <td align='right'>91.70</td>
                <td align='right'>-0.21</td>
Argument "-0.23%\n" isn't numeric in sprintf at reddrill.pl line 17.
                <td align='right'>-0.23</td>
</tr>
<tr>/n          <td>Babson Value</td>
                <td align='right'>44.25</td>
                <td align='right'>43.95</td>
                <td align='right'>44.25</td>
                <td align='right'>44.25</td>
                <td align='right'>0.30</td>
Argument "0.68%\n" isn't numeric in sprintf at reddrill.pl line 17.
                <td align='right'>0.68</td>
</tr>
<tr>/n          <td>Baron Asset</td>
                <td align='right'>47.92</td>
                <td align='right'>47.61</td>
                <td align='right'>47.92</td>
                <td align='right'>47.92</td>
                <td align='right'>0.31</td>
Argument "0.65%\n" isn't numeric in sprintf at reddrill.pl line 17.
                <td align='right'>0.65</td>
</tr>
<tr>/n          <td>Baron Small Cap</td>
                <td align='right'>20.28</td>
                <td align='right'>20.18</td>
                <td align='right'>20.28</td>
                <td align='right'>20.28</td>
                <td align='right'>0.10</td>
Argument "0.50%\n" isn't numeric in sprintf at reddrill.pl line 17.
                <td align='right'>0.50</td>
</tr>
<tr>/n          <td>Credit Suisse Capital Apprec Comm</td>
                <td align='right'>15.67</td>
                <td align='right'>15.63</td>
                <td align='right'>15.67</td>
                <td align='right'>15.67</td>
                <td align='right'>0.04</td>
Argument "0.26%\n" isn't numeric in sprintf at reddrill.pl line 17.
                <td align='right'>0.26</td>
</tr>
<tr>/n          <td>Credit Suisse Emerging Growth Comm</td>
                <td align='right'>29.55</td>
                <td align='right'>29.60</td>
                <td align='right'>29.55</td>
                <td align='right'>29.55</td>
                <td align='right'>-0.05</td>
Argument "-0.17%\n" isn't numeric in sprintf at reddrill.pl line 17.
                <td align='right'>-0.17</td>
</tr>
<tr>/n          <td>DeVry</td>
                <td align='right'>32.09</td>
                <td align='right'>31.90</td>
                <td align='right'>32.31</td>
                <td align='right'>31.75</td>
                <td align='right'>0.19</td>
Argument "0.60%\n" isn't numeric in sprintf at reddrill.pl line 17.
                <td align='right'>0.60</td>
</tr>
<tr>/n          <td>Eaton Vance Tax-Mgd Growth 1.1 A</td>
                <td align='right'>21.44</td>
                <td align='right'>21.31</td>
                <td align='right'>21.44</td>
                <td align='right'>21.44</td>
                <td align='right'>0.13</td>
Argument "0.61%\n" isn't numeric in sprintf at reddrill.pl line 17.
                <td align='right'>0.61</td>
</tr>
<tr>/n          <td>Eaton Vance Tax-Mgd Growth 1.2 A</td>
                <td align='right'>9.63</td>
                <td align='right'>9.57</td>
                <td align='right'>9.63</td>
                <td align='right'>9.63</td>
                <td align='right'>0.06</td>
Argument "0.63%\n" isn't numeric in sprintf at reddrill.pl line 17.
                <td align='right'>0.63</td>
</tr>
<tr>/n          <td>Fidelity Aggressive Growth</td>
                <td align='right'>15.83</td>
                <td align='right'>15.76</td>
                <td align='right'>15.83</td>
                <td align='right'>15.83</td>
                <td align='right'>0.07</td>
Argument "0.44%\n" isn't numeric in sprintf at reddrill.pl line 17.
                <td align='right'>0.44</td>
</tr>
<tr>/n          <td>Fidelity Contrafund</td>
                <td align='right'>51.57</td>
                <td align='right'>51.38</td>
                <td align='right'>51.57</td>
                <td align='right'>51.57</td>
                <td align='right'>0.19</td>
Argument "0.37%\n" isn't numeric in sprintf at reddrill.pl line 17.
                <td align='right'>0.37</td>
</tr>
<tr>/n          <td>Fidelity Disciplined Equity</td>
                <td align='right'>23.38</td>
                <td align='right'>23.27</td>
                <td align='right'>23.38</td>
                <td align='right'>23.38</td>
                <td align='right'>0.11</td>
Argument "0.47%\n" isn't numeric in sprintf at reddrill.pl line 17.
                <td align='right'>0.47</td>
</tr>
<tr>/n          <td>Fidelity Growth & Income</td>
                <td align='right'>36.32</td>
                <td align='right'>36.13</td>
                <td align='right'>36.32</td>
                <td align='right'>36.32</td>
                <td align='right'>0.19</td>
Argument "0.53%\n" isn't numeric in sprintf at reddrill.pl line 17.
                <td align='right'>0.53</td>
</tr>
<tr>/n          <td>Fidelity Low-Priced Stock</td>
                <td align='right'>36.92</td>
                <td align='right'>36.73</td>
                <td align='right'>36.92</td>
                <td align='right'>36.92</td>
                <td align='right'>0.19</td>
Argument "0.52%\n" isn't numeric in sprintf at reddrill.pl line 17.
                <td align='right'>0.52</td>
</tr>
<tr>/n          <td>Fidelity Magellan</td>
                <td align='right'>100.14</td>
                <td align='right'>99.56</td>
                <td align='right'>100.14</td>
                <td align='right'>100.14</td>
                <td align='right'>0.58</td>
Argument "0.58%\n" isn't numeric in sprintf at reddrill.pl line 17.
                <td align='right'>0.58</td>
</tr>
<tr>/n          <td>Fidelity Select Biotechnology</td>
                <td align='right'>58.09</td>
                <td align='right'>57.55</td>
                <td align='right'>58.09</td>
                <td align='right'>58.09</td>
                <td align='right'>0.54</td>
Argument "0.94%\n" isn't numeric in sprintf at reddrill.pl line 17.
                <td align='right'>0.94</td>
</tr>
<tr>/n          <td>Fidelity Select Electronics</td>
                <td align='right'>41.69</td>
                <td align='right'>42.35</td>
                <td align='right'>41.69</td>
                <td align='right'>41.69</td>
                <td align='right'>-0.66</td>
Argument "-1.56%\n" isn't numeric in sprintf at reddrill.pl line 17.
                <td align='right'>-1.56</td>
</tr>
<tr>/n          <td>Fidelity Select Food & Agriculture</td>
                <td align='right'>46.70</td>
                <td align='right'>46.27</td>
                <td align='right'>46.70</td>
                <td align='right'>46.69</td>
                <td align='right'>0.43</td>
Argument "0.93%\n" isn't numeric in sprintf at reddrill.pl line 17.
                <td align='right'>0.93</td>
</tr>
<tr>/n          <td>Fidelity Small Cap Independence</td>
                <td align='right'>18.77</td>
                <td align='right'>18.70</td>
                <td align='right'>18.77</td>
                <td align='right'>18.77</td>
                <td align='right'>0.07</td>
Argument "0.37%\n" isn't numeric in sprintf at reddrill.pl line 17.
                <td align='right'>0.37</td>
</tr>
<tr>/n          <td>Fidelity Spartan MA Municipal Income</td>
                <td align='right'>12.11</td>
                <td align='right'>12.08</td>
                <td align='right'>12.11</td>
                <td align='right'>12.11</td>
                <td align='right'>0.03</td>
Argument "0.25%\n" isn't numeric in sprintf at reddrill.pl line 17.
                <td align='right'>0.25</td>
</tr>
<tr>/n          <td>Fidelity Value</td>
                <td align='right'>65.52</td>
                <td align='right'>65.04</td>
                <td align='right'>65.52</td>
                <td align='right'>65.52</td>
                <td align='right'>0.48</td>
Argument "0.74%\n" isn't numeric in sprintf at reddrill.pl line 17.
                <td align='right'>0.74</td>
</tr>
<tr>/n          <td>Julius Baer International Equity A</td>
                <td align='right'>28.02</td>
                <td align='right'>27.81</td>
                <td align='right'>28.02</td>
                <td align='right'>28.02</td>
                <td align='right'>0.21</td>
Argument "0.76%\n" isn't numeric in sprintf at reddrill.pl line 17.
                <td align='right'>0.76</td>
</tr>
<tr>/n          <td>SumTotal Systems Inc.</td>
                <td align='right'>7.59</td>
                <td align='right'>7.64</td>
                <td align='right'>7.65</td>
                <td align='right'>7.40</td>
                <td align='right'>-0.05</td>
Argument "-0.65%\n" isn't numeric in sprintf at reddrill.pl line 17.
                <td align='right'>-0.65</td>
</tr>
</table>
</body> <! --end tag for main page section -->
</html> <!-- end tag for entire HTML page -->

And here is the code

#!C:\XAMPP\perl\bin -w
use English; #allow long built-in variable names
#this line sets the MIME type
print "Content-type: text/html\n\n";
print <<HEADER;#remember: no spaces after << !
<html>       <!-- start tag for the HTML page -->
<head>   <!-- header data like the window title -->
<title>Wonu LLC</title>
#Cascading Style Sheet(CSS)definitions (and/or links) go here JavaScript or VBScript function definitions and/or links.
</head>
<body>   <!-- the page's main HTML code -->
HEADER
use vars qw ($StockName $LastPrice $PrevClose $High $Low $Change $PctChange); 
# return argument with two decimal places
sub twodec
{
return sprintf("%0.2f",$_[0]);
}# read stock data
open STOCKS, "StockQuotes.csv" #open input file
    or die print "<i>Processing error:&nbsp;</i> $OS_ERROR.";
    my @quotes = <STOCKS>;       #read data all at once
close STOCKS;           #close input file
# display page header, read file and start table
print "<h3>Stock Quotes</h3>\n";
print "<table border ='1' cellpadding='5' cellspacing='0'>\n";
#process each line of the file in turn
foreach $line (@quotes)  #$line is the variable for each line returned from the file
{
($StockName, $LastPrice, $PrevClose, $High, $Low, $Change, $PctChange) = split(",", $line);#it takes each line and analyzes if the first line equals $StockName if so, it then takes each data in the line and splits with a comma and then places each one in each row.
if ($StockName eq "Name") #column heads.  The first row of the spreadsheet is the header rows. And the first cell is the Name column
{
print "<tr>\n";
print " <th>$StockName</th>\n";
print " <th>$LastPrice</th>\n";
print " <th>$PrevClose</th>\n";
print " <th>$High</th>\n";
print " <th>$Low</th>\n";
print " <th>$Change</th>\n";
print " <th>$PctChange</th>\n";
print " </tr>\n";
next ;
}
print "<tr>/n";      #data rows
print "     <td>$StockName</td>\n";
print "     <td align='right'>", twodec($LastPrice), "</td>\n";
print "     <td align='right'>", twodec($PrevClose), "</td>\n";
print "     <td align='right'>", twodec($High),       "</td>\n";
print "     <td align='right'>", twodec($Low),        "</td>\n";
print "     <td align='right'>", twodec($Change),     "</td>\n";
print "     <td align='right'>", twodec($PctChange, 0, -1), "</td>\n";
print "</tr>\n";
}
print "</table>\n";#end table
print <<FOOTER;
</body> <! --end tag for main page section -->
</html>  <!-- end tag for entire HTML page -->
FOOTER
#Had to add a newline after FOOTER
#to avoid newline terminating error

Edited by Dani: Formatting fixed

1
Contributor
1
Reply
3
Views
6 Years
Discussion Span
Last Post by choosenalpha
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.