On Thu, Aug 16, 2012 at 04:55:33AM -0700, Irfan Sayed wrote:
> hi,
> 
> i need to parse the xml file and store the data in array :
> 
> here is the code:
> use XML::Simple;
> 
> my $ItemGroup = XMLin('C:\Users\bvcontrolbuild\Desktop\data.xml');
> 
> foreach my $BuildProject (@{$ItemGroup->{BuildProject}}) {
>     print $BuildProject->{Include} . "\n";
> }
> 
> 
> and xml file is : 
> 
> 
>  <ItemGroup>
> 
>     <BuildProject Include="AssemblyInfo.csproj" />
>     <BuildProject Include="Assembly.csproj" />
> 
>   </ItemGroup>
> 
> but when i compile the code, it throws the error : "Not an ARRAY reference"'
> 
> i need output in array : @a = (AssemblyInfo.csproj,Assembly.csproj);
> please suggest 
> 
> 

Hi Irfan

1.  I see no 
    use strict; 
    use warnings; 
    in your code.  If you are not using them please do so, as they will give
    syntax errors and warnings about your code.

2.  use Data::Dumper; 
    and then 
    print Dumper($ItemGroup);
    will show the data structure returned by XMLin.

FWIW I got 

$VAR1 = {
          'BuildProject' => [
                            {
                              'Include' => 'AssemblyInfo.csproj'
                            },
                            {
                              'Include' => 'Assembly.csproj'
                            }
                          ]
        };

AssemblyInfo.csproj
Assembly.csproj

from

#!/usr/bin/env perl

use Modern::Perl 2011;
use autodie;

use strict;
use warnings;

use XML::Simple;
use Data::Dumper;
 
 my $ItemGroup = XMLin('./data.xml');

 say Dumper($ItemGroup);
 
 foreach my $BuildProject (@{$ItemGroup->{BuildProject}}) {
   say $BuildProject->{Include};
 }

Kind Regards

Lesley

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to