Hi all, I have try to debug my script but I always got an error message: Can't use string ("250") as an ARRAY ref while "strict refs". I am tring to change a value in the element tags "conditionning".
Here the code
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" } } } } } } }
Here some data
<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>
I have check my data structure it seems to be fine. I don't know what the problem.
Thanks in advance.
Maxim

Janitored by Arunbear - moved readmore tags outside the code block


In reply to Can't use string ("250") as an ARRAY ref while "strict by Maxim

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.