newbie question. Please help!

L

L. Hao

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

Jürgen Exner

L. Hao said:
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
 
L

Leon

L. Hao said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top