in reply to Better way to perform "double split" ?

Is it a requirement that you have stored your table in a scalar? If, for instance, you get it from a `external command`, and you know that the date line is always the last, you could store it into an @array instead and use [-1] to extract the last line, without splitting.

-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re^2: Better way to perform "double split" ?
by perlpal (Scribe) on Nov 10, 2009 at 10:15 UTC
    Well , i thought of that too, but it is a requirement to store the output in a scalar.

      Well, thinking of it, you could of course also operate on substr($cmd_output,rindex($cmd_output,"\n")+1) which also would eliminate one split, but I admit that this doesn't look very elegant either. But if the format is always as shown in your example (in particular, the usage of white space), you could get the date by

      (split(/(\s|\n)/m,$cmd_output))[-3]

      (BTW, I believe that the m modifier can even be left out here - what do the experts say?).
      -- 
      Ronald Fischer <ynnor@mm.st>