in reply to Re: problem to open a specified path file in open system call
in thread problem to open a specified path file in open system call

Hi Naikonta,
Thx for quick reply,the actual problem is as below
$path1="/remote/scm/rsync/builds/v_dialer/FailedInformal/3.0.0.0.118"; i can able to open the file by command prompt as
vi /remote/scm/rsync/builds/v_dialer/FailedInformal/3.0.0.0.118/build.log
but in open comman unable to open
open(FILE,$path1/build.log) or die "$!\n"; why this will not open the build.log?
whats wrong in open() call...litrally i am not getting where its going wrong...help me out to proceed further
  • Comment on Re^2: problem to open a specified path file in open system call

Replies are listed 'Best First'.
Re^3: problem to open a specified path file in open system call
by naikonta (Curate) on Jul 14, 2007 at 13:31 UTC
    The problem with your usage on open is that it can't open a file with newline character in its name. As pointed out by tirwhan, the embedded newline characters in your filenames came from ls command. You need to chomp them.
    my @files = `ls -1`; chomp @files; # or in one line chomp(my @files = `ls -1`);
    Using built-in opendir and readdir would be safer for you, and no extra processes needed.

    Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

      The problem with your usage on open is that it can't open a file with newline character in its name.

      To be precise, open can open a file with newline characters in its name just fine, as long as they're supported by the filesystem and they do exist. Under *NIX the only forbidden charachters are "\0" and "/".

      blazar@perlmonk ~ $ perl -e 'open F, ">foo\nbar" or die' blazar@perlmonk ~ $ ls foo* foo?bar
        Thank you for clarifying this. I hope my reply wasn't leading to misinterpretation as I referred to newline characters "embedded" in the output by external program as they are not part of the original filenames.

        Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

Re^3: problem to open a specified path file in open system call
by almut (Canon) on Jul 14, 2007 at 13:46 UTC
    open(FILE,$path1/build.log) or die "$!\n"; why this will not open the build.log?

    In case it's not just a typo in this post...  you'd need to either interpolate

    open(FILE,"$path1/build.log") or die "$!\n";

    or concatenate the strings

    open(FILE,$path1."/build.log") or die "$!\n";

    Using strictures would have revealed the problem. With use strict; you'd have gotten:

    Bareword "build" not allowed while "strict subs" in use at ./626616.pl + line 8. Execution of ./626616.pl aborted due to compilation errors.

    and with use warnings; even more:

    Unquoted string "build" may clash with future reserved word at ./62661 +6.pl line 8. Name "main::FILE" used only once: possible typo at ./626616.pl line 8. Argument "build" isn't numeric in division (/) at ./626616.pl line 8. Argument "." isn't numeric in division (/) at ./626616.pl line 8. Illegal division by zero at ./626616.pl line 8.