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

Re: [PBML] Can anyone explain this code?

Expand Messages
  • Jonathan E. Paton
    ... I ll try. :) ... The current line is processed as: Start at beginning of line... Zero or more spaces... Nonspaces - place in $1... One or more spaces...
    Message 1 of 2 , Jan 31, 2002
    • 0 Attachment
      > I am trouble shooting a script that does a ps -eo
      > command and kills a process if it meets certain
      > criteria and came upon these lines. Can anyone
      > explain what each line does?

      I'll try. :)

      > I know if the variable meets this condition it
      > goes to next line. The variables I get from
      > doing a ps -eo and is either the elapses time
      > or cpu time.
      >
      > if ($line =~ /^\s*(\S+)\s+(\S+)\s+(\S+)/)

      The current line is processed as:

      Start at beginning of line...
      Zero or more spaces... Nonspaces - place in $1...
      One or more spaces... Nonspaces - place in $2...
      One or more spaces... Nonspaces - place in $3

      \s = spaces
      \S = nonspaces
      * = zero or more
      + = one or more

      Hope that helps for that one!

      > ($eltime =~ /^(\d+)-/) { $eldays = $1; }

      Err... this isn't valid use of the if statement - have you
      grouped some seperate bits you didn't understand? Should
      be:

      if (condition) {
      action
      }

      Assuming it's an if:

      $eldays = leftmost digits of $eltime

      > if ($cputime =~ /^\d+-/) { $cpumin = 1440; }

      If $cputime has digits at the start, followed by a '-',
      then set $cpumin to 1440.

      > # elsif ($cputime =~ /^(\d+):(\d+):\d+/)

      Else if it's a timestamp like 9:34:39, do something...

      Jonathan Paton

      __________________________________________________
      Do You Yahoo!?
      Everything you'll ever need on one web page
      from News and Sport to Email and Music Charts
      http://uk.my.yahoo.com
    Your message has been successfully submitted and would be delivered to recipients shortly.