in reply to Deleting everything before a string

$content =~ s/.*\+_(.*?)\+_.*/$1/s; #or $content = (split/\+_/,$content)[1];

Replies are listed 'Best First'.
Re: Re: Deleting everything before a string
by maverick (Curate) on Dec 21, 2000 at 09:07 UTC
    I would prefer
    @content = ($content =~ /\+_(.*?)\+_/sg);
    since it would work for more that occurance of the replacement string in the file.

    /\/\averick

      Although it is unclear to me how Anonymous Monk would want to handle in that case. Perhaps Anonymous Monk would prefer @content = ($content =~ /\+_(.*?)(?=\+_)/)sg); or /\+_(.*)\+_/s
Re: Re: Deleting everything before a string
by repson (Chaplain) on Dec 21, 2000 at 07:08 UTC
    And then of course writing the new $content over the file you read in from.

    On the other hand if you are dealing with a large file then I would suggest searching line by line (or chunk by chuck) for +_...+_ and then storing that, closing the file, writing the found information to a new file of the same or different name.

      Or perhaps setting $/ to '+_' and $^I to '.bak'