Gossamer Forum
Home : General : Perl Programming :

Stripping misc characters form my output?

Quote Reply
Stripping misc characters form my output?
In an earlier thread I was shown how to strip spaces from a field. I also need to strip &,_,- from the output. Dbman does not like characters in the logon field.

Code:
my $record;
while ($record = $sth->fetchrow_arrayref() ) {
$record->[0] =~ s/ //g;
$record->[0] =~ s/_//g;
$record->[0] =~ s/-//g;
$record->[0] =~ s/&//g;
$record->[0] =~ s/*//g;
print OUTFILE "$record->[0]:$record->[1]:$record->[2]:$record->[3]:$record->[4]:$record->[5]:$record->[6]\n";
}
Above is what I tried, but it managed to drop all the data from the entry. Is there a syntax I am missing to make it perform all at once?

Thanks Dale

Quote Reply
Re: Stripping misc characters form my output? In reply to
s/*//g essentially tells the regex to wipe everything in the var.
try
$record->[0] =~ s/\*//g;

if you just want to strip all non (alpha)numeric characters you can just use:
$record->[0] =~ s/[^a-zA-Z0-9]//g;

-- Gordon


s/(\d{2})/chr($1)/ge + print if $_ = '8284703280698276687967';
Quote Reply
Re: Stripping misc characters form my output? In reply to
Thanks it worked very well.

Dale