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:
cherryEPG

 



zaca011
New User

Feb 7, 2016, 11:14 PM

Post #1 of 7 (2203 views)
cherryEPG Can't Post

Hi to everybody.

I am new in using perl . I need just to modify file for my porpose. I hope that someone can help me with this.

this is en error thet reporting:

cherryEPG.pl - Copyright 2013-2014 Bojan Ramsak
Importing Comedy-xmltv.xml
Not a HASH reference at ./cherryEPG.pl line 213.


this is a part of code :

Code
        my @descriptors; 
my $short_descriptor;
$short_descriptor->{descriptor_tag} = 0x4d; # short event descriptor
# language code from ISO 639-2 lowercase
$short_descriptor->{language_code} = 'sr-SP';
# define codepage according to Annex.2 of EN 300 468 - Latin 2
$short_descriptor->{codepage_prefix} = "\x10\x00\x05";
$short_descriptor->{event_name} = $rawEvent->{title}{content}; <-----line 213
$short_descriptor->{text} = $rawEvent->{"sub-title"}{content} || "";
push( @descriptors, $short_descriptor);

my $extended_descriptor;
$extended_descriptor->{descriptor_tag} = 0x4e; # extended event descriptor
$extended_descriptor->{language_code} = 'sr-SP';
$extended_descriptor->{codepage_prefix} = "\x10\x00\x05";
$extended_descriptor->{text} = $rawEvent->{desc}{content};
push( @descriptors, $extended_descriptor);

$event->{descriptors} = \@descriptors;

$epg->addEvent( $event)



Laurent_R
Veteran / Moderator

Feb 7, 2016, 11:31 PM

Post #2 of 7 (2200 views)
Re: [zaca011] cherryEPG [In reply to] Can't Post

Hi,
the error is on $rawEvent->{title}{content}, which Perl does not recognizes as a hash reference.

Your are not showing how $rawEvent or %rawEvent or @rawEvent (or whatever) is populated, so it is not possible to tell you how to fix that.

My best guess would be %rawEvent might be a hash of hashes and therefore to tell you to perhaps try $rawEvent{title}{content}, but that's just shooting in the dark.


zaca011
New User

Feb 8, 2016, 1:30 AM

Post #3 of 7 (2190 views)
Re: [Laurent_R] cherryEPG [In reply to] Can't Post

hi,

thanks for replay
here is part of the code that refers to the import xml.
Code

Code
sub importXmlTv {  
my $epg = shift;
my $filename = shift;

use XML::Simple;

my $xml = XMLin( $filename, KeepRoot => 1);

my $schedule = $xml->{tv}{programme};

foreach my $rawEvent ( @$schedule) {
my $event;

# take the title

# the start and stop
$rawEvent->{start} =~ m/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/;
my @t = ( $6, $5, $4, $3, $2 - 1, $1 );
$event->{start} = timelocal(@t);

$rawEvent->{stop} =~ m/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/;
@t = ( $6, $5, $4, $3, $2 - 1, $1 );
$event->{stop} = timelocal(@t);

if( $rawEvent->{channel} eq "NameCh") {
$event->{uid} = 2;
}
else {
die( "Unknown service name: $rawEvent->{channel}");
}

my @descriptors;
my $short_descriptor;
$short_descriptor->{descriptor_tag} = 0x4d; # short event descriptor
# language code from ISO 639-2 lowercase
$short_descriptor->{language_code} = 'sr';
# define codepage according to Annex.2 of EN 300 468 - Latin 2
$short_descriptor->{codepage_prefix} = "\x10\x00\x02";
$short_descriptor->{event_name} = $rawEvent->{title}{content}; ------line 213 error hash
$short_descriptor->{text} = $rawEvent->{"sub-title"}{content} || "";
push( @descriptors, $short_descriptor);

my $extended_descriptor;
$extended_descriptor->{descriptor_tag} = 0x4e; # extended event descriptor
$extended_descriptor->{language_code} = 'sr';
$extended_descriptor->{codepage_prefix} = "\x10\x00\x02";
$extended_descriptor->{text} = $rawEvent->{desc}{content};
push( @descriptors, $extended_descriptor);

$event->{descriptors} = \@descriptors;

$epg->addEvent( $event);
}

return 1;
}



(This post was edited by Laurent_R on Feb 8, 2016, 4:40 AM)


Laurent_R
Veteran / Moderator

Feb 8, 2016, 4:43 AM

Post #4 of 7 (2161 views)
Re: [zaca011] cherryEPG [In reply to] Can't Post

Hi,

I have edited your post to add the code tags, in order to make the code more readable.

Cheers,
Laurent.


BillKSmith
Veteran

Feb 9, 2016, 5:46 AM

Post #5 of 7 (2127 views)
Re: [zaca011] cherryEPG [In reply to] Can't Post

You would not reach #213 if $rawEvent were not a hash reference. The problem must be in the data itself. I recommend that you trap the error and dump the offending data structure.

Temporarily replace line 213 with:

Code
#$short_descriptor->{event_name} = $rawEvent->{title}{content}; #------line 213 error hash  
$short_descriptor->{event_name} = eval{$rawEvent->{title}{content}};
if ($@) {
use Data::Dumper;
print Dumper(\$rawEvent);
die $@;
}


Post the output of Dumper.
Good Luck,
Bill


zaca011
New User

Feb 10, 2016, 1:25 AM

Post #6 of 7 (2095 views)
Re: [BillKSmith] cherryEPG [In reply to] Can't Post

Hi Bill
thanks for reply.
this is the output


Code
Importing Comedy-xmltv.xml 
$VAR1 = \{
'channel' => 'Comedy',
'credits' => {
'director' => "D\x{17e}on Krauli",
'actor' => [
'Silijen Marfi',
'Kolm Mini',
'Keli MekDonald'
]
},
'start' => '20160210090100 +0100',
'desc' => {
'content' => "
Prekid je urbana ljubavna pri\x{10d}a o otu\x{111}enim ljudima i njihovim krivudavim putevima u potrazi za nekom vrstom ljubavi. Kada beznade\x{17e}no nesiguran i emotivno neartikulisani D\x{17e}on raskine sa Diedri, da bi je stavio na \"malu probu\", plan mu se obija o glavu, ostavljaju\x{107}i nju slomljenog srca a njega samog i nesre\x{107}nog. Igrom slu\x{10d}aja, njihov raskid pokre\x{107}e lavinu ljudi oko njih...
",
'lang' => 'sr'
},
'stop' => '20160210104300 +0100',
'title' => [
{
'content' => 'Prekid',
'lang' => 'sr'
},
{
'content' => 'Intermission',
'lang' => 'orig'
}
]
};
Not a HASH reference at ./cherryEPG.pl line 214.



BillKSmith
Veteran

Feb 10, 2016, 4:16 AM

Post #7 of 7 (2077 views)
Re: [zaca011] cherryEPG [In reply to] Can't Post

$rawEvent{title} refers to an array of hashes, not a single hash. If you want the first of them ('Prekid'), you could use:

Code
$short_descriptor->{event_name} = $rawEvent->{title}[0]{content};


Otherwise, you will have to specify what data you need to keep.
Good Luck,
Bill

 
 


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

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