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:
Item from database

 



six
stranger

Jun 26, 2001, 2:28 AM

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

Hi Folks,

My database looks like this
ID|Category|Headline|Image|Description|blah|blah

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

<pre>
open(ARRAY, "../Data_files/shopping.data") || &eg_error(array);
@data = <ARRAY>;
close(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;
</pre>

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...

Brad



mhx
Enthusiast / Moderator

Jun 26, 2001, 3:08 AM

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

Hi,

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

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

instead of

Code
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



six
stranger

Jun 26, 2001, 10:05 AM

Post #3 of 3 (390 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.

Brad


 
 


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

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