Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: joining string content

by Corion (Patriarch)
on Jun 24, 2025 at 08:59 UTC ( [id://11165456]=note: print w/replies, xml ) Need Help??


in reply to joining string content

Given your code, that's impossible.

my $string = (+book +dog +cat);

Given your code, Perl sees:

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

... which makes Perl calculate the sum of book, dog and cat, which is zero, because (non-number-looking) strings evaluate to 0 in Perl.

Can you show us a complete, runnable example of the code and data you have that replicates your problem?

I think you want something like Text::CSV_XS, if your goal is to produce a CSV file, for example for Excel.

Replies are listed 'Best First'.
Re^2: joining string content
by joyfedl (Acolyte) on Jun 24, 2025 at 09:04 UTC

    is this not also possible

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

      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>"; } } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11165456]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2026-02-18 03:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.