Gossamer Forum
Home : General : Perl Programming :

Parse information

Quote Reply
Parse information
Inside a script I have the folllowing code:

@cats = split(/\|/, $infodata[1]);
$catline = "";
$caturl = "";
foreach $pcats(@cats) {
$catline .= "$pcats, ";
$caturl = qq|<A HREF=\"$pcats.html\">$catline</A>|;
}
chop($catline);
chop($caturl);

The cats @cats are a string seperated by commas like so - auto, truck, power-sports, motorsport, etc., Right now it is returning the last cateogry in the string e.g. <A HREF="motorsport.html">thestring</A> but instead I want it to print out each cat by splitting it at the comma and then spit out the corresponding URL.

Thanks for your help.

Quote Reply
Re: [socrates] Parse information In reply to
Hi,

This what you mean?

Code:
my @cats;
foreach my $pcats (split /\|/, $infodata[1]) {
push @cats, qq|<a href="$pcats.html">$catline</a>|;
}
my $caturl = join( ",", @cats );

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!

Last edited by:

Andy: May 14, 2010, 12:29 AM
Quote Reply
Re: [Andy] Parse information In reply to
Thanks Andy, but I want it to print $caturl for each category as I showed above.
Shold that be $caturl = qq|...|; ?
Quote Reply
Re: [socrates] Parse information In reply to
Ah ok - what about the above code? (I've edited it)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Parse information In reply to
Ok, now it is only printing commas like so (,,,) instead of the categories and also those commas are only text (not links).

Thanks!

Last edited by:

socrates: May 14, 2010, 8:38 PM
Quote Reply
Re: [socrates] Parse information In reply to
Ah whoops - try this:

Code:
push @cats, qq|<a href="$pcats.html">$pcats</a>|;

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Parse information In reply to
Yes, that worked - Thanks, Andy!