Creating a generic hash

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Creating a generic hash

Joel Davidson
I'm still trying to read a data file on startup and have the info in a
hash for use by my html generator.  Here's the code I'm trying to use:

---------------------------------------
$genre_list = new Generic_Item;
my ($genre, $genre_descr, $genre_filename);

if ($Startup) {
   # clear out hash
   $genre_list = ();
   $genre_filename = $config_parms{movie_info_dir} . "/" .
                     $config_parms{movie_genre_list};
   if (!open(GENRE_LIST, "<", $genre_filename)) {
     print_log "movie_base.pl: error opening genre file $genre_filename";
     }
   else {
     while ($genre = <GENRE_LIST>) {
       if (substr($genre, 0, 1) eq '#') { $genre = <GENRE_LIST>; }
       chop($genre);
       ($genre, $genre_descr) = split "\"", $genre;
       $genre =~ s/\s+$//;
       $genre_list{$genre} = $genre_descr;
       }
     close (GENRE_LIST);
     }
   }
---------------------------------------

When I fire up mh, I get:
01/25/06 10:07:19 PM Oops1: Variable "%genre_list" is not imported at (eval 382) line 4858.

Error in user code file /home/hac/mh/data/mh_temp.user_code

01/25/06 10:07:19 PM:
01/25/06 10:07:19 PM Oops1: Variable "%genre_list" is not imported at (eval 382) line 4858.
Global symbol "%genre_list" requires explicit package name at (eval 382) line 4858.

Where line 4858 is $genre_list{$genre} = $genre_descr;

I've tried creating $genre_list as a new Generic_Item_Hash, but I get the
same error.  Anyone have any ideas on how to create a hash I can access
elsewhere?  Thanks.

Joel
--
Joel Davidson
Austin, TX


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
________________________________________________________
To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Creating a generic hash

Winston Gadsby


--- Joel Davidson <[hidden email]> wrote:

> I'm still trying to read a data file on startup and
> have the info in a
...


> if ($Startup) {
>    # clear out hash
>    $genre_list = ();

Instead, try

     %genre_list = ();

%genre_list and $genre_list are two different
variables.  $genre_list{item} references %genre_list.
You might need to use something like

     use vars %genre_list;

to export it elsewhere.  I'm not certain of the syntax
there.


>    $genre_filename = $config_parms{movie_info_dir} .
> "/" .
>                    
> $config_parms{movie_genre_list};
>    if (!open(GENRE_LIST, "<", $genre_filename)) {
>      print_log "movie_base.pl: error opening genre
> file $genre_filename";
>      }
>    else {
>      while ($genre = <GENRE_LIST>) {
>        if (substr($genre, 0, 1) eq '#') { $genre =
> <GENRE_LIST>; }
>        chop($genre);
>        ($genre, $genre_descr) = split "\"", $genre;
>        $genre =~ s/\s+$//;
>        $genre_list{$genre} = $genre_descr;
>        }
>      close (GENRE_LIST);
>      }
>    }
> ---------------------------------------
>
> When I fire up mh, I get:
> 01/25/06 10:07:19 PM Oops1: Variable "%genre_list"
> is not imported at (eval 382) line 4858.
>
> Error in user code file
> /home/hac/mh/data/mh_temp.user_code
>
> 01/25/06 10:07:19 PM:
> 01/25/06 10:07:19 PM Oops1: Variable "%genre_list"
> is not imported at (eval 382) line 4858.
> Global symbol "%genre_list" requires explicit
> package name at (eval 382) line 4858.
>
> Where line 4858 is $genre_list{$genre} =
> $genre_descr;
>
> I've tried creating $genre_list as a new
> Generic_Item_Hash, but I get the
> same error.  Anyone have any ideas on how to create
> a hash I can access
> elsewhere?  Thanks.
>
> Joel
> --
> Joel Davidson
> Austin, TX
>
>
>
-------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do
> you grep through log files
> for problems?  Stop!  Download the new AJAX search
> engine that makes
> searching your log files as easy as surfing the
> web.  DOWNLOAD SPLUNK!
>
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
>
________________________________________________________
> To unsubscribe from this list, go to:
> http://sourceforge.net/mail/?group_id=1365
>
>


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com 


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
________________________________________________________
To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Creating a generic hash

Joel Davidson
Well, defining $genre_list as a Generic_Item is supposed to define it
as a global, so the use vars ... is redundant.  The problem seems to
be that $genre_list isn't being defined as a hash correctly.  It gets
recognized as being a hash when I go to use it, but it's not getting
defined as one.  Thanks for the suggestions, though.  I know we'll
figure it out in time...

Until then, I'm still confused.

Joel

On Thu, 26 Jan 2006, it would appear that Winston Gadsby wrote:

> --- Joel Davidson <[hidden email]> wrote:
>
>> I'm still trying to read a data file on startup and
>> have the info in a
> ...
>
>
>> if ($Startup) {
>>    # clear out hash
>>    $genre_list = ();
>
> Instead, try
>
>     %genre_list = ();
>
> %genre_list and $genre_list are two different
> variables.  $genre_list{item} references %genre_list.
> You might need to use something like
>
>     use vars %genre_list;
>
> to export it elsewhere.  I'm not certain of the syntax
> there.
>
>
>>    $genre_filename = $config_parms{movie_info_dir} .
>> "/" .
>>
>> $config_parms{movie_genre_list};
>>    if (!open(GENRE_LIST, "<", $genre_filename)) {
>>      print_log "movie_base.pl: error opening genre
>> file $genre_filename";
>>      }
>>    else {
>>      while ($genre = <GENRE_LIST>) {
>>        if (substr($genre, 0, 1) eq '#') { $genre =
>> <GENRE_LIST>; }
>>        chop($genre);
>>        ($genre, $genre_descr) = split "\"", $genre;
>>        $genre =~ s/\s+$//;
>>        $genre_list{$genre} = $genre_descr;
>>        }
>>      close (GENRE_LIST);
>>      }
>>    }
>> ---------------------------------------
>>
>> When I fire up mh, I get:
>> 01/25/06 10:07:19 PM Oops1: Variable "%genre_list"
>> is not imported at (eval 382) line 4858.
>>
>> Error in user code file
>> /home/hac/mh/data/mh_temp.user_code
>>
>> 01/25/06 10:07:19 PM:
>> 01/25/06 10:07:19 PM Oops1: Variable "%genre_list"
>> is not imported at (eval 382) line 4858.
>> Global symbol "%genre_list" requires explicit
>> package name at (eval 382) line 4858.
>>
>> Where line 4858 is $genre_list{$genre} =
>> $genre_descr;
>>
>> I've tried creating $genre_list as a new
>> Generic_Item_Hash, but I get the
>> same error.  Anyone have any ideas on how to create
>> a hash I can access
>> elsewhere?  Thanks.
>>
>> Joel
>> --
>> Joel Davidson
>> Austin, TX


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
________________________________________________________
To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Creating a generic hash

Joel Davidson
In reply to this post by Joel Davidson
Sometimes it's nice to be able to answer your own questions, once you
get enough prodding from others.

Winston, you were on the right track this morning.  I took a look in
mh/bin/mh to see how the config_parms were defined, since that's a
global hash also.

use vars qw(%genre_list);

did it.

You were right that $genre_list = (); needed to be changed to
%genre_list = ();

Thanks for your help.  I might actually get mh talking to my dvd changer
yet.  :)

Joel


On Thu, 26 Jan 2006 I wrote:

> Well, defining $genre_list as a Generic_Item is supposed to define it
> as a global, so the use vars ... is redundant.  The problem seems to
> be that $genre_list isn't being defined as a hash correctly.  It gets
> recognized as being a hash when I go to use it, but it's not getting
> defined as one.  Thanks for the suggestions, though.  I know we'll
> figure it out in time...
>
> Until then, I'm still confused.
>
> Joel
>
> On Thu, 26 Jan 2006, it would appear that Winston Gadsby wrote:
>
> > --- Joel Davidson <[hidden email]> wrote:
> >
> >> I'm still trying to read a data file on startup and
> >> have the info in a
> > ...
> >
> >
> >> if ($Startup) {
> >>    # clear out hash
> >>    $genre_list = ();
> >
> > Instead, try
> >
> >     %genre_list = ();
> >
> > %genre_list and $genre_list are two different
> > variables.  $genre_list{item} references %genre_list.
> > You might need to use something like
> >
> >     use vars %genre_list;
> >
> > to export it elsewhere.  I'm not certain of the syntax
> > there.
> >
> >
> >>    $genre_filename = $config_parms{movie_info_dir} .
> >> "/" .
> >>
> >> $config_parms{movie_genre_list};
> >>    if (!open(GENRE_LIST, "<", $genre_filename)) {
> >>      print_log "movie_base.pl: error opening genre
> >> file $genre_filename";
> >>      }
> >>    else {
> >>      while ($genre = <GENRE_LIST>) {
> >>        if (substr($genre, 0, 1) eq '#') { $genre =
> >> <GENRE_LIST>; }
> >>        chop($genre);
> >>        ($genre, $genre_descr) = split "\"", $genre;
> >>        $genre =~ s/\s+$//;
> >>        $genre_list{$genre} = $genre_descr;
> >>        }
> >>      close (GENRE_LIST);
> >>      }
> >>    }
> >> ---------------------------------------
> >>
> >> When I fire up mh, I get:
> >> 01/25/06 10:07:19 PM Oops1: Variable "%genre_list"
> >> is not imported at (eval 382) line 4858.
> >>
> >> Error in user code file
> >> /home/hac/mh/data/mh_temp.user_code
> >>
> >> 01/25/06 10:07:19 PM:
> >> 01/25/06 10:07:19 PM Oops1: Variable "%genre_list"
> >> is not imported at (eval 382) line 4858.
> >> Global symbol "%genre_list" requires explicit
> >> package name at (eval 382) line 4858.
> >>
> >> Where line 4858 is $genre_list{$genre} =
> >> $genre_descr;
> >>
> >> I've tried creating $genre_list as a new
> >> Generic_Item_Hash, but I get the
> >> same error.  Anyone have any ideas on how to create
> >> a hash I can access
> >> elsewhere?  Thanks.
> >>
> >> Joel
> >> --
> >> Joel Davidson
> >> Austin, TX


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
________________________________________________________
To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365

Loading...