Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Creating a new file in a directory

by parthodas (Acolyte)
on Aug 21, 2015 at 07:40 UTC ( [id://1139382]=note: print w/replies, xml ) Need Help??


in reply to Re: Creating a new file in a directory
in thread Creating a new file in a directory

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.
  • Comment on Re^2: Creating a new file in a directory

Replies are listed 'Best First'.
Re^3: Creating a new file in a directory
by Corion (Patriarch) on Aug 21, 2015 at 07:42 UTC

    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 . . .

        Yes, that means you have a newline in $mycrdir. This is because you read $mycrdir from the user and that readline includes the final newline as entered by the user. You could have shown this part of your code as well to make it more obvious that $mycrdir is read from the outside.

      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1139382]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-25 15:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found