in reply to Re: joining string content
in thread joining string content

is this not also possible

$string = $q->param("us1"); # this is what entered +book +dog +cat print join(',', $string), "\n";
# Output "+book", "+dog", "+cat"

Replies are listed 'Best First'.
Re^3: joining string content
by Corion (Patriarch) on Jun 24, 2025 at 09:22 UTC

    Maybe the core of your problem is that you have a string like this:

    my $string = '+book +dog +cat';

    ... and you want to transform it into

    "+book", "+dog", "+cat"

    Then, the following code could do that:

    my $string = '+book +dog +cat'; my @raw_params = split /\s+/, $string; my @quoted_params = map { qq{"$_"} } @raw_params; my $quoted_params_string = join ", ", @quoted_params; print $quoted_params_string;

    Update: johngg++ spotted an error that resulted in pluses being added unnecessarily.

      This is wat i tried, but not working because the receipts numbers have to be this way

      my @recipients = ("+1234567890", "+1234567890");
      my $sender = $CGI->param("sender"); my $phone = $CGI->param("phonenumber"); # so am entering this way +1 +2344, +123344, +45454444 in textarea my $message = $CGI->param("message"); my $rep = ''; if ($sender) { my @raw_params = split /\s+/, $phone; my @quoted_params = map { qq{"$_"} } @raw_params; my $quoted_params_string = join ", ", @quoted_params; my @recipients = ($quoted_params_string); foreach my $recipient (@recipients) { my $req = HTTP::Request->new(POST => 'https://api.twilio.com/2010-04-0 +1/Accounts/AC5b68......756/Messages.json'); $req->content_type('application/x-www-form-urlencoded'); $req->authorization_basic("AC5b686.....56", "cd3.......d"); $req->content("To=$recipient&From=$sender&Body=$message"); my $response = $ua->request($req); if ($response->is_success) { $rep = "<p style='color: #29AB87;'>Messages Sent</p>"; } else { $rep = "<p style='color: #BF4F51;'>Nothing Sent</p>"; } } }

        From my cursory reading of the Twilio documentation of the Message API, it expects $message to contain a JSON message as in the examples.

        You send some string in the Body parameter that may or may not be a properly URL-encoded JSON message that Twilio expects.

        Also, concatenating strings does not make something x-www-form-urlencoded. You should properly URL-encode the parameters or look (for example) at the URL::Encode module for properly encoding all the parameters. Especially, your phone numbers contain the + character, which needs to be URL-encoded, for example as %22.

        replace

        my @raw_params = split /\s+/, $phone; my @quoted_params = map { qq{"$_"} } @raw_params; my $quoted_params_string = join ", ", @quoted_params; my @recipients = ($quoted_params_string);

        with

        my @recipients = $phone =~ /[+\d]+/g;