Gossamer Forum
Home : General : Perl Programming :

how to delete spaces out of a $value (part II)

Quote Reply
how to delete spaces out of a $value (part II)
But i need it for this piece of code:

...and i decided i only realy need to delete <P> and the SPACE's nothing more)

counter = 1;
foreach my $elem (@gesorteerd) {
my($url,$headline) = $elem =~ m|<a HREF="(.*?)"(?:.*?)>\s*(.*?)\s*</a>|sgi;


if ($headline =~ /cd-rom|CD|CD-ROM|CD ROM/){
$output .= "<!-- this headline contained an illegal word -->";
} else {

$headline =~ s/<P>//g;
$headline =~ s/<p>//g;

# so here i need an extra edition to the piece of code,
#so this script alsow removes the extra spaces

$output .= "<br>$counter - <a href=\"$url\" target=\"_new\">$headline</a>\n";

$counter++;

}
}

Quote Reply
Re: how to delete spaces out of a $value (part II) In reply to
This line of code, or a variant of it would remove all whitespace from a line, including tabs.

$headline =~ s/\s//;

Quote Reply
Re: how to delete spaces out of a $value (part II) In reply to
Going to need a /g on there.. =)

$headline =~ s/\s//g;
Quote Reply
Re: how to delete spaces out of a $value (part II) In reply to
Oops.. yes, thanks for that Alex. The "g" is good because it allows the search to continue through the entire text, not stop at the first match.

Glad for fellow Perl programmers to help out.



------------------
Fred Hirsch
Web Consultant & Programmer