CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
white space in text file

 



pauls
Novice

Jan 6, 2001, 12:47 AM

Post #1 of 3 (392 views)
white space in text file Can't Post

here is what i have when this is complete the text file has a white space at the first space of all lines except the first. I need to remove these spaces. it screws up a find function that i use after the file is rewritten.
any help would be great.
thanks
paul

open(UF, "updatedtext");
@new = <UF>;
close(UF);
open(GB, "<text") || die "cant: $!";
@all=<GB>;
close(GB);
$file= "@all";
$file =~ s!$imagename.*$imagename!!s;
open(GB, ">text");
print GB "$file";
close(GB);
open(GB, ">>$text");
seek(GB, 0, 4);
print GB "@new";
close(GB);
open(GB, "$text") || die "cant: $!";
@newgb = <GB>;
close(GB);
print "@newgb";




japhy
Enthusiast

Jan 6, 2001, 6:47 AM

Post #2 of 3 (390 views)
Re: white space in text file [In reply to] Can't Post

That whitespace is due to you evaluating an array in double quotes. Doing that places a space in between each element of the array. To get around this, try using join(), or change the $" variable to an empty string.


Code
$file = join "", @all;  # instead of "@all"

Also, please avoid useless quoting of variables, since it can cause problems, like the one you just encountered.


Code
print $file;  # instead of print "$file" 
print @lines; # instead of print "@lines"

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author


pauls
Novice

Jan 6, 2001, 8:24 AM

Post #3 of 3 (387 views)
Re: white space in text file [In reply to] Can't Post

thanks, it worked just fine.
but about the quoting of variables, I tried removing those first and the result was not good. but when I added the join... it worked without all the quoting. ??? I'm sure it's my sloppy writing.
but, thanks again.
paul



 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives