System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

Need Help in writing PERL code for following -

 
Virat
Occasional Contributor

Need Help in writing PERL code for following -

Hi, I am opening a file whose original format is :
===============================================




USHER2K3FS02_POL
1/3/2008 11:29:14 PM
209
200
3607
1
0
0
0
79
10615
0
\\USHER2K3FS02\FS02$
\\USHER2K3FS02
1



USHER2K3FS02_POL
1/3/2008 11:03:28 PM
1546
200
1849461
70
0
0
0
2181
37835
0
\\USHER2K3FS02\FS01$
\\USHER2K3FS02
1


===============================================
But when I am trying to print samething via perl code, its giving different output :
Perl code is :

open BEXREPORT, " or Fatal ("Cannot open Backup Exec Report: $!");



foreach $line () {
chomp($line); # remove the newline from $line.
print "$line";

}
==============================================
Output is :


C:\test>perl xyz.pl
 ■< ? x m l v e r s i o n = " 1 . 0 " e n c o d i n g = " u t f - 1 6 " ? >
< P o l i c y N a m e > U S H E R 2 K 3 F S 0 2 _ P O L < / P o
< A c t u a l S t a r t T i m e > 1 / 3 / 2 0 0 8 1 1 : 2 9 :
< E l a p s e d T i m e S e c o n d s > 2 0 9 < / E l a p s e d
< D a t a S i z e K B y t e s > 3 6 0 7 < / D a t a S i z e K B
< H a s S k i p p e d F i l e s > 0 < / H a s S k i p p e d F i
< H a s C o r r u p t F i l e s > 0 < / H a s C o r r u p t F i
< H a s I n u s e F i l e s > 0 < / H a s I n u s e F i l e s >
< N u m b e r O f F i l e s > 7 9 < / N u m b e r O f F i l e s
< N u m b e r O f D i r e c t o r i e s > 1 0 6 1 5 < / N u m b
< R e s o u r c e N a m e > \ \ U S H E R 2 K 3 F S 0 2 \ F S 0
< S e r v e r N a m e > \ \ U S H E R 2 K 3 F S 0 2 < / S e r v
< R e s o u r c e T y p e I D > 1 < / R e s o u r c e T y p e I
< P o l i c y N a m e > U S H E R 2 K 3 F S 0 2 _ P O L < / P o
< A c t u a l S t a r t T i m e > 1 / 3 / 2 0 0 8 1 1 : 0 3 :
< E l a p s e d T i m e S e c o n d s > 1 5 4 6 < / E l a p s e
< D a t a S i z e K B y t e s > 1 8 4 9 4 6 1 < / D a t a S i z
< H a s S k i p p e d F i l e s > 0 < / H a s S k i p p e d F i
< H a s C o r r u p t F i l e s > 0 < / H a s C o r r u p t F i
< H a s I n u s e F i l e s > 0 < / H a s I n u s e F i l e s >
< N u m b e r O f F i l e s > 2 1 8 1 < / N u m b e r O f F i l
< N u m b e r O f D i r e c t o r i e s > 3 7 8 3 5 < / N u m b
< R e s o u r c e N a m e > \ \ U S H E R 2 K 3 F S 0 2 \ F S 0
< S e r v e r N a m e > \ \ U S H E R 2 K 3 F S 0 2 < / S e r v
< R e s o u r c e T y p e I D > 1 < / R e s o u r c e T y p e I
< / D a t a S e t > t D a i l y P o l i c y J o b s B y R e s o u r c e >
C:\test>
===============================================
Because of this I am not able to grep for something...and do further processing...
3 REPLIES
Stuart Browne
Honored Contributor

Re: Need Help in writing PERL code for following -

Your answer is right there on the first line:



You need to make sure that you're reading it in a unicode friendly mode. Something like:

use encoding utf16;
open ...

See the man pages for more (man perlunicode).

One long-haired git at your service...
Leonid Mishkind
Frequent Advisor

Re: Need Help in writing PERL code for following -

Try using the XML::Simple module for XML parsing. very simple and very useful.

Leonid.
dirk dierickx
Honored Contributor

Re: Need Help in writing PERL code for following -

i also propose to use the XML modules from perl, it's easy, reliable and fast.