CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [regex2012] trying to properly create directory: Edit Log



regex2012
User

Jan 30, 2017, 8:33 AM


Views: 2365
Re: [regex2012] trying to properly create directory

 
Ok I was able to do this by these statements:


Code
chomp( my $strHostname = qx{ hostname }); 
print $strHostname;

my $newdir="/prj/inventory/reports/accounting/$strHostname";
mkdir $newdir, 0777;


open (my $file, '>', '/prj/inventory/reports/accounting/$strHostname/listofaccounts.txt') or die "Could not open file: $!";
my $bpjoutput = qx(/bin/reportingmod -all_columns);
die "$!" if $?;
print $file $bpjoutput;


The directory is created just fine, but the listofaccounts.txt never gets created and the error "no directory" comes up, even though I can cd to the directory "benny" which is the hostname that $strHostname would contain.

It does work if I use the actual name of the host, for example,

Code
open (my $file, '>', '/prj/inventory/reports/accounting/benny/listofaccounts.txt')



However, I can't get a file created in there if I use the $strHostname variable.
how to fix this?


(This post was edited by regex2012 on Jan 30, 2017, 8:35 AM)


Edit Log:
Post edited by regex2012 (User) on Jan 30, 2017, 8:34 AM
Post edited by regex2012 (User) on Jan 30, 2017, 8:35 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives