[thelist] foreach problem with Perl
andre torrez
andre at torrez.org
Sun Jul 22 23:22:38 CDT 2001
yeah, straight outta Perl Cookbook, I highly recommend it:
##############################################
$string = " Hi, I have too much whitespace ";
$string = trim($string);
print $string;
exit(1);
sub trim {
my @out = @_;
for (@out) {
s/^\s+//;
s/\s+$//;
}
return wantarray ? @out : $out[0];
}
##################
# note, you can also
# pass this function an
# array of strings
##################
At 10:04 PM 7/22/2001 -0600, you wrote:
> I need some perl help. I'm writing a script to automate multiple
>majordomo subscriptions from a web form by sending an email using
>sendmail. Everything's working fine except that an extra space is added at
>the beginning of some of the lines in the final email (actually, every one
>after the first line). Here is the body of the email in question:
>
><SNIP>
>
>subscribe list1-l name at somewhere.com
> subscribe list2-l name at somewhere.com
> subscribe list3-l name at somewhere.com
>
></SNIP>
>
>I think it might have something to do with a foreach block i'm using
>to modify the original imported array. Here is the relevant code:
>
><SNIP>
>
>my $c = new CGI;
>my $email = $c->param("email");
>my @lists = $c->param("listname");
>
>foreach $list (@lists) {
> $list="subscribe "."$list"." $email\n";
>}
>
>open MAIL, "|/usr/lib/sendmail -t -i"
> or die "Could not open sendmail: $!\n";
>
> print MAIL <<END_OF_MESSAGE;
>To: mdomo\@somewhere.com
>From: webmaster\@somewhere.com
>Subject: Test
>@lists
>END_OF_MESSAGE
>
> close MAIL or die "Could not close sendmail properly: $!\n";
>
></SNIP>
>
>The web page containing the original form is here:
>http://cgi.cadvision.com/~ppdmweb/development/listserv/index.html
>
>Do any of the perl gurus out there know how to get rid of these extra
>lines? I don't know if it'll affect majordomo but this is really bugging
>me. Any help would be greatly appreciated.
>
>.tony
>
>
>---------------------------------------
>For unsubscribe and other options, including
>the Tip Harvester and archive of TheList go to:
>http://lists.evolt.org Workers of the Web, evolt !
More information about the thelist
mailing list