List Info

Thread: Categories and sub categories??




Categories and sub categories??
country flaguser name
United States
2007-09-19 23:05:04


I need to be able to print a list a categories to screen, then after each category, a list of
sub categories. I'm printing the categroies and I'm trying to reference the sub categories
by attaching "_categories" to $cat but it's not working.
Any help is appreciated.

foreach $cat (categories){
print qq~<a href=";index.cgi?search_and_display_db_button=on&site_category=$cat"&gt;See
ALL $cat</a> ~;

foreach $subcat($cat . "_categories&quot;){
print qq~ >>&lt;a href=";index.cgi?
search_and_display_db_button=on&site_category=$cat&site_subcat=$subcat&quot;>$subcat</
a> ~;
}
print qq~<BR&gt;~;
}

print qq~~;

categories = ("Shopping", "TheArts", "Education", "Lifestyle", "FamilyFun", "Media");

Shopping_categories = ("Arts_and_Crafts", "Audio_and_Video_Equipment", "Businesses";,
"Catalogs&quot;, "Computers_and_Software&quot;, "Gift_Ideas";, "Products", "Real_Estate&quot;, "Reviews",
"Stores");

TheArts_categories = ("Art", "Books", "Entertainment&quot;, "Film_and_Video&quot;, "Music",
"Performers&quot;, "Photography&quot;, "Writers");

Education_categories = ("Bible_Study&quot;, "Christian_Apologetics&quot;, "Colleges", "Counselling&quot;,
"Distance_Learning", "Evangelism";, "Finances", "Home_School&quot;, "Personal_Growth",
"Schools";, "Youth");

Lifestyle_categories = ("Children", "Churches", "Clubs", "E-Pen_Pals";,
"Health_and_Fitness&quot;, "Jobs", "Marriage", "Ministries";, "People", "Prayer", "Resumes",
"Singles";, "Teens", "Youth");

FamilyFun_categories = ("Camping", "Entertainment&quot;, "Family_Activities", "Games",
"Performers&quot;,";Pets", "Postcards", "Sports", "Travel");

Media_categories = ("Books", "Book_Reviews&quot;, "Computers_and_Software&quot;, "Extra",
"The_Listening_Room&quot;, "Misc_Reviews&quot;, "Music_Reviews&quot;, "Publishing";, "Radio",
"Television&quot;);

__._,_.___
.

__,_._,___
Re: Categories and sub categories??
country flaguser name
United States
2007-09-20 13:39:52

Fred,

--- In perl_advanced_programmming%40yahoogroups.com">perl_advanced_programmmingyahoogroups.com, "Fred Garvin&quot;
<ahqmed...> wrote:
&gt; I need to be able to print a list a categories to screen, then after
> each category, a list of sub categories. I'm printing the categroies
> and I'm trying to reference the sub categories by attaching
> "_categories&quot; to $cat but it's not working.
> Any help is appreciated.
>
> foreach $cat (categories){
> print qq~<a
href=";index.cgi?search_and_display_db_button=on&site_category=$cat"&gt;See
> ALL $cat</a> ~;
>
> foreach $subcat($cat . "_categories&quot;){
>; print qq~ >>&lt;a href=";index.cgi?

<snip>

If this is anything other than a quick & dirty run once program, you
may want to read this and re-consider:
http://perldoc.perl.org/perlfaq7.html#How-can-I-use-a-variable-as-a-variable-name%3f

If you really must do this, and you're not using the strict module and
the variables are global, then I believe you should be able to get
this to work by changing the line
foreach $subcat($cat . "_categories&quot;)
to
foreach $subcat({$cat . "_categories&quot;})

(I.e. put squiggle braces around the concatenation that you want to
turn into a variable name.)

Regards,

Matt

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )