in reply to Creating a new file in a directory

Is there a newline in $mycrdir? Also, you should output the reason why open fails:

my $filename = "$mycrdir/file_detail.txt"; open my $OUT, '>>', $filename or die "Can't create '$filename': $!";

The error reason maybe gives you a better hint at what fails. Also try hardcoding $mycrdir in your script first to see whether whitespace or other stuff might be a problem.

Replies are listed 'Best First'.
Re^2: Creating a new file in a directory
by parthodas (Acolyte) on Aug 21, 2015 at 07:40 UTC
    It seems a new line character comes at the end of $mycrdir and the file name goes to the next line. Maybe, because of this the file is not getting created. I chomped $mycrdir to remove any white characters, but then also it is failing.

      chomp does not remove all whitespace from the end of a string. I recommend that you be more explicit and use:

      $mycrdir =~ s!\s*$!!;

      Also, what is the error message your OS gives you in $! when creating the file fails?

        Getting this error, when running the script --
        Please enter your selection : 1
        Please enter the CR# :117365
        CR num is 117365

        File type confirmation for CR 117365..........

        Cannot open D:\SiebelAdmin\CR_Files\CR117365_20150821_0045
        /file_detail.txt: Invalid argument

        D:\SiebelAdmin\Operations>pause
        Press any key to continue . . .
        The error message is as below
        Please enter your selection : 1 Please enter the CR# :117365 CR num is 117365 File type confirmation for CR 117365.......... Cannot open D:\SiebelAdmin\CR_Files\CR117365_20150821_0045 /file_detail.txt: Invalid argument D:\SiebelAdmin\Operations>pause Press any key to continue . . .
        That helped a lot. Thanks a lot. Issue is resolved. The variable was a input which was used in different section. Hence, it was not included.