Maxim has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use CGI ':standard'; use XML::Simple; use Data::Dumper; #Variables my $newval = '200'; my $var1; my $oldval = '200'; my $prodid = '8080'; my $temps; print header; my $arrays = [qw/content subcategory packaging_qty recipe descript +ion product paragraph comments channel brand conditionning product_id + heading photo/]; my $cat = (<DATA>); my $category = XMLin( $cat, keyattr => 1, forcearray => $arrays); print Dumper($category); print "<html><body>Yes work\n"; foreach my $subcategory (@{$category->{'subcategory'}}) { foreach my $product (@{$subcategory->{'product'}}) { foreach my $product_id (@{$product->{'product_id'}}) { if ($product_id eq $prodid) { foreach my $conditionning (@{$product->{'condition +ning'}}) { foreach my $content (@{$conditionning->{'conte +nt'}}) { #$temps = $conditionning; if ($content eq $oldval) { $content = $newval; XMLout($category, xmldecl => '<?xml version="1.0"?><?xml-stylesheet ty +pe="text/xsl" href="Adminproduct.xsl"?>', rootname =>'category', outp +utfile =>('C:\Program Files\Apache Group\Apache2\htdocs\legastronome\ +XML\Admin\test9.xml')); print"<br><h3>All done!</h3>"; print "</body></html>\n"; exit 1; } else { print "$temps" } } } } } } }
I have check my data structure it seems to be fine. I don't know what the problem.<category name="Coffee"> <heading>150 years of know how at the service of a same strategy: +Taste</heading> <photo>images/bag_legal.jpg</photo> <subcategory name="Prestige"> <photo>images/prestige.jpg</photo> <product>Coffee <brand>33</brand> <channel>D</channel> <channel>A</channel> <conditionning unit="gr">250</conditionning> <description>aaaa</description> <packaging_qty>12</packaging_qty> <product_id>8080</product_id> <recipe>/recipes/coffee1.html</recipe> </product> </subcategory> </category>
Janitored by Arunbear - moved readmore tags outside the code block
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Can't use string as an ARRAY
by PodMaster (Abbot) on Oct 02, 2004 at 11:13 UTC | |
by Maxim (Sexton) on Oct 02, 2004 at 11:41 UTC | |
by Maxim (Sexton) on Oct 03, 2004 at 01:26 UTC | |
by PodMaster (Abbot) on Oct 03, 2004 at 10:38 UTC | |
by Maxim (Sexton) on Oct 04, 2004 at 07:22 UTC | |
|
Re: Can't use string ("250") as an ARRAY ref while "strict
by TedPride (Priest) on Oct 03, 2004 at 22:26 UTC |