CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
script not producing output

 



StaedarN
Novice

May 10, 2013, 6:07 AM

Post #1 of 15 (805 views)
script not producing output Can't Post

http://pastebin.com/UEys3gCF

The script is designed to compare memory dumps and list the amount of pages that differs (if I understand the author correctly). However it doesnt seem to want to produce any output, even if there are differences in the dumps. Would you guys have an Idea?


Laurent_R
Veteran / Moderator

May 10, 2013, 8:18 AM

Post #2 of 15 (798 views)
Re: [StaedarN] script not producing output [In reply to] Can't Post

Hi,

Can you please provide the exact command line that you used to launch this script?

And also show the test files that you used?


StaedarN
Novice

May 10, 2013, 8:53 AM

Post #3 of 15 (793 views)
Re: [Laurent_R] script not producing output [In reply to] Can't Post

This is the original script sent to me by the author(which I cant get a hold of): http://pastebin.com/FUr8dWgF.

I was instructed to insert the path to the files in my first$ and my $second (it is the same directory i launch the script from).

The command line statement is as follows: Compare.pl Windows7-Snapshot9.vmem Windows7-Snapshot13.vmem

As the files are both 1 gb each in size, I dont know if I should upload them, but I was told .vmem dumps from virtual machines was the intended files for use.

After the command is issued, the processor starts working, so I assume its going through the memory pages as intended. Ofcourse going through two 1gb files probably takes a long time, but if I understand the script correctly, its supposed to print some stuff once a page is confirmed to diff or not. Ive tried comparing some notepad documents with slight differences, but I still get no output whatsoever.


StaedarN
Novice

May 10, 2013, 9:03 AM

Post #4 of 15 (785 views)
Re: [StaedarN] script not producing output [In reply to] Can't Post

Oh and I should probably mention that the script was made for a linux machine, if that makes any difference


FishMonger
Veteran / Moderator

May 10, 2013, 9:30 AM

Post #5 of 15 (778 views)
Re: [StaedarN] script not producing output [In reply to] Can't Post


Quote
I still get no output whatsoever


So, it's not even outputting the print statement on line 16?


FishMonger
Veteran / Moderator

May 10, 2013, 9:45 AM

Post #6 of 15 (775 views)
Re: [StaedarN] script not producing output [In reply to] Can't Post

Since you're hard codding the filenames in the script, there's no need to pass then on the command line.

Did you try executing it like this:
Compare.pl diff indent verbose


StaedarN
Novice

May 11, 2013, 4:42 AM

Post #7 of 15 (760 views)
Re: [FishMonger] script not producing output [In reply to] Can't Post

precicely. Ive tried doing no command line statements aswell as the thing you suggested with the diff indent verbose.

The only print statement shown is the one that asks my "what files do u wish to compare" If I input invalid files(which arent of equal size for example).


FishMonger
Veteran / Moderator

May 11, 2013, 6:06 AM

Post #8 of 15 (754 views)
Re: [StaedarN] script not producing output [In reply to] Can't Post


Quote
The only print statement shown is the one that asks my "what files do u wish to compare"


The script you linked to doesn't have any such print statement, which clearly shows it's not the same script that you're testing.


StaedarN
Novice

May 11, 2013, 8:48 AM

Post #9 of 15 (748 views)
Re: [FishMonger] script not producing output [In reply to] Can't Post

uh, no not the link in the first post. I have linked the "original" in the second post. What im reffering to are the "or die" statements. Those are the only ones that have shown themselves while ive been fidling about.

I mean, the print statements from the while loop, dont show


FishMonger
Veteran / Moderator

May 11, 2013, 9:11 AM

Post #10 of 15 (746 views)
Re: [StaedarN] script not producing output [In reply to] Can't Post

Why are you doing this?

Code
print "... ".$#ARGV."\n"; 
if( $#ARGV >= 0 && $#ARGV < 2 )
{
$first = shift @ARGV;
$second = shift @ARGV;
print "$first .. $second \n";
} else {
die "What files do you want to compare?\n";
}

Instead of letting Getopt::Long handle those var assignments?


Quote
the print statements from the while loop, dont show

All of those print statements are inside conditional blocks and based on how you said you were executing the script, those conditionals will evaluate to false. So, there's no reason to expect the while loop to produce any output.

I'll take a closer look at the script and post back later with some suggestions.


FishMonger
Veteran / Moderator

May 11, 2013, 1:11 PM

Post #11 of 15 (730 views)
Re: [StaedarN] script not producing output [In reply to] Can't Post

I made a few adjustments. See if this works better.


Code
#!C:\Perl64\bin 

use strict;
use warnings;
use Getopt::Long;

my $first = "Windows7-Snapshot9.vmem";
my $second = "Windows7-Snapshot13.vmem";
my $verbose = 1; ## Any Debugging and other info
my $diff = 0; ## print all the pages with differences
my $ident = 0; ## Print all the pages which are identical
my $summary = 1; ## Print the statistical summary
my $size = 4096;
my $help = 0;

GetOptions( "help|?" => \$help,
"size=i" => \$size,
"verbose+" => \$verbose,
"diff" => \$diff,
"ident" => \$ident,
"summary" => \$summary,
"first|f=s" => \$first,
"second|s=s" => \$second,
) or die "Error in command line arguments\n";

unless (-e $first and -e $second) {
die "One of the required input files can't be found\n";
}

if( -s $first != -s $second )
{
die "Files are not of equal size. Can not proceed\n";
}

# Perl Best Practice is to use the 3 arg form of open
# and a lexical var for the filehandle instead of a bareword
open my $first_fh, '<', $first or die "Could not open: '$first' $!";
open my $second_fh, '<', $second or die "Could not open: '$second' $!";
#open FIRST, "< ".$first or die "Could not open: ".$first."\n";
#open SECOND, "< ".$second or die "Could not open: ".$second."\n";


my $wordcount = 0;
my $pagenumber = 0;
my $pagecount = 0;
my $diffcount = 0;
my $fline;
my $sline;


while( read( $first_fh, $fline, $size ) && read( $second_fh, $sline, $size ) )
{
print "Comparing $size bytes\n" if $verbose;

$pagenumber += $size ;
$pagecount++;

# why are youy using the square brackets in the unpack statements?
# I suspect that they are unneeded/unwanted
# my @fcmpare = unpack("C[$size]", $fline );
# my @scmpare = unpack("C[$size]", $sline );
my @fcmpare = unpack("C$size", $fline );
my @scmpare = unpack("C$size", $sline );

my $nodiff = 0;

# perl's for loop construct is cleaner and more efficient than the C style
for my $index (0..$size-1)
#for( $index = 0; $index < $size ; $index++)
{
# is your intension to apply a regex pattern match
# or did you mean to test for equality?
$nodiff++ if( $fcmpare[$index] !~ $scmpare[$index] )
# $nodiff++ if( $fcmpare[$index] !~ /$scmpare[$index]/ )
# $nodiff++ if( $fcmpare[$index] ne $scmpare[$index] )
}

$diffcount++ if $nodiff;

if( $nodiff && $diff )
{
printf("\n%d : %x : Differences found\n", $pagecount, $pagenumber);
}
elsif( $ident and not $nodiff)
{
printf("\n%d : %x : No Differences found\n", $pagecount, $pagenumber);
}

if( $verbose )
{
printf("Completed page %d : %x\n", $pagecount, $pagenumber);
}

}

if( $summary )
{
print '#' x 30, "\n",
"Total pages read = $pagecount \n",
"Total different pages found = $diffcount\n",
"Percentage Different = ".($diffcount / $pagecount * 100)."\n";
}

close $first_fh;
close $second_fh;



(This post was edited by FishMonger on May 11, 2013, 2:18 PM)


StaedarN
Novice

May 14, 2013, 11:45 PM

Post #12 of 15 (692 views)
Re: [FishMonger] script not producing output [In reply to] Can't Post

 if( $nodiff && $diff )
{
printf("\n%d : %x : Differences found\n", $pagecount, $pagenumber);
}
elsif( $ident and not $nodiff)
{
printf("\n%d : %x : No Differences found\n", $pagecount, $pagenumber);

This if statement is confusing me. (the script was given to me, I have no previous perl experience so bare with me, ive tried hard to understand)

If we start from the first looping, $nodiff should be evaluated to 1 if the strings match, while $diff should be 0 all the time (since it never changes right?) which means the first statement will allways be false (concidering the && operation). This begs the question, how anything will ever be evaluated as "differences found"?

[edit] Another thing im wondering about is the !~.This kinda means if string 1 is not string 2; return true, right? (so the $nodiff should maybe be named $diff for clarity?)

As u can see im kind of clueless :< sry. Apreciate the help anyways!


(This post was edited by StaedarN on May 15, 2013, 12:14 AM)


StaedarN
Novice

May 15, 2013, 12:19 AM

Post #13 of 15 (689 views)
Re: [FishMonger] script not producing output [In reply to] Can't Post

Use of uninitialized value within @scmpare in regexp compilation at C:\Perl64\bi
n\compare.pl line 73.
Completed page 131060 : 1fff4000
##############################
Total pages read = 131060
Total different pages found = 127668
Percentage Different = 97.4118724248436

Here is the output, when the script has gone through all the pages. It seems to be working (or is it really? thats alot of different pages) even though there is that error


StaedarN
Novice

May 15, 2013, 2:20 AM

Post #14 of 15 (684 views)
Re: [StaedarN] script not producing output [In reply to] Can't Post

Aahh. The author meant that I should set the $diff and $ident values to 1, if I wish to see them printed. But they dont actually come to play here as they are set to zero. Correct right?


Laurent_R
Veteran / Moderator

May 15, 2013, 3:22 AM

Post #15 of 15 (682 views)
Re: [StaedarN] script not producing output [In reply to] Can't Post

Another thing im wondering about is the !~.This kinda means if string 1 is not string 2; return true, right? (so the $nodiff should maybe be named $diff for clarity?)


Not exactly. This returns true if string 1 does not match the regular expression pattern of string 2.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives