What's wrong is the way you are entering the file name.
Double quotes allow interpretation of what is between them:
I.e. step 1:
print out the name of the file:
perl -e ' use P;
my $filelist="C:\Users\cign\Desktop\printFile.txt";
P "opening file: %s", $filelist;
'
opening file: C:SERS GNDESKTOPPRINTFILE.TXT
Is that the file you wanted to open? Prolly not.
step 2, at least turn on warning and try to use strict - they detect alot (though not all) of problems -- in this case they would have given you a hint:
perl -we 'use strict; use P;
my $filelist="C:\Users\cign\Desktop\printFile.txt";
P "opening file: %s", $filelist;'
Unrecognized escape \D passed through at -e line 2.
Unrecognized escape \p passed through at -e line 2.
opening file: C:SERS GNDESKTOPPRINTFILE.TXT
use single quotes to define a literal, or put another backslash \ before each \, or use the 'q{...}' operator to really set it off that emphasizes it has to be taken literally (and doesn't interfere with my using single
quotes in a 1 line program I typed in on the command line! ;-)
perl -we 'use strict; use P;
my $filelist=q{C:\Users\cign\Desktop\printFile.txt};
P "opening file: %s", $filelist;'
opening file: C:\Users\cign\Desktop\printFile.txt
##
#alternate ways
##
> perl -we 'use strict; use P;
my $filelist='\''C:\Users\cign\Desktop\printFile.txt'\'';
P "opening file: %s", $filelist;'
opening file: C:\Users\cign\Desktop\printFile.txt
##
> perl -we 'use strict; use P;
my $filelist="C:\\Users\\cign\\Desktop\\printFile.txt";
P "opening file: %s", $filelist;'
opening file: C:\Users\cign\Desktop\printFile.txt
###
## my favorite (in a file)...
#! perl/bin/perl.exe
use strict; use P;
my $filelist="C:/Users/../tmp/../Perl64/printFile.txt";
P "opening file: %s", $filelist;
open (test, ">", $filelist) or die "didn't work";
print test "Hello World!\n";
close test;
C:\Perl64>perl test.pl
opening file: C:/Users/../tmp/../Perl64/printFile.txt
C:\Perl64>type printFile.txt
Hello World!
Forward slash works in alot of places on Windows cuz the underlying 'NT' OS accepts it.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.