Perl: How do I write to a directory besides bin?

I am trying to output a file in perl.

I open the file and output like this..

open(my $out, ">",  "output.html") or die "Can't open output.txt: $!";
print $out "something!";

Which works perfect. If I change it to this

open(my $out, ">",  "c:\somedirectory\output.html") or die "Can't open output.txt: $!";
print $out "something!";

It does run fine(I do not get the 'Can't open output.txt' message) but when I look in the directory the file I just output isn't there. If I leave it with no path the file is found in the bin.

What am I missing here? How do I get it to output another location.

Also.. I am running the .pl using this .bat file.


cd \xampp\perl\bin

perl "C:\somedirectory\"



Within double quotes, \ starts an escape sequence. Unrecognized escapes are simply ignored.

print "abc\tdef";
# abc     def
print "c:\somedirectory\output.html";
# c:somedirectoryoutput.html
print qq(c:\somedirectory\output.html);
# c:somedirectoryoutput.html

You may double up the backslashes in order to let them pass through the double quotes.

print "c:\\somedirectory\\output.html";
# c:\somedirectory\output.html
print qq(c:\\somedirectory\\output.html);
# c:\somedirectory\output.html

You may use single quotes instead of double quotes, because escape sequences are not recognized within single quotes.

print 'c:\somedirectory\output.html';
# c:\somedirectory\output.html
print q(c:\somedirectory\output.html);
# c:\somedirectory\output.html

And a final option: the Win32 and NT APIs happily treat / as directory separators just as well as \. While it may look odd, the following will work too:

open(my $out, ">", "C:/somedirectory/output.html");

You have to use double backslashes as directory separators for windows paths, or use simple forward slashes.

Need Your Help

Java Swing - Switch forms without resetting vales

java swing jframe jdialog

First of all I have a jFrame as parent and 2 jDialog forms as children.

Why are these arguments the default for events?

c# winforms events

I see the following arguments repeated a lot in boilerplate code and yet I don't seem to have made use of them yet?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.