CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Need help with an if statement

 



FireBird_1991
New User

Feb 23, 2011, 8:26 AM

Post #1 of 1 (209 views)
Need help with an if statement Can't Post

I am looking to add an if statement that would change the $beginning variable if what it returns to begin with is after the ending variable. Example would be if when it looks up the beginning variable and it is 02302010 and the ending variable is 02202010 it will change the beginning variable to 02012010 which is the previous beginning. Here is the current code that I have and I can't seem to figure out how to impliment this new if statement. Any help would be greatly appreciated.

</td><td style=width:10px></td><td>
<%= $url = "$selfurl?session=$session_id;action="; ''; %>
<%= include('header') %>

<FONT SIZE=4>Service usage details for
<%= Date::Format::time2str('%b&nbsp;%o&nbsp;%Y', $beginning) %> -
<%= Date::Format::time2str('%b&nbsp;%o&nbsp;%Y', $ending) %>
</FONT><BR><BR>

<%= if ( $error ) {
$OUT .= qq!<FONT SIZE="+1" COLOR="#ff0000">$error</FONT><BR><BR>!;
} ''; %>

<TABLE WIDTH="100%">
<TR>
<TD WIDTH="50%">
<%= if ($previous < $beginning) {
$OUT .= qq!<A HREF="${url}view_usage_details;svcnum=$svcnum;beginning=!;
$OUT .= qq!$previous;ending=$beginning">Previous period</A>!;
}else{
'';
} %>
</TD>
<TD WIDTH="50%" ALIGN="right">
<%= if ($next > $ending) {
$OUT .= qq!<A HREF="${url}view_usage_details;svcnum=$svcnum;beginning=!;
$OUT .= qq!$ending;ending=$next">Next period</A>!;
}else{
'';
}%>
</TD>
</TR>
</TABLE>
<TABLE BGCOLOR="#cccccc">
<TR>
<TH ALIGN="left">Account</TH><td style=width:10px></td>
<TH ALIGN="right">Start Time</TH><td style=width:10px></td>
<TH ALIGN="right">Duration</TH><td style=width:10px></td>
<TH ALIGN="right">Upload</TH><td style=width:10px></td>
<TH ALIGN="right">Download</TH>
</TR>
<%= my $total = 0;
my $utotal = 0;
my $dtotal = 0;
foreach my $usage ( @usage ) {
$OUT .= '<TR><TD>';
$OUT .= $usage->{'username'};
$OUT .= '</TD><td style=width:20px></td><TD ALIGN="right">';
$OUT .= Date::Format::time2str('%T%P %a&nbsp;%b&nbsp;%o&nbsp;%Y', $usage->{'acctstarttime'});
$OUT .= '</TD><td style=width:20px></td><TD ALIGN="right">';
my $duration = $usage->{'acctstoptime'} - $usage->{'acctstarttime'};
$total += $duration;
my $h = int($duration/3600);
my $m = sprintf("%02d", int(($duration % 3600) / 60));
my $s = sprintf("%02d", $duration % 60);
$OUT .= "$h:$m:$s";
$OUT .= '</TD><td style=width:10px></td><TD ALIGN="right">';
$OUT .= Number::Format::format_bytes($usage->{'acctinputoctets'}, precision => 2);
$utotal += $usage->{'acctinputoctets'};
$OUT .= '</TD><td style=width:10px></td><TD ALIGN="right">';
$OUT .= Number::Format::format_bytes($usage->{'acctoutputoctets'}, precision => 2);
$dtotal += $usage->{'acctoutputoctets'};
$OUT .= '</TD></TR>';
}
my $h = int($total/3600);
my $m = sprintf("%02d", int(($total % 3600) / 60));
my $s = sprintf("%02d", $total % 60);
$OUT .= qq!<TR><TD></TD><TD></TD>!;
$OUT .= qq!<TD ALIGN="right" style="width:100px"><HR></TD>! x 3;
$OUT .= qq!</TR>!;
$OUT .= qq!<TR><TD></TD><TD></TD><TD></TD><TD></TD><TD ALIGN="right" style="width:100px; font-weight:bold;"></TD>!;
$OUT .= qq!<TD></TD><TD ALIGN="right" style="width:100px; font-weight:bold;">!;
$OUT .= Number::Format::format_bytes($utotal, precision => 2). qq!</TD>!;
$OUT .= qq!<TD></TD><TD ALIGN="right" style="width:100px; font-weight:bold;">!;
$OUT .= Number::Format::format_bytes($dtotal, precision => 2). qq!</TD>!;
$OUT .= qq!</TR>!; %>
</TABLE>
<BR>


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives