CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Item from database



Jun 26, 2001, 2:28 AM

Post #1 of 3 (412 views)
Item from database Can't Post

Hi Folks,

My database looks like this

2004|Computers~Software~Html Editors|Coffee Cup Html Editor|ccup.jpg| etc, etc..

What I'm looking for is a way to display my categories down to that third level.

rGeoffrey, in the past gave me this code to sort and display my single level categories, ie 'Computers' to html with a link to that category

open(ARRAY, "../Data_files/") || &eg_error(array);
@data = <ARRAY>;
my %hash;
foreach (@data) {
my $category = (split ('\|', $_))[1];
$hash{$category} = 1 unless (exists ($hash{$category}));
my @links = map { '<a href="%%sc_link%%&product=' . "$_\">$_</a>\n" } sort keys %hash;
print @links;

Is there some way to pick up on that last part of my category only. In my database above, it would be 'Html Editors' that I am looking to link.

I've tried for the last couple of days with no success so I thought I would ask for some help here...


Enthusiast / Moderator

Jun 26, 2001, 3:08 AM

Post #2 of 3 (410 views)
Re: Item from database [In reply to] Can't Post


you only want the last part of the category field in your hash table? Try this:

my $category = (split '~', (split '\|', $_)[1])[-1];

instead of

my $category = (split ('\|', $_))[1];

This will put only 'Html Editors' (always the last item, no matter how many there are) into $category.
Hope I got you right and this helps.

-- Marcus


Jun 26, 2001, 10:05 AM

Post #3 of 3 (402 views)
Re: Item from database [In reply to] Can't Post

Hi Marcus,

Thanks for the quick reply this morning, I had to leave just after I posted.

Worked like a champ, the switch you made. Sort of knew there had to be a double split function but from the reading I've done, it just didn't click to do it in the same line. Won't go into what I tried...

Again, thanks for the code.



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

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