Hi I am very new to PERL i have written code as :
if (open(PROGRAM_1, "C:\program_1")) {
print ( "working");
}
for opening the simple txt file but it is showing error as
"Name "main::PROGRAM_1" used only once: possible typo at Untitled1 line 3.
Please do help me.i am using perlexpress on windows environment.
Your method of calling open is deprecated - that is, you should be using a scalar filehandle variable instead of a bareword filehandle. If your program had the strict and warnings pragmas enables (as it always should), you would be getting complaints. In addition, you are not telling open how you want to open the file - for input? output? Finally, the '\' character is the escape character, so the open function thinks you have a special character '\p' in the string. Either backslash your backslash '\\' or use single quotes so that the backslash isn't interpolated.
Your code should look like this:
- if (open my $PROGRAM_1, '<', 'C:\program_1') { # '<' assuming you want to open for input
-
print "Working.\n";
-
}