943,577 Members | Top Members by Rank

Ad:
  • Perl Discussion Thread
  • Unsolved
  • Views: 1819
  • Perl RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Feb 11th, 2009
0

Re: perl assignment question

Click to Expand / Collapse  Quote originally posted by KevinADC ...
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.
Oddly enough, the above posted (with the suggestions to try cd / and cd /windows and cd "/documents and settings") was tested in windows XP SP1. I went to start... run, and typed in cmd. Once the window was up, I typed cd /, and hit enter. While XP didn't completely flip out, it certainly did not take me to the root directory (\). Then, when I typed cd /windows/system32, this most certainly did error. Try it with a known branch, such as: cd /windows/system32. No can do. Notice the second entry of the command line... gives an error. The third (using \'s) does not. The rest of the lines... none of them work either (although, the cd / doesn't error, it also doesn't work.). This is not DOS. This is cmd.exe (not command.com). However, KevinADC is right that explorer.exe (windows Desktop shell) does allow the use of / in paths (such as typing a path in my computer's location bar). The question is... is that the file system, or is that explorer.exe?

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.
Attached Thumbnails
Click image for larger version

Name:	pic2.png
Views:	6
Size:	19.2 KB
ID:	9173  
Last edited by Comatose; Feb 11th, 2009 at 7:22 am.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Feb 11th, 2009
0

Re: perl assignment question

I see that link I posted was broke, try again:

http://en.wikipedia.org/wiki/Path_(computing)
Reputation Points: 246
Solved Threads: 67
Practically a Posting Shark
KevinADC is offline Offline
898 posts
since Mar 2006
Feb 11th, 2009
0

Re: perl assignment question

That link does not want to post on this forum

http://en.wikipedia.org/wiki/Path_(computing)
Reputation Points: 246
Solved Threads: 67
Practically a Posting Shark
KevinADC is offline Offline
898 posts
since Mar 2006
Feb 11th, 2009
0

Re: perl assignment question

I trust O'Reilly significantly more than wikipedia. I also read on MSDN (will post when I get home) that it's the API calls and programs that do the translation, not NTFS Native.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Feb 11th, 2009
0

Re: perl assignment question

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.
Reputation Points: 26
Solved Threads: 38
Posting Whiz in Training
mitchems is offline Offline
293 posts
since Feb 2009
Feb 13th, 2009
0

Re: perl assignment question

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.
Last edited by KevinADC; Feb 13th, 2009 at 1:05 pm. Reason: disable smilies
Reputation Points: 246
Solved Threads: 67
Practically a Posting Shark
KevinADC is offline Offline
898 posts
since Mar 2006
Feb 17th, 2009
0

Re: perl assignment question

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)
  1. #!/usr/bin/perl -w
  2. # Assignment3Ex1.pl
  3.  
  4. use strict;
  5.  
  6. open(INFH, '<', "C:\Documents and Settings\Home\Desktop\perl\gettysburg.txt") or die $!;
  7. open(OUTFH, '>', 'ex1out.txt') or die $!;
  8.  
  9. while (<INFH>) {
  10. next if /^\s*$/;
  11. my @words = split;
  12. print OUTFH "$_\n" foreach @words;
  13. }
  14.  
  15. close INFH;
  16. close OUTFH;
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mtramnes is offline Offline
11 posts
since Dec 2008
Feb 17th, 2009
0

Re: perl assignment question

Click to Expand / Collapse  Quote originally posted by Comatose ...
I trust O'Reilly significantly more than wikipedia. I also read on MSDN (will post when I get home) that it's the API calls and programs that do the translation, not NTFS Native.
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.
Reputation Points: 246
Solved Threads: 67
Practically a Posting Shark
KevinADC is offline Offline
898 posts
since Mar 2006
Feb 17th, 2009
0

Re: perl assignment question

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
Last edited by Comatose; Feb 17th, 2009 at 3:58 pm.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Feb 17th, 2009
0

Re: perl assignment question

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.
Reputation Points: 246
Solved Threads: 67
Practically a Posting Shark
KevinADC is offline Offline
898 posts
since Mar 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Perl Forum Timeline: Print in Perl
Next Thread in Perl Forum Timeline: perl loop replacement for normalization





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC