Perl Code in style not working

Discuss news styles, css code, and other Coranto customizations in here...the possibilities are endless, so have at it!

Moderator: Spunkmeyer

Perl Code in style not working

Postby tlcoverdale » Sun Jun 19, 2005 7:32 pm

I've got fields for start hour, start minute, end hour, and end minute for a daily schedule page. I'm having the profile sort by start hour then start minute, which is working fine.

However, in the setup of the hour fields, I've numbered them military time style to make the sorting work. I want to present the correct clock number for those hours...In other words, "0" should be "12", "13" and higher should revert to the (hour - 12).

I've done the code before, but all of the tweaks I remember making aren't taking this time. So, here goes...

<PerlCode>
if (<Field: CustomField_start_hour> == 0) {
$sh == 12;
}
if (<Field: CustomField_start_hour> <= 12) {
$sh == <Field: CustomField_start_hour>;
}
if (<Field: CustomField_start_hour> > 12) {
$sh == (<Field: CustomField_start_hour> - 12);
}
</PerlCode>

$sh is the starting hour in my style. The first entry doesn't even register $sh, and the next registers it as "0", when it should be the entry for <Field: CustomField_start_hour>

I've hammered on this quite a bit today, already, and my ever balding head is losing more & more of its cover ;)

Thanks as always, gang.
User avatar
tlcoverdale
 
Posts: 22
Joined: Wed May 22, 2002 1:27 am

Postby Esstee » Sun Jun 19, 2005 8:23 pm

shouldn't there be an </If> somewheres?

If im suggesting something stupid just ignore this post :P
I went deeper into the belly of Coranto and look! I found maginot.
User avatar
Esstee
 
Posts: 320
Joined: Thu Nov 25, 2004 4:13 pm
Location: Deep in some project

Re: Perl Code in style not working

Postby Parahead » Sun Jun 19, 2005 9:13 pm

Should only be one equal sign when you assign a value. Also, why do you use the Coranto style tags within the PerlCode section, just makes things look real messy? Try this out:
Code: Select all
<PerlCode>
if ($CustomField_start_hour == 0) {
$sh = 12;
}
if ($CustomField_start_hour <= 12) {
$sh = <Field: CustomField_start_hour>;
}
if ($CustomField_start_hour > 12) {
$sh = ($CustomField_start_hour - 12);
}
</PerlCode>


Esstee wrote:shouldn't there be an </If> somewheres?
That is a Coranto styletag, which is equivalent to a } in the PerlCode, so it is there.
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden

Postby InSAnE NiNjA » Sun Jun 19, 2005 11:10 pm

missed one


Code: Select all
<PerlCode>
if ($CustomField_start_hour == 0) {
$sh = 12;
}
if ($CustomField_start_hour <= 12) {
$sh = $CustomField_start_hour;
}
if ($CustomField_start_hour > 12) {
$sh = ($CustomField_start_hour - 12);
}
</PerlCode>
..nuttier then a squirrel turd..
User avatar
InSAnE NiNjA
 
Posts: 1213
Joined: Sat Jan 25, 2003 6:35 am

Well...

Postby tlcoverdale » Sun Jun 19, 2005 11:40 pm

So, I'm scratching my head, thinking I tried this type of coding earlier today...

Maybe the heat's gettin' to me...Altered Parahead's code for one change...

<PerlCode>
if ($CustomField_start_hour <= 12) {
$sh = $CustomField_start_hour;
}
if ($CustomField_start_hour > 12) {
$sh = ($CustomField_start_hour - 12);
}
if ($CustomField_start_hour == 0) {
$sh = 12;
}
</PerlCode>


This code:
if ($CustomField_start_hour == 0) {
$sh = 12;
}
needed to be put at the bottom of the statements, otherwise:
if ($CustomField_start_hour <= 12) {
$sh = $CustomField_start_hour;
}
was overwriting $sh ...

Example: $sh = 12, after point one, then <=12 it was set to equal $CustomField_start_hour.

So, confusing, yes, but still should've had this figured out earlier...

Thanks gang!
User avatar
tlcoverdale
 
Posts: 22
Joined: Wed May 22, 2002 1:27 am

Postby Parahead » Mon Jun 20, 2005 7:45 am

InSAnE NiNjA wrote:missed one
Oops...

Anyway, we could improve it a little more, using elsif...
Code: Select all
<PerlCode>
if ($CustomField_start_hour == 0) {
  $sh = 12;
} elsif ($CustomField_start_hour <= 12) {
  $sh = $CustomField_start_hour;
} elsif ($CustomField_start_hour > 12) {
  $sh = ($CustomField_start_hour - 12);
}
</PerlCode>
tlcoverdale, does this updated version of your initial code solve your problem?
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden

Postby LoneOwl » Mon Jun 20, 2005 8:36 am

I just have to do at least one one liner......
Code: Select all
<PerlCode>
$sh = $CustomField_start_hour % 12 + ($CustomField_start_hour % 12 ? 0 : 12)
</PerlCode>
User avatar
LoneOwl
 
Posts: 1465
Joined: Sun Mar 10, 2002 2:57 am
Location: That one place, you know?

Postby Parahead » Mon Jun 20, 2005 9:25 am

LoneOwl wrote:I just have to do at least one one liner......
I knew that would come! You are more than welcome with your oneliners LoneOwl, at least I use them as inspiration... :pray:
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden

Postby LoneOwl » Mon Jun 20, 2005 9:41 am

Simpler code can be faster code, even if perhaps a tad harder to read. And to think, three years ago, I didn't know any perl.
User avatar
LoneOwl
 
Posts: 1465
Joined: Sun Mar 10, 2002 2:57 am
Location: That one place, you know?

Holy (censored)...

Postby tlcoverdale » Mon Jun 20, 2005 11:34 am

:pray:

LoneOwl, that rocks. I'm still learning & hacking away at web dev as a "hobby", so my Perl is very basic, usually trial and error...

Thanks for the updates and help!
User avatar
tlcoverdale
 
Posts: 22
Joined: Wed May 22, 2002 1:27 am

Postby Lumberjack » Mon Jun 20, 2005 4:12 pm

tlcoverdale wrote:This code:
if ($CustomField_start_hour == 0) {
$sh = 12;
}
needed to be put at the bottom of the statements, otherwise:
if ($CustomField_start_hour <= 12) {
$sh = $CustomField_start_hour;
}
was overwriting $sh ...

Example: $sh = 12, after point one, then <=12 it was set to equal $CustomField_start_hour.

Yeah that's because <= means less than or equal to. You should use < only when writing things like this (I know you probably use LoneOwl's nice but hard to read code now though).
Lumberjack
 
Posts: 555
Joined: Wed Jan 10, 2007 7:22 pm
Location: Oxford, UK


Return to Customization

Who is online

Users browsing this forum: No registered users and 3 guests