User Control Panel
Advertisements

HELP US, HELP YOU!

Dealing with numbers

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Perl
View unanswered posts
Author Message
JTW
God Like
God Like


Joined: 07 Mar 2004
Posts: 579
Location: Maidstone
Reputation: 67.1
votes: 4

PostPosted: Thu Jan 03, 2008 5:56 pm    Post subject: Dealing with numbers Reply with quote

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
Member


Joined: 25 Jun 2004
Posts: 130
Location: Liverpool(home) or Derby(uni), UK
Reputation: 59.8
votes: 3

PostPosted: Fri Jan 04, 2008 12:41 am    Post subject: Reply with quote

Sorry, I posted a reply but then I realised it was totally wrong Sad 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
God Like


Joined: 07 Mar 2004
Posts: 579
Location: Maidstone
Reputation: 67.1
votes: 4

PostPosted: Fri Jan 04, 2008 9:39 am    Post subject: Reply with quote

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
Member


Joined: 25 Jun 2004
Posts: 130
Location: Liverpool(home) or Derby(uni), UK
Reputation: 59.8
votes: 3

PostPosted: Fri Jan 04, 2008 1:26 pm    Post subject: Reply with quote

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
God Like


Joined: 07 Mar 2004
Posts: 579
Location: Maidstone
Reputation: 67.1
votes: 4

PostPosted: Fri Jan 04, 2008 8:44 pm    Post subject: Reply with quote

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
Member


Joined: 25 Jun 2004
Posts: 130
Location: Liverpool(home) or Derby(uni), UK
Reputation: 59.8
votes: 3

PostPosted: Sat Jan 05, 2008 1:43 am    Post subject: Reply with quote

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 Smile
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Perl All times are GMT
Page 1 of 1

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group