#!/usr/bin/perl -- ## ## ## ## perltidy -olq -csc -csci=3 -cscl="sub : BEGIN END " -otr -opr -ce -nibc -i=4 -pt=0 "-nsak=*" #!/usr/bin/perl -- use strict; use warnings; use XML::LibXML 1.70; ## for load_html/load_xml/location my( $xml ) = q{0010110001001100}; RunWithIt( $xml ); exit( 0 ); sub RunWithIt { my $dom = XML::LibXML->new( qw/ recover 2 / )->load_xml( string => shift ); for my $reg ( $dom->findnodes( q{ //reg } ) ) { my $bitstr = FunWithIt( $reg ); my $bytes = BitsToBytes( $bitstr ); print "$bitstr The answer is $bytes\n"; } } ## end sub RunWithIt sub BitsToBytes { return pack 'b*', shift; } ## end sub BitsToBytes sub FunWithIt { my( $reg ) = @_; my $str = ''; for my $bit ( $reg->findnodes( q{ //bit } ) ) { $str .= $bit->findvalue( './/init_val' ); } return $str; } ## end sub FunWithIt