Gossamer Forum
Quote Reply
s///
Mmm...can anyone see why this isn't working?

$page =~ s/<Count>\d<\/Count>//g;

I'm trying to remove;

<Count>12</Count>

But for some reason, its just staying there! Is it something wrong with my format, or somewhere else in my script? I've been starting at this for a good hour, but still can't find the problem!

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] s/// In reply to
Never mind...I'm using XML::Simple now. Got a problem with how toi extract the data though. At the moment, I am getting a hash, with data that looks like this (from Data::Dumper);

Quote:
'Listing' => [
{
'Description' => 'We have a wide selection of puppy at low prices! Bird cages, dog crates, cat furniture, advantage, frontine, rabbit cages, ferret cages, and more! We\'re your "Pet Supply Online" provider!',
'Title' => 'puppy - Pet Supply Online',
'URI' => 'http://www.searchfeed.com/rd/Clk.jsp?id=5674117&r=7&source=8&p=5491&sid=513376&ex=1032016188601',
'Bid' => '0.05',
'URL' => 'www.petsupplyonline.com'
},
{
'Description' => 'The largest site on the internet with unique gifts for dog lovers features sculpture, embroidered pillows, afgan throws, jewelry pins&amp; charms, dog picures, doorstops, and cute plush dogs',
'Title' => 'Handcrafted gifts for Dog and Cat Lovers',
'URI' => 'http://www.searchfeed.com/rd/Clk.jsp?s=sp&k=puppy&lnk=687474703a2f2f737072696e6b732d636c69636b732e61626f75742e636f6d2f3f7265663d736561726368666565645f786d6c5f534b44266269643d39373830303936266c6e6b3d687474702533412532462532467777772e6c6f7665697361726f73652e636f6d7c302e3037&p=5491&sid=513376&ex=1032016188601',
'Bid' => '0.042000003',
'URL' => 'www.loveisarose.com'
},
{
'Description' => 'Dog toys, cat toys, puppy toys & supplies. Dog treats, grooming supplies. Seasonal and holiday items.',
'Title' => 'Fido\'s Toys - Quality dog and cat toys and supplies. Puppies too!',
'URI' => 'http://www.searchfeed.com/rd/Clk.jsp?id=4027277&r=5&source=8&p=5491&sid=513376&ex=1032016188601',
'Bid' => '0.04',
'URL' => 'www.fidostoys.com'
},
{
'Description' => 'DoctorDog.com provides quality pet care information and supplies for dogs and cats.',
'Title' => 'Dr. Dog Health Care and Pet Mart',
'URI' => 'http://www.searchfeed.com/rd/Clk.jsp?s=sp&k=puppy&lnk=687474703a2f2f737072696e6b732d636c69636b732e61626f75742e636f6d2f3f7265663d736561726368666565645f786d6c5f534b44266269643d33353731373736266c6e6b3d687474702533412532462532467777772e646f63746f72646f672e636f6d2532467c302e3035&p=5491&sid=513376&ex=1032016188601',
'Bid' => '0.030000001',
'URL' => 'www.doctordog.com'
},
{
'Description' => 'Pet doors in all shapes and sizes for use in doors, walls, windows, screens, patio doors plus electronic doors. Free catalog, free help line, and free tech support.',
'Title' => 'Buy pet doors at Pet Doors USA',
'URI' => 'http://www.searchfeed.com/rd/Clk.jsp?s=sp&k=puppy&lnk=687474703a2f2f737072696e6b732d636c69636b732e61626f75742e636f6d2f3f7265663d736561726368666565645f786d6c5f534b44266269643d32343237323838266c6e6b3d687474702533412532462532467777772e646f67646f6f72732e636f6d2532467c302e3035&p=5491&sid=513376&ex=1032016188601',
'Bid' => '0.030000001',
'URL' => 'www.dogdoors.com'
},
{
'Description' => 'GundogsOnline.com, is a FREE monthly Web publication dedicated to the promotion of the all gundog breeds. Monthly articles from the industry\'s leading outdoor writers, breeders and trainers.',
'Title' => 'Puppy - FINDat GundogsOnline.com',
'URI' => 'http://www.searchfeed.com/rd/Clk.jsp?id=2980566&r=2&source=8&p=5491&sid=513376&ex=1032016188601',
'Bid' => '0.03',
'URL' => 'www.gundogsonline.com'
},
{
'Description' => 'Spaniels Online, is a free monthly Web publication dedicated to the promotion of the field bred spaniel. Monthly articles from the industry\'s leading outdoor writers, breeders and trainers.',
'Title' => 'Spaniel Puppies Available Oct-Nov 2001',
'URI' => 'http://www.searchfeed.com/rd/Clk.jsp?id=4524395&r=6&source=16&p=5491&sid=513376&ex=1032016188601',
'Bid' => '0.03',
'URL' => 'www.spanielsonline.com'
},
{
'Description' => 'PetsWarehouse pet supply, our online mail order Pet Supply Catalog has Pet supplies for all your Pets needs. We carry more pet supplies than anyone else for your freshwater aquarium, African Cichlids, marine fish and reef aquarium fish, and Everything for',
'Title' => 'Everything for your pet',
'URI' => 'http://www.searchfeed.com/rd/Clk.jsp?id=5901013&r=9&source=8&p=5491&sid=513376&ex=1032016188601',
'Bid' => '0.03',
'URL' => 'www.petswarehouse.com'
},
{
'Description' => 'Dog and Cat pet doors from cat to dane sizes for doors, walls, windows, screens, patio doors plus electronic doors. Free Catalog, Free Help Line, Free Tech Support, Free yourself from doorman duty.',
'Title' => 'Online Pet Door Catalog',
'URI' => 'http://www.searchfeed.com/rd/Clk.jsp?id=3184592&r=3&source=8&p=5491&sid=513376&ex=1032016188601',
'Bid' => '0.02',
'URL' => 'www.dogdoors.com'
},
{
'Description' => 'Silken Windhounds are a small longhaired Sighthound, somewhat like a longhaired Whippet or miniature Borzoi. They are a rare breed, working on full recognition.',
'Title' => 'Internation Silken Windhound Society',
'URI' => 'http://www.searchfeed.com/rd/Clk.jsp?id=3883275&r=4&source=8&p=5491&sid=513376&ex=1032016188601',
'Bid' => '0.02',
'URL' => 'www.silkenwindhound.com'
},
{
'Description' => 'Puppy related gift and merchandise items.',
'Title' => 'Puppy Related Products',
'URI' => 'http://www.searchfeed.com/rd/Clk.jsp?id=256892&r=1&p=5491&sid=513376&ex=1032016188601',
'Bid' => '0.01',
'URL' => 'www.krittersinthemailbox.com'
},
{
'Description' => ' We have the most amazing dog t-shirts you have seen! Breathtaking color by serious and well-known artists. We love doggies. All profits to charity. Click on the image to find other styles.',
'Title' => 'Buy a Stunning Dog Shirt Online!',
'URI' => 'http://www.searchfeed.com/rd/Clk.jsp?id=5717351&r=8&source=8&p=5491&sid=513376&ex=1032016188601',
'Bid' => '0.01',
'URL' => 'www.ardithkeef.com'
}
]
};

I know I can call it via $ref->{Listings}, but the problem I am having, is how to seperate each of the sub-listings within that. Anyone got any ideas/suggestions?

Code:
my $ref = XMLin($page);
print Dumper($ref);
exit;

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] s/// In reply to
Your problem is the \d:

$page =~ s/<Count>\d<\/Count>//g;

You're telling it to match against only one digit. so "12" fails because that's two digits.

$page =~ s/<Count>\d+<\/Count>//g;

would fix that

[edit, mere seconds too late, after you responded to your self Smile]
--mark

Last edited by:

Mark Badolato: Sep 14, 2002, 8:17 AM
Quote Reply
Re: [Andy] s/// In reply to
Quote:
I know I can call it via $ref->{Listings}, but the problem I am having, is how to seperate each of the sub-listings within that. Anyone got any ideas/suggestions?

The data structure is not the best for this type of thing. You'd have to do something like:

Code:
foreach my $element (@{$ref->{Listing}}) {
print join "<br>", map { "$_ => $element->{$_}<br>" } keys %$element;
}

Or individually:

$ref->{Listing}->[element]->{key};

Last edited by:

Paul: Sep 16, 2002, 2:32 AM
Quote Reply
Re: [Paul] s/// In reply to
So, you are saying, something like;

$ref->{Listing}->[1]->{Title};

should work? I'm not sure if I'm quite clear about the 'element' part Tongue

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] s/// In reply to
Yeah that's right. Using your sample data above:

$ref->{Listing}->[1]->{Title} would print:

Handcrafted gifts for Dog and Cat Lovers

Last edited by:

Paul: Sep 16, 2002, 3:18 AM
Quote Reply
Re: [Paul] s/// In reply to
Ah..thanks :) I'll give that a go, and let you know how it goes.

BTW: This is for a SearchFeed.com live feed, to replace the BigWhat plugin...

Thanks again.

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!