Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: string concatenation

by DamnDirtyApe (Curate)
on Nov 12, 2002 at 22:41 UTC ( [id://212435]=note: print w/replies, xml ) Need Help??


in reply to string concatenation

I can't seem to recreate your problem...

/ Mail: 0 / Tue Nov 12 14:39 / ~ $ cat concat.pl $st1 = "12"; $st2 = "08"; $result = $st1 . $st2; print "\n", $result, "\n\n"; / Mail: 0 / Tue Nov 12 14:39 / ~ $ perl concat.pl 1208 / Mail: 0 / Tue Nov 12 14:39 / ~ $

Can you post a running example of the code not working as intended?


_______________
DamnDirtyApe
Those who know that they are profound strive for clarity. Those who
would like to seem profound to the crowd strive for obscurity.
            --Friedrich Nietzsche

Replies are listed 'Best First'.
Re: Re: string concatenation
by Anonymous Monk on Nov 13, 2002 at 00:08 UTC
    Hi, The actual code is like this: ($min, $hours) = localtime(2,3); $now = "$hour" . "$min" # expect to see - $now = "1208" For minutes equal or greater than 2 digits, it's fine. Only when minutes is less than 2 digits ( < 10). Any help is appreciated.
      The problem is that $min is returned from localtime as "2" instead of "02", the same with hours for that matter you could do something like the following:
      my ($min,$hours) = (localtime)[2,3]; my $now = $hours . sprintf ("%02",$min);

      -enlil

        Thanks! EnLil. That works great.

      Enlil beat me to the sprintf solution, but if you've got more complex date formatting to do, consider using the strftime function from the POSIX module.

      use POSIX ; my $now = POSIX::strftime( "%H%M", localtime ) ; print $now, "\n" ;

      _______________
      DamnDirtyApe
      Those who know that they are profound strive for clarity. Those who
      would like to seem profound to the crowd strive for obscurity.
                  --Friedrich Nietzsche

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-19 05:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found