Gossamer Forum
Home : General : Perl Programming :

Stripping spaces?

Quote Reply
Stripping spaces?
I have altered a script I found. I use it to export my users from my bulletin board to DBMan's .pass file. DBMan does not like the spaces in the usersID. I need to add a line of code to my script that will strip the space and add the underline character in its place prior to output to my .pass file. Here is the code I am working with.

Code:
SELECT U_Username, U_Password, U_DBView, U_DBAdd, U_DBDelete, U_DBModify, U_DBAdmin
FROM w3t_Users
EOS

my $sth = $dbh->prepare($statement);
my $rv = $sth->execute();

my $record;
while ($record = $sth->fetchrow_arrayref() ) {
print OUTFILE "$record->[0]:$record->[1]:$record->[2]:$record->[3]:$record->[4]:$record->[5]:$record->[6]\n";
}
I am a perl illiterate, so please be gentle in your answer. I think I understand how the lines of my script work, but only because I got educated guesses. I really would not know how to implement any commands.

Thanks
Dale

Quote Reply
Re: Stripping spaces? In reply to
 
Hmmm,

Try re-opening the data base and cleaning up the left overs.

Like so,

Code:
sub cleanup{
open(data, "</path/to/file/data.db");
while(<data>){
$_ =~ s!\s!!sg;
push(@neat, $_);
}
close(data);
open(rewrite, ">/path/to/file/data.db");
print rewrite @neat;
close(rewrite);
}#end of sub
#
SELECT U_Username, U_Password, U_DBView, U_DBAdd, U_DBDelete, U_DBModify, U_DBAdmin
FROM w3t_Users
EOS
my $sth = $dbh->prepare($statement);
my $rv = $sth->execute();
my $record;
while ($record = $sth->fetchrow_arrayref() ) {
print OUTFILE "$record->[0]:$record->[1]:$record->[2]:$record->[3]:$record->[4]:$record->[5]:$record->[6]\n";}
&cleanup;
I think that will do it, if not then let me know, I have some more ideas that may work.

perlkid

Quote Reply
Re: Stripping spaces? In reply to
Code:
while ($record = $sth->fetchrow_arrayref() ) {
$record->[0] =~ s/ //g;
(Underscore used per discussion of same thread on HS forums)

--mark


Installation support is provided via ICQ at UIN# 53788453. I will only respond on that number.
Quote Reply
Re: Stripping spaces? In reply to
Thanks for all your help