By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,834 Members | 2,240 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,834 IT Pros & Developers. It's quick & easy.

Helop on file name display

rajiv07
100+
P: 141
Hi to all,

I have a script to list the file names in a directory .When i run this script locally (command prompt) it displays the exact file name (even though the file name has two spaces).But i upload the script into server (Browser) it shows trimmed file names(single space for double spaces).

I have checked both IE and Firefox it shows only single space file name instead on double space file name. Is it browser problem.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. my @distinct_download_path=('c:/perl/examples/array');
  4.  
  5. for(@distinct_download_path){
  6. next if /^(\s)*$/;
  7. unless (opendir(DIR,$_)){ push(@download_invalid_directory,$_);}
  8.  while($file=readdir(DIR)){
  9.     next if/^(\s)*$/;
  10.      next if(($file eq ".")||($file eq ".."));
  11.     next if(-d $file); #next if $file is directory
  12.  $_=~s/(.)\/$/$1/; #remove last /
  13.  $file=$_.'/'.$file; #construct full path
  14.  
  15.  
  16.  
  17. push(@list_files_in_download_directory,$file);
  18.  }
  19.  
  20. }
  21.  
  22. print "content-type:text/html\n\n";
  23.  
  24. print join("\n",@list_files_in_download_directory);
Script Output For local run
-------------------------------------
c:/perl/examples/array/data structure.pl
c:/perl/examples/array/dumper.pl
c:/perl/examples/array/rajiv gandhi.pl# here the file name actually has two spaces between rajiv and gandhi but it shows only one space.


Script Output For server run
-------------------------------------
c:/perl/examples/array/data structure.pl
c:/perl/examples/array/dumper.pl
c:/perl/examples/array/rajiv gandhi.pl

Please help me.

Regards
Rajiv
Jun 3 '08 #1
Share this Question
Share on Google+
3 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
Hi to all,

I have a script to list the file names in a directory .When i run this script locally (command prompt) it displays the exact file name (even though the file name has two spaces).But i upload the script into server (Browser) it shows trimmed file names(single space for double spaces).

I have checked both IE and Firefox it shows only single space file name instead on double space file name. Is it browser problem.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. my @distinct_download_path=('c:/perl/examples/array');
  4.  
  5. for(@distinct_download_path){
  6. next if /^(\s)*$/;
  7. unless (opendir(DIR,$_)){ push(@download_invalid_directory,$_);}
  8.  while($file=readdir(DIR)){
  9.     next if/^(\s)*$/;
  10.      next if(($file eq ".")||($file eq ".."));
  11.     next if(-d $file); #next if $file is directory
  12.  $_=~s/(.)\/$/$1/; #remove last /
  13.  $file=$_.'/'.$file; #construct full path
  14.  
  15.  
  16.  
  17. push(@list_files_in_download_directory,$file);
  18.  }
  19.  
  20. }
  21.  
  22. print "content-type:text/html\n\n";
  23.  
  24. print join("\n",@list_files_in_download_directory);
Script Output For local run
-------------------------------------
c:/perl/examples/array/data structure.pl
c:/perl/examples/array/dumper.pl
c:/perl/examples/array/rajiv gandhi.pl# here the file name actually has two spaces between rajiv and gandhi but it shows only one space.


Script Output For server run
-------------------------------------
c:/perl/examples/array/data structure.pl
c:/perl/examples/array/dumper.pl
c:/perl/examples/array/rajiv gandhi.pl

Please help me.

Regards
Rajiv
I am really not sure myself. My first thought is maybe the browser is stripping the unnecessary white space. I see that in viewing your post with firefox that the extra space got stripped.

Again, not sure.

Regards,

Jeff
Jun 3 '08 #2

KevinADC
Expert 2.5K+
P: 4,059
Web browsers collapse multiple spaces into one space. Look in the source code of the HTML document and you will see the extra spaces, but you will not see them in the browser. This is an html issue, not a perl issue. Use some HTML code that maintains text formatting (<pre>formatted text here</pre>) or use html entities to display the extra spaces: &nbsp;

Study up on HTML.
Jun 3 '08 #3

rajiv07
100+
P: 141
Thank You for your replies



Rajiv
Jun 4 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.