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:
Write a file

 



Johnt
New User

Sep 5, 2009, 1:43 PM

Post #1 of 6 (639 views)
Write a file Can't Post

Im trying to create file into a dir. But im trying to make the file path configurable . How would i get the file path from a variable or whatever.

$brconfig::$config_logfilepath is the file path i want to use set in brconfig.pm . brconfig.pm creates a configurable file where other config settings are set.

So how would i get the file path so it writes in the file in that dir. Not sure what to do.

could i do somthing like
open (ConsoleCommand, '>>$brconfig::$config_logfilepath\ConsoleCommand.txt');
print ConsoleCommand "command flymode ObjectID\n";
close (ConsoleCommand);


(This post was edited by Johnt on Sep 5, 2009, 1:46 PM)


KevinR
Veteran


Sep 5, 2009, 2:54 PM

Post #2 of 6 (633 views)
Re: [Johnt] Write a file [In reply to] Can't Post

You could try something like that but variables can't be in single-quoted strings, use double-quotes instead and use a forward slash instead of a backslash in the path:


Code
open (ConsoleCommand, ">>$brconfig::$config_logfilepath/ConsoleCommand.txt") or die "$!";


Keep in mind that '>>' opens for appending to an existing file or creating a new file if one does not already exist. Use '>' if you want to create a new file each time you open the file.
-------------------------------------------------


Johnt
New User

Sep 5, 2009, 3:23 PM

Post #3 of 6 (631 views)
Re: [KevinR] Write a file [In reply to] Can't Post

Ok that's what I did wrong. But it created the file in C:\ and the FDSLogFilePath = C:\test\Server\data\


It does this when it reads the brconfig if that helps at all
if (/^\s*FDSLogFilePath\s*=\s*(\S+)/i) { $config_logfilepath = $1; }

else it will show an error


(This post was edited by Johnt on Sep 5, 2009, 3:27 PM)


KevinR
Veteran


Sep 5, 2009, 9:56 PM

Post #4 of 6 (614 views)
Re: [Johnt] Write a file [In reply to] Can't Post


In Reply To
Ok that's what I did wrong. But it created the file in C:\ and the FDSLogFilePath = C:\test\Server\data\


It does this when it reads the brconfig if that helps at all
if (/^\s*FDSLogFilePath\s*=\s*(\S+)/i) { $config_logfilepath = $1; }

else it will show an error


OK, I'm not sure what you're getting at. If the file path is C:\test\Server\data\ then it makes sense it created the file on the C drive.
-------------------------------------------------


Johnt
New User

Sep 6, 2009, 2:10 PM

Post #5 of 6 (604 views)
Re: [KevinR] Write a file [In reply to] Can't Post

it created the file at C:\ and not C:\test\Server\data\


KevinR
Veteran


Sep 6, 2009, 4:08 PM

Post #6 of 6 (602 views)
Re: [Johnt] Write a file [In reply to] Can't Post


In Reply To
it created the file at C:\ and not C:\test\Server\data\


OK, well, I have no idea why that is. Print the value of $config_logfilepath while the script is running to see what its value is.
-------------------------------------------------

 
 


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

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