Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 29th, 2001, 08:50 AM
jjk jjk is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 0 jjk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I am trying to gather some statistics and print the contents of all the files in a particular directory. Everything works fine for alphanumeric filenames, however the filenames with whitespace are causing me some grief.
Could somebody give me some pointers or solution to dealing with " file name .text"?

thanks

Reply With Quote
  #2  
Old March 29th, 2001, 09:14 AM
randor randor is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Location: Western New York
Posts: 85 randor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 8 m 46 sec
Reputation Power: 8
Send a message via Yahoo to randor
jjk,

im not sure what you are looking to do? if it is remove the spaces, then try this:

$file = ' file .txt"
$file=~ s/\s//;

if that does not work, try this:
$file=~ s/ //;

hope this helps

Reply With Quote
  #3  
Old March 29th, 2001, 09:50 AM
jjk jjk is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 0 jjk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks randor, that's not exactly what I'm trying to do, I don't think I was really sure either. I believe now what I am trying to do is open a filehandle with spaces in the filename and I get "Read on closed filehandle" error on the statement
open(SOMEFILE, "$filename");
where $filename = "\x20filename"

thanks

Reply With Quote
  #4  
Old March 29th, 2001, 10:01 AM
jjk jjk is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 0 jjk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks randor, that's not exactly what I'm trying to do, I don't think I was really sure either. I believe now what I am trying to do is open a filehandle with spaces in the filename and I get "Read on closed filehandle" error on the statement
open(SOMEFILE, "$filename");
where $filename = "\x20filename"

thanks

Reply With Quote
  #5  
Old March 29th, 2001, 10:12 AM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 10
You'll need to show us more code than just the open() command if you want us to know what it does.

Reply With Quote
  #6  
Old March 30th, 2001, 02:00 AM
jjk jjk is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 0 jjk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Source code as requested. Any suggestions for improvement are welcome.
The objective is to produce a list of filenames in a directory in the format "filename, creation time (I know this gives mtime), file contents.
My other thought is if I can't get around the open file with spaces_in_the_filename problem, change the filename. Thoughts?

$srcdir = $ARGV[0];
chdir($srcdir) || die "Cannot change directory to $srcdir: $!";
opendir(DATA, ".") || die "Cannot open directory $srcdir : $!";
foreach $filename (grep !/^\./, readdir(DATA)) {
$a = <STDIN>;
open(SOMEFILE, "<$filename");
while (<SOMEFILE>) {
$fdate = localtime((stat($filename))[9]);
print "$filename $fdate $_ \n";
}
}
closedir(DATA);

thanks in advance

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Filenames with spaces


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway