in reply to doing something with the rest of a file after matching a keyword

Undef the input seperator variable ($/) after you find it:

my $data; while($data = <FILE>) { chomp $data; $/ = undef if($data eq 'Well'); }
  • Comment on Re: doing something with the rest of a file after matching a keyword
  • Download Code

Replies are listed 'Best First'.
Re: Re: doing something with the rest of a file after matching a keyword
by Hofmator (Curate) on Jan 17, 2003 at 17:40 UTC
    some remarks:
    • it's not nice to fiddle around with the global variable $/. This might affect other parts of the program, you should localise it before usage, in this case wrap your code in
      { local $/ = $/; # your code goes here }
    • I don't think this is working as you expect it to work. Where do you want to do something with the rest of the file? If you try to do this after the loop you will find that $data is undef (because the last value <FILE> returns is undef - which terminates the while loop). If you want to deal with $data within the loop you need some extra condition to find out whether you have the right piece of the file in $data or not.

    -- Hofmator