Maxim has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,
I have this error error not "well-formed (invalid token)". I am a If.elsif.Else. I have to debug but I fail. Can you please help me to debug.
Here my code:
use strict; use CGI ':standard'; use XML::Simple; use Data::Dumper; #Variables my $newval = 'Max'; my $categor = 'Vinegars'; my $oldval = 'Martin Pouret'; my $prodid = '600.54.01'; my $cats; if ($categor eq 'Coffee') { my $cat = (<DATA>); } elsif ($categor eq 'Vinegars') { $cats = (<DATA>); print "Hello world"; #exit 1; } elsif ($categor eq 'Seafood') { my $cat = (<DATA>); } elsif ($categor eq 'Pate') { my $cat = (<DATA>); } elsif ($categor eq 'Mustard') { my $cat = (<DATA>); } else { print "Sorry the category that you wanted to edited doesn' +t exist. Please contact your administrator. \n Thanks"; print "No data will be print"; exit 1; } my $cat = $cats; my $arrays = [qw/subcategory packaging_qty recipe descript +ion product paragraph comments channel brand conditionning product_id + heading photo/]; my $category = XMLin($cat, keyattr => 1, forcearray => $ar +rays); print Dumper($category)
Here data
===DATA=== <category name="Vinegars"> <subcategory name="Range Martin Pouret"> <comments><paragraph>Gourmet vinegar for Connoisseurs. Vin +egar as it was once and always should be!</paragraph></comments> <photo>images/vinegars.jpg</photo> <product>Vinegar <channel>D</channel> <channel>S</channel> <product_id>600.54.01</product_id> <brand>Martin Pouret</brand> <description>Red wine vinegar old reserve</description +> <conditionning unit="ml">500</conditionning> <packaging_qty>6</packaging_qty> </product> </subcategory> </category>

Thanks Maxim

Replies are listed 'Best First'.
Re: not well-formed (invalid token)
by Prior Nacre V (Hermit) on Oct 04, 2004 at 07:51 UTC

    Looks like a cut-n-paste error :-)

    In the four places that you have:

    my $cat = (<DATA>);

    Change it to:

    $cats = (<DATA>);

    Regards,

    PN5

      It won't work what you suggest but I found the error from a FAQ. It is from the encoding declaration. XML::SIMPLE doesn't like this:
      <?xml version='1.0' encoding="iso-8859-1"?>

      But he likes this:
      <?xml version='1.0' encoding='iso-8859-1'?> or <?xml version="1.0" encoding='iso-8859-1'?>

      Very tricky. Becareful of the encoding guys

        I'm not sure if you're aware of the pointless processing occurring at these four lines. The data assigned to $cat are immediately lost because this variable immediately goes out of scope. This may not be a typo, as I suggested, but it is definitely an issue you should address.

        The problem you describe with XML::Simple indicates non-conformance with the published XML Specification. If you are absolutely certain about this, consider advising the module's author(s).

        Regards,

        PN5

Re: not well-formed (invalid token)
by cLive ;-) (Prior) on Oct 04, 2004 at 07:28 UTC
    Are you mis-spelling conditioning?

    cLive ;-)

    ps - I hope the my $cat is just a snippet - otherwise you have the variable too tightly scoped :)

      No, it is like this. The cause of the error is not because of the mis-spelling. :P
      my $cat is to get the info of the variable $cats which holds the path and the file.