| | |
perl assignment question
Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
•
•
Thats DOS (or other shell), not Windows. DOS uses forward slashes as switches, so you can't use them in directory paths. But Windows does fully support them. Its Windows itself that translates forward slashes into backslashes. Try using backslashes in Unix directry paths with perl or python and see what happens.
According to O'Reilly & Associates (Section 2.2.2, point / bullet number 2, and the table in 2.2.4) Some Perl modules and functions allow the use of '/' as a path separator, but it is strongly discouraged as a use of good practice.
Last edited by Comatose; Feb 11th, 2009 at 7:22 am.
I have always had more success at the cmd line (for windows) with perl using "\\path\\file.txt" However, in a web environment (at least if you're running apache for windows) "/path/file.txt" works just fine.
That has been my experience anyway.
That has been my experience anyway.
And don't tell me there isn't one bit of difference between null and space, because that's exactly how much difference there is.
Larry Wall
Larry Wall
Just to add a bit to the discussion. I was reading the perl FAQs to answer a question on a forumand came upon this:
Why can't I use "C:\temp\foo" in DOS paths? Why doesn't `C:\temp\foo.exe` work?
Whoops! You just put a tab and a formfeed into that filename! Remember that within double quoted strings ("like\this"), the backslash is an escape character. The full list of these is in "Quote and Quote-like Operators" in perlop. Unsurprisingly, you don't have a file called "c:(tab)emp(formfeed)oo" or "c:(tab)emp(formfeed)oo.exe" on your legacy DOS filesystem.
Either single-quote your strings, or (preferably) use forward slashes. Since all DOS and Windows versions since something like MS-DOS 2.0 or so have treated / and \ the same in a path, you might as well use the one that doesn't clash with Perl--or the POSIX shell, ANSI C and C++, awk, Tcl, Java, or Python, just to mention a few. POSIX paths are more portable, too.
Why can't I use "C:\temp\foo" in DOS paths? Why doesn't `C:\temp\foo.exe` work?
Whoops! You just put a tab and a formfeed into that filename! Remember that within double quoted strings ("like\this"), the backslash is an escape character. The full list of these is in "Quote and Quote-like Operators" in perlop. Unsurprisingly, you don't have a file called "c:(tab)emp(formfeed)oo" or "c:(tab)emp(formfeed)oo.exe" on your legacy DOS filesystem.
Either single-quote your strings, or (preferably) use forward slashes. Since all DOS and Windows versions since something like MS-DOS 2.0 or so have treated / and \ the same in a path, you might as well use the one that doesn't clash with Perl--or the POSIX shell, ANSI C and C++, awk, Tcl, Java, or Python, just to mention a few. POSIX paths are more portable, too.
Last edited by KevinADC; Feb 13th, 2009 at 1:05 pm. Reason: disable smilies
•
•
Join Date: Dec 2008
Posts: 11
Reputation:
Solved Threads: 0
I think I changed it to what some of the posts are saying but its still not working. This is what Ive got.
Perl Syntax (Toggle Plain Text)
#!/usr/bin/perl -w # Assignment3Ex1.pl use strict; open(INFH, '<', "C:\Documents and Settings\Home\Desktop\perl\gettysburg.txt") or die $!; open(OUTFH, '>', 'ex1out.txt') or die $!; while (<INFH>) { next if /^\s*$/; my @words = split; print OUTFH "$_\n" foreach @words; } close INFH; close OUTFH;
Its windows itself. Support for forward and backslashes in builtin to Windows. You can google around and find MicroSoft articles that explain it if interested. I think thats enough on the subject.
If it were windows itself, don't you think cmd.exe (which is a windows program) would support it? I would imagine so. According to MSDN (I was holding off on it, but will post it when I get home) they say it's the API functions that translate the / slashes to \ slashes. That would mean it's not windows itself (ie: the file system) but the programs that are running on it (ie: explorer.exe, and so forth). Just for fun, try this:
start, run, type in: /
Oops.
Start, run, type in: \
interesting.
http://www.cygwin.com/cygwin-ug-net/...fectively.html <<-- Under Pathnames
And straight from the horse's mouth:
http://msdn.microsoft.com/en-us/libr...22(VS.80).aspx
start, run, type in: /
Oops.
Start, run, type in: \
interesting.
http://www.cygwin.com/cygwin-ug-net/...fectively.html <<-- Under Pathnames
And straight from the horse's mouth:
http://msdn.microsoft.com/en-us/libr...22(VS.80).aspx
Last edited by Comatose; Feb 17th, 2009 at 3:58 pm.
I guess when we say Windows we should be more specific. Windows operating systems based on NT are different than older operating systems. The older ones support both slashes at the kernel level where NT does not. NT based systems do a conversion before the kernel level (in the APIs apparently). I had a link that explained all this on the MS website but the link now returns a "not found" page.
![]() |
Similar Threads
- PERL Text Statistic Help (Perl)
- perl assignment question (Perl)
- The Pascal Triangle (Perl)
- Help with a Profile Managment System (Perl)
- HELP! What does this mean.......? (Visual Basic 4 / 5 / 6)
Other Threads in the Perl Forum
- Previous Thread: Print in Perl
- Next Thread: perl loop replacement for normalization
| Thread Tools | Search this Thread |






