A. Sinan Unur said:
Then you need to specify the problem a little better. For example, given
the input below, what output would you like your program to produce?
I would like the program to tell me which number is different. Each
number represents a unique number to a physical server.
Please do read the posting guidelines to find out how you can help others
help you.
You will need to better describe what you are trying to do and make an
effort yourself if you are to get the maximum possible help here.
Basically, the numbers that I produced below where parsed from a log
file.
EXAMPLE:
<Endpoint ep='10.50.19.77:9876'>
<SoapVersion>1207553365</SoapVersion>
<Status>ok</Status>
</Endpoint>
</Control>
<Control>
<Endpoint ep='10.15.19.78:9876'>
<SoapVersion>1207553365</SoapVersion>
<Status>ok</Status>
</Endpoint>
</Control>
<Control>
<Endpoint ep='10.15.19.79:9876'>
<SoapVersion>1207553365</SoapVersion>
<Status>ok</Status>
</Endpoint>
This is the code I used to parse it:
my $start_tag = '<SoapVersion>';
my $end_tag = '</SoapVersion>';
open(FILE, '/tmp/test.whatever') || die "can't open the file: $!";
my $line = <FILE>;
while(defined ( $line = <FILE> ) ) {
if ( $line =~ m/$start_tag(.+?)$end_tag/g )
99% of the time all these numbers are identical, when one is different
from the other, I want Perl to tell me that.
Here is something that might do what you are after. Please study it (not
as a great example of programming) to try and understand in what ways it
meets your specs, and in what ways it doesn't, and then formulate your
next attempt based on that new understanding.
I'm in the process of studying your example, thank you.
#! /usr/bin/perl
use strict;
use warnings;
if(defined(my $prev = <DATA>)) {
chomp($prev);
while(defined(my $curr = <DATA>)) {
chomp $curr;
Can you explain to me what 'last unless length $curr' ????
last unless length $curr;
unless($curr == $prev) {
print "$.: $curr not equal to $prev\n";
$prev = $curr;
}
}
}
__END__
1207553365
1207553365
1207553365
1207553365
1207553365
1207553365
1207553365
1207553366
1207553365
Sinan
I want to learn from you guys, thanks in advance.