Hi Anirban,

On Thu, 15 Mar 2012 20:41:31 +0530
Anirban Adhikary <anirban.adhik...@gmail.com> wrote:

> I am writting a following code to parse this xml but not able yo understand
> that why the value of $bsc_id_1 getting changed.
> here is my code
> 
> use strict;
> use warnings;
> 
> my $xml_file_to_read = "BSC-19478.xml";
> my $counter = 1;
> my $bsc_id_1;
> my $bsc_id;
> open my $RFH,'<',$xml_file_to_read or die "Can't open $xml_file_to_read
> $!\n";
> 
> while(<$RFH>) {
>     chomp;
>     if (($bsc_id_1) = /<BSC id="(.*?)"/ and $counter == 1){
>         print "BSC1=[$bsc_id_1]\n";
>         next;
>     }
> 

[SNIP]

Please don't parse XML using regular expressions. Use an XML parser such as
http://search.cpan.org/dist/XML-LibXML/ (of which I took over the maintenance,
but I have used it beforehand, when it was maintained by other people), or a
similar parser (but please avoid XML::Simple). If the XML is not too large read
about its DOM (Document Object Model) capabilities and its XPath support.
 
Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
UNIX Fortune Cookies - http://www.shlomifish.org/humour/fortunes/

Skill without imagination is craftsmanship and gives us many useful objects
such as wickerwork picnic baskets.  Imagination without skill gives us modern
art.            — Tom Stoppard

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
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