Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: How do I remove newline character from a number got from unix command

by Tux (Monsignor)
on Sep 04, 2013 at 12:19 UTC ( #1052314=note: print w/ replies, xml ) Need Help??


in reply to How do I remove newline character from a number got from unix command

  1. As the others already said: use chomp
  2. Why use external commands when all is avail in perl?
    my $year = 1900 + (localtime)[5];
  3. Why quote $year in the print? print $year; will do just what you want. There is no need for forced stringification.
  4. Why printf? You are not using any formatting at all.

Enjoy, Have FUN! H.Merijn


Comment on Re: How do I remove newline character from a number got from unix command
Select or Download Code
Re^2: How do I remove newline character from a number got from unix command
by tousifp (Novice) on Sep 04, 2013 at 12:22 UTC

    How can I have date and month in a similar fashion? I need like this : 2013-09-04 and "Sep 04"

      my $date_as_YYYY_MM_DD = do { my @d = localtime; sprintf "%04d-%02d-%02d", $d[5] + 1900, ++$d[4], $d[3]; };

      but that is most likely better done with POSIX' strftime:

      use POSIX qw( strftime ); my $d_YMD = POSIX::strftime ("%Y-%m-%d", localtime); my $d_Md = POSIX::strftime ("%d %b", localtime); # I prefer 04 Sep ov +er Sep 04

      Enjoy, Have FUN! H.Merijn
        t a n k s!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (11)
As of 2014-08-28 00:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (253 votes), past polls