perl assignment question

Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: perl assignment question

 
0
  #11
Feb 11th, 2009
Originally Posted by KevinADC View Post
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.
Last edited by Comatose; Feb 11th, 2009 at 7:22 am.
Attached Thumbnails
pic2.png  
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: perl assignment question

 
0
  #12
Feb 11th, 2009
I see that link I posted was broke, try again:

http://en.wikipedia.org/wiki/Path_(computing)
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: perl assignment question

 
0
  #13
Feb 11th, 2009
That link does not want to post on this forum

http://en.wikipedia.org/wiki/Path_(computing)
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: perl assignment question

 
0
  #14
Feb 11th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 58
Reputation: mitchems is an unknown quantity at this point 
Solved Threads: 2
mitchems's Avatar
mitchems mitchems is offline Offline
Junior Poster in Training

Re: perl assignment question

 
0
  #15
Feb 11th, 2009
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.
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: perl assignment question

 
0
  #16
Feb 13th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 11
Reputation: mtramnes is an unknown quantity at this point 
Solved Threads: 0
mtramnes mtramnes is offline Offline
Newbie Poster

Re: perl assignment question

 
0
  #17
Feb 17th, 2009
I think I changed it to what some of the posts are saying but its still not working. This is what Ive got.

  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;
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: perl assignment question

 
0
  #18
Feb 17th, 2009
Originally Posted by Comatose View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: perl assignment question

 
0
  #19
Feb 17th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: perl assignment question

 
0
  #20
Feb 17th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Perl Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC