in reply to open file error

Note that when you use split, your variable will have a space at the end. You can find that by printing the values:

print "[$pagal]\n";

In the case that does not work, you will find that there is the additional space from $run_cmd.

Personally, I would restructure the code so that the log file is in a separate variable from the start:

my $logfile = '/tmp/some/logfile.txt'; my $run_cmd = "... >$logfile"; ... open my $log, '<', $logfile or die "Couldn't open log file '$logfile': $!";

Replies are listed 'Best First'.
Re^2: open file error
by t-rex (Scribe) on Jul 19, 2016 at 10:57 UTC

    I used chomp on $logfile to get rid of any space. Actually I think you didn't get my problem, I am extracting the file name from the $run_cmd string and using it further along with a $rundir_path variable. I am unable to figure our why after using chomp , why this is happening.

      Feel free to use different approaches.

      As a hint, maybe you want to re-read chomp - it will not remove space (chr(32)) from the end of a string. But as I already showed you how to diagnose the problem, you certainly have found out by using my advice that whitespace at the end of $logfile was not the case for the difference between the hardcoded filename working and the dynamic filename not working.

      Please show us again the code that works and the code that fails, together with the diagnostic that ascertains that there is no whitespace at the end of the filename you use in the dynamic case.

        oh i got it ... i should have read chomp properly, i used a regex to trim the spaces from both ends of any string

        $logfile =~ s/^\s+|\s+$//g;

        and now it's working. Sorry for the not so intelligent answer above :P please don't down vote that :) Thanks