[EMAIL PROTECTED] writes:

> For example, If I have this in my file (see below) how can I get the
> line <val2>20<\val2>, with out reading through the entire file
>
> <val1>0<\val1>
> <val2>0<\val2>
> <val3>0<\val3>
> <val1>10<\val1>
> <val2>10<\val2>
> <val3>10<\val3>
> <val1>20<\val1>
> <val2>20<\val2>
> <val3>20<\val3>

If you are on a unix like machine or even windows with cygwin
installed you could just use the `tail' command and parse for the
regex you want.  Or if you know for sure the line you want is the very
last line then just use `tail -n1'  but for safety I think you might
want at least the last 5 so:
## Untested

  my @tailar = qx/tail -n5 filename/;
  my line;
  for (@tailar){
    if (/<\d+>/){
       $line = $_;
    }
  }
  print "[$line] contains last variable\n"; 

But unless the file is pretty big this may not be measurably faster.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to