|
| Author |
Message |
JTW God Like

Joined: 07 Mar 2004 Posts: 579 Location: Maidstone
  votes: 4
|
Posted: Thu Jan 03, 2008 5:56 pm Post subject: Dealing with numbers |
|
|
Hi
I am making a command to get tv listings. The problem is the programs are coming out in the wrong order ie. 2035 before 1920 I was wondering if there was any way i could solve this. The code I am using is; | Code: | my $programs, $description;
foreach my $program (keys %{$bot->{tv}->{BBC1}->{time}}){ # For Every bbc1 listing
if($program>$string){
$description = substr($bot->{tv}->{BBC1}->{time}->{$program}->{description},0,100);
$description .= "...";
$programs.="\n\n$program: $bot->{tv}->{BBC1}->{time}->{$program}->{title}\n$description";
}
}
$self->sendMessage("BBC 1 Listings$programs"); | I would also if possible like to get the program that is currently on, (the highest number that is lower than the current time) I am sure there must be an easy way to do this I just can't figure out how.
Thanks Very much for any help
JT
Edit: Re wrote post so it made more sense _________________ "Help us, Help you" - BotDepot |
|
| Back to top |
|
 |
Teario Member

Joined: 25 Jun 2004 Posts: 130 Location: Liverpool(home) or Derby(uni), UK
  votes: 3
|
Posted: Fri Jan 04, 2008 12:41 am Post subject: |
|
|
Sorry, I posted a reply but then I realised it was totally wrong My perl is rusty.
Can you give me an example of the data? Is $bot...{time}->{program_name} the time that this program is aired? |
|
| Back to top |
|
 |
JTW God Like

Joined: 07 Mar 2004 Posts: 579 Location: Maidstone
  votes: 4
|
Posted: Fri Jan 04, 2008 9:39 am Post subject: |
|
|
Ive worked out one bit How to get the now and next, Very confusing.
So all I need to do now is order the times of the programs. Here is the way the data is stored
| Quote: | $save1 = {
'BBC1' => {
'time' => {
'1330' => {
'title' => 'BBC London News',
'description' => 'The latest stories from the BBC London newsroom.'
},
'0210' => {
'title' => 'Top Gear',
'description' => 'In the last show of the series Jeremy, James and Richard take the new BMW M3, Mercedes ...'
},
| So basicly all I need to do now is get it to print the programs in order by the correct $bot->{tv}->{BBC1}->{time} _________________ "Help us, Help you" - BotDepot |
|
| Back to top |
|
 |
Teario Member

Joined: 25 Jun 2004 Posts: 130 Location: Liverpool(home) or Derby(uni), UK
  votes: 3
|
Posted: Fri Jan 04, 2008 1:26 pm Post subject: |
|
|
If time has a list of entries and the key is the time that they are aired, then you can just add a call to sort() in your foreach:
| Code: | | foreach my $program sort((keys %{$bot->{tv}->{BBC1}->{time}})){ |
Can't test this as im at work, but I did something similar last night and it seemed to be ok. |
|
| Back to top |
|
 |
JTW God Like

Joined: 07 Mar 2004 Posts: 579 Location: Maidstone
  votes: 4
|
Posted: Fri Jan 04, 2008 8:44 pm Post subject: |
|
|
Thanks I have managed to get it working
However it did not like | Code: | | foreach my $program sort((keys %{$bot->{tv}->{BBC1}->{time}})){ | so instead i did this
| Code: | sort($bot->{tv}->{BBC1}->{time});
foreach my $program (keys %{$bot->{tv}->{BBC1}->{time}}){ |
Thanks for your help _________________ "Help us, Help you" - BotDepot |
|
| Back to top |
|
 |
Teario Member

Joined: 25 Jun 2004 Posts: 130 Location: Liverpool(home) or Derby(uni), UK
  votes: 3
|
Posted: Sat Jan 05, 2008 1:43 am Post subject: |
|
|
Just checked my code and it should have been this:
| Code: | | foreach my $program (sort(keys %{$bot->{tv}->{BBC1}->{time}})){ |
I got the sort in the wrong place.
Hope that helps  |
|
| Back to top |
|
 |
|