Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
There's more than one way to do things
 
PerlMonks  

Comparing two directories and then exiting from the script

by iphone (Beadle)
on Nov 20, 2010 at 01:39 UTC ( #872611=perlquestion: print w/ replies, xml ) Need Help??
iphone has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am trying to compare two directories with the following code but I am getting the following warning.What is wrong with the below code?

Argument "E:/perl/scripts" isn't numeric in numeric ne (!=) at orphan_check.pl line 26. Argument "Z:\\edit\\scripts" isn't numeric in numeric ne (!=) at orphan_check.pl line 26.

I am trying
if($client_root!=$cwd) { print "EXITING:Perforce client root donot match the current working di +rectory"; exit; }

Comment on Comparing two directories and then exiting from the script
Download Code
Re: Comparing two directories and then exiting from the script
by Khen1950fx (Canon) on Nov 20, 2010 at 01:51 UTC
    Neither of your arguments are numeric. Just use ne:
    if ($client_root ne $cwd) { #do something }
Re: Comparing two directories and then exiting from the script
by biohisham (Priest) on Nov 20, 2010 at 03:22 UTC
    Argument "E:/perl/scripts" isn't numeric in numeric ne (!=) at orphan_check.pl line 26
    Of course this argument is not numeric because "E:/perl/scripts" is not a number, hence you were offered the operator 'ne' instead of the one you tried to use '!='.

    You have to decide whether your operand(s) is in numeric context or a string context. In Perl it makes a difference and using an operator in a context that is it not applicable could give out such warnings.

    'lt, gt, le, ge, eq, ne, cmp' perform on strings similar operations performed by '<, >, <=, >=, ==, !=, <=>' respectively on numbers

    On a further note, be careful with treating strings as numbers because perl can force into a number any string that has been treated that way, an example will include using the arithmetic operators on strings, they will be reinitialized to zero..
    my $string = "lion"; my $result = $string + 2; print $result;
    '$string' was reinitialized to 0... These are some errors that may just be hard to detect if you chose to ignore warnings given to you..



    Excellence is an Endeavor of Persistence. A Year-Old Monk :D .

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://872611]
Approved by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2014-04-20 02:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls