For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > November 2004 > newbie question. Please help!









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author newbie question. Please help!
L. Hao

2004-11-29, 4:05 pm

Hello, I am new to Perl. What I am trying to do is to get and parse the
result of a system function execution. But I am not sure how to do it.

The system function is the file comparison, cmp, i.e.
system(" cmp -xl $file1 $file2") && die "failed"

If the file1 and file2 are not identical, cmp returns the detailed
differences by bytes. What do I need to do to get this results and parse
them in Perl? To be specific about parsing, I'd like to get the index of
differences.

Thanks a lot.

Li


Jürgen Exner

2004-11-29, 4:05 pm

L. Hao wrote:
> Hello, I am new to Perl. What I am trying to do is to get and parse
> the result of a system function execution.


You should read the documentation for the functions you are using.
The third paragraph of 'perldoc -f system' describes how to get the actual
exit value of the program executed by system() as well as how to capture the
output of the program executed by system().

> The system function is the file comparison, cmp, i.e.
> system(" cmp -xl $file1 $file2") && die "failed"
>
> If the file1 and file2 are not identical, cmp returns the detailed
> differences by bytes. What do I need to do to get this results and
> parse them in Perl? To be specific about parsing, I'd like to get the
> index of differences.


You will have to show us the detailed format, then we may be able to show
you how to parse it.
But chances are that it will involve some form of split() or Text::CSV.

jue


Leon

2004-11-29, 4:05 pm

"L. Hao" <lhao@NOSPAMcomcast.net> wrote in message
news:SBeqd.108661$5K2.58365@attbi_s03...
> Hello, I am new to Perl. What I am trying to do is to get and parse the
> result of a system function execution. But I am not sure how to do it.
>
> The system function is the file comparison, cmp, i.e.
> system(" cmp -xl $file1 $file2") && die "failed"
>
> If the file1 and file2 are not identical, cmp returns the detailed
> differences by bytes. What do I need to do to get this results and parse
> them in Perl? To be specific about parsing, I'd like to get the index of
> differences.
>
> Thanks a lot.
>
> Li
>
>


Try ...

@Result = `cmp -xl $file1 $file2`;

....then just treat as normal array.


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com