473,378 Members | 1,543 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

what's wrong with my loop?

i wish to compare 1 file with multiple files (in a folder)
@allfile - >> the paths for all files in a folder

but once i run the code below, it keep loop at print "comparing $masterfile with $file1";
if i delete the compare function it works well.
what's wrong? Thanks


Expand|Select|Wrap|Line Numbers
  1. use File::Compare;
  2. foreach $file (@allfile) {
  3. my $file1=$file;
  4. $masterfile='c:\\ts\\compare1.pl';
  5.             print "comparing $masterfile with $file1";
  6.     if (compare("$masterfile","$file1") == 0) {
  7.         print "They're equal\n";
  8.     } else {
  9.          print "They're not equal\n";
  10.              }
  11.  
  12. }
Jul 5 '08 #1
6 1424
KevinADC
4,059 Expert 2GB
i wish to compare 1 file with multiple files (in a folder)
@allfile - >> the paths for all files in a folder

but once i run the code below, it keep loop at print "comparing $masterfile with $file1";
if i delete the compare function it works well.
what's wrong? Thanks


Expand|Select|Wrap|Line Numbers
  1. use File::Compare;
  2. foreach $file (@allfile) {
  3. my $file1=$file;
  4. $masterfile='c:\\ts\\compare1.pl';
  5.             print "comparing $masterfile with $file1";
  6.     if (compare("$masterfile","$file1") == 0) {
  7.         print "They're equal\n";
  8.     } else {
  9.          print "They're not equal\n";
  10.              }
  11.  
  12. }
Here is the code a bit cleaned up. It looks like it should work OK.

Expand|Select|Wrap|Line Numbers
  1. use File::Compare;
  2. my $masterfile = 'c:/ts/compare1.pl'; # <-- forward slashes OK with windows
  3. foreach my $file (@allfile) {
  4.    print "comparing $masterfile with $file\n";
  5.    if (compare($masterfile, $file) == 0) {
  6.       print "They're equal\n";
  7.    }
  8.    else {
  9.       print "They're not equal\n";
  10.    }
  11. }
run the code and post what this line prints:

Expand|Select|Wrap|Line Numbers
  1.  print "comparing $masterfile with $file";
Jul 5 '08 #2
It's still the same where it's pause at the code of compare.
comparing c:/ts/compare1.pl with c:\ts\aaa.pl

Once i remove the compare function, it's become ok.

should be somethingwrong with the compare function.

i noticed that whenever i use
Expand|Select|Wrap|Line Numbers
  1. print Dumper "comparing $masterfile with $file\n";
i can print the path correctly meaning got double '\\'

while if i use the
Expand|Select|Wrap|Line Numbers
  1. print "comparing $masterfile with $file\n";
it all change to single '\'
Jul 6 '08 #3
comparing c:/ts/compare1.pl with c:\ts\aaa.pl

i tried to change the "\" to "/"... but the code stil failed (keep looping when comapring the first file ) at the compare function.

help. thanks
Jul 6 '08 #4
i check with open(file, $file)|| or die $;
it's working fine. meaning there's no broken link for the path.
beside using compare function, is there any module tat i can use?
Please guide.
Jul 6 '08 #5
KevinADC
4,059 Expert 2GB
I don't know what the problem is or if there is another module you can use.
Jul 6 '08 #6
It's ok. thanks for your time.
Jul 7 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

226
by: Stephen C. Waterbury | last post by:
This seems like it ought to work, according to the description of reduce(), but it doesn't. Is this a bug, or am I missing something? Python 2.3.2 (#1, Oct 20 2003, 01:04:35) on linux2 Type...
51
by: WindAndWaves | last post by:
Can anyone tell me what is wrong with the goto command. I noticed it is one of those NEVER USE. I can understand that it may lead to confusing code, but I often use it like this: is this...
6
by: Niklaus | last post by:
Hi, Can someone point out what is wrong with this code ? How can i make it better optimize it. When run it gives me seg fault in linux. But windows it works fine(runs for a long time). Do we...
5
by: ken | last post by:
Hi, I have two questions the first is: in the example below how can I call an event from within a statement, such as replace Stop1 with cmdStop1 which is a button on my form? My second question...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
30
by: Bill Reid | last post by:
#define MAX_VALUES 64 typedef struct { unsigned value_1; double value_2; double value_3; double value_4; } VALUES; typedef struct {
16
by: chutsu | last post by:
Ok Here is a problem, I got a imaginary database program that I need to code, to add a patient I have function inser_patient. but when I try to input the details it doesn't quite work the way I...
14
by: Mohamed Mansour | last post by:
Hey there, this will be somewhat a long post, but any response is appreciated! I have done many PInvoke in the past from C++ to C#, but I did PInvoke within C# not C++/CLI. Can someone explain...
10
by: DavidSeck.com | last post by:
Hi, I am working with the Facebook API right now, an I have kind of a problem, but I don't know what I am doing wrong. So I have a few arrays, f.ex.: User albums: array(2) {
16
by: raylopez99 | last post by:
I am running out of printing paper trying to debug this...it has to be trivial, but I cannot figure it out--can you? Why am I not printing text, but just the initial string "howdy"? On the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.