Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if (-e ... not working

Status
Not open for further replies.

Crisps

Programmer
Sep 28, 2006
26
0
0
US
I have a simple perl script that contains these few lines
Code:
	$Filename = "Z:\\user_CCPROJ_Integration\\SxSupport\\SxRelease\\.\\Product500\\Hooks\\Generic\\ScriptHook\\Release.txt";
	$Filename2 = $DestPath . ".\\" . $RelRelease;
		
	print "$Filename\n\n";
	print "$Filename2\n\n";
	
	if (-e "$Filename2")
	{	
		print "Found!\n";

The code prints both Filename 1 and 2 which are identical filename (and which definitely exist).

If I use filename 1 in the if statement it returns true - Found

if I use filename 2 then it returns false.

Why?

What am I doing wrong. I am new to perl.

 
Found the issue, one of the filenames had a carriage return on the end. removed it with chomp and it now works.
 
Since you're new to perl, and you're working in a Windows environment, here's something that may interest you - when specifying paths in your perl scripts, you can use forward slashes and Windows doesn't care.

So rather than:
Code:
my $path = "c:\\path\\to\file\\";
You can use:
Code:
my $path = "c:/path/to/file/";
It's a bit easier to read and you don't have to worry about escaping all the backslashes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top