Wroof has asked for the wisdom of the Perl Monks concerning the following question:

Good morning all,

I am not sure if it is due to the early hours (now 7am started on this at 5am) but I cannot, for the life of me, work out how to load a + into a string.

I have this string here

my $SettlementTimeString = $SettlementDateTime->ymd."T".$SettlementDateTime->hms.".".$SettlementDateTime->nanosecond."+12:00";

but it removes the + when I try to use the string elsewhere. (The string is being sent to a server which then tries to convert it to a DateTime but does not see the + that is expecting).

Any help would be great thanks.

Replies are listed 'Best First'.
Re: How to load a + into a string
by Perlbotics (Archbishop) on Jun 16, 2014 at 19:35 UTC

    The string is being sent to a server which then tries to convert it to a DateTime but does not see the + that is expecting

    HTTP? Try %2B instead of +. See also Percent-encoding.

      Thanks Perlbotics. Yes sorry I forgot to mention that it was via HTTP and once I changed it to %2B it worked perfectly. Also helped me work out a few other bugs in the code. Thanks again.

        Are you sending it via a HTTP GET parameter? The "cleaner" way to do that would be with something like URI:

        use URI; my $uri = URI->new("http://www.foo.com/bar"); $uri->query_form( param_one => "hello+world&foo=bar", param_two => "blah" ); print "$uri\n"; # prints "http://www.foo.com/bar?param_one=hello%2Bworld%26foo%3Dbar&p +aram_two=blah"
Re: How to load a + into a string
by BrowserUk (Patriarch) on Jun 16, 2014 at 19:36 UTC

    Try:

    my $SettlementTimeString = $SettlementDateTime->ymd() . "T" . $SettlementDateTime->hms() . "." . $SettlementDateTime->nanosecond() . "+12:00";

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: How to load a + into a string
by Anonymous Monk on Jun 16, 2014 at 19:35 UTC
    Post compilable/runnable code that demonstrates this magic, not word descriptions, code
Re: How to load a + into a string
by Anonymous Monk on Jun 16, 2014 at 19:57 UTC

    Your code works for me, $SettlementTimeString contains the "+". This also works for me: $SettlementDateTime->strftime("%Y-%m-%dT%H:%M:%S.%9N%z") As the other monks have suggested, your "+" is probably getting list elsewhere.