Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] Problem with SPLIT function...for "date" command in Linux

Expand Messages
  • manoj mitra
    Hi! The problem you faced, is just because - perl keeps two space for printing date. You just need to remove the extra space in between. The code should be the
    Message 1 of 1 , Oct 5, 2006
    • 0 Attachment
      Hi!

      The problem you faced, is just because - perl keeps two space for printing date. You just need to remove the extra space in between. The code should be the following -

      $date = `date`;
      print "Today is $date\n";
      $date =~ s/ +/ /g;
      ($day, $month, $dat, $time, $area, $year) = split(/ /,$date);
      print "Day : $day\n";
      print "Month : $month\n";
      print "Date : $dat\n";
      print "Time : $time\n";
      print "Area : $area\n";
      print "Year : $year\n";

      Manoj

      ----- Original Message ----
      From: shailesh <shail_hegde@...>
      To: perl-beginner@yahoogroups.com
      Sent: Thursday, October 5, 2006 4:02:44 PM
      Subject: [PBML] Problem with SPLIT function...for "date" command in Linux

      hello,
      This is my perl script to split the various entities available as
      part of the "date" command in Linux:

      #start
      $date = `date`;
      print "Today is $date\n";
      ($day, $month, $dat, $time, $area, $year) = split(/ /,$date);
      print "Day : $day\n";
      print "Month : $month\n";
      print "Date : $dat\n";
      print "Time : $time\n";
      print "Area : $area\n";
      print "Year : $year\n";
      #end

      This is the output of running the above :
      #<<start of output>>
      Today is Thu Oct 5 09:44:07 IST 2006

      Day : Thu
      Month : Oct
      Date :
      Time : 5
      Area : 09:44:07
      Year : IST
      #<<end of output>>

      My doubt: Why is the Date output empty ?? Is it becoz of the double
      space b/w "Oct" and "5".. the time, area and year are wrong also..!!!

      I believe the split shd work irrespective of the no. of spaces in
      b/w the character strings..

      Plz let me know
      shailesh.






      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.