Hammy has asked for the wisdom of the Perl Monks concerning the following question:

Sorry for the extremely basic question, but I'm having problem finding <head> in a string. I am reading in a file and trying to locate where <head> is so I can insert a line in after it. Thanks in advance for your help.

Replies are listed 'Best First'.
•Re: trying to find <head> in a string
by merlyn (Sage) on Feb 05, 2003 at 04:09 UTC
Re: (nrd) trying to find <head> in a string
by newrisedesigns (Curate) on Feb 05, 2003 at 05:41 UTC

    Some advice not-so-directly related to your problem.

    If you're parsing HTML, and think (even the slightest bit) that you'll need to update your script to accommodate other tags, might I suggest HTML::TokeParser. TokeParser's a module that's good to know, and is great for making changes to strings of HTML.

    For projects larger than a one-tag only parser, use TokeParser. Learning it will sharpen your skills in HTML parsing, array and hash refs, and OO module use (if you aren't familiar with them now).

    John J Reiser
    newrisedesigns.com

Re: trying to find <head> in a string
by artist (Parson) on Feb 05, 2003 at 04:21 UTC
    my $string = q(This is <head> in the string); my $look = q(<head>); my $pos = length($look) + index($string,$look); substr($string,$pos,0)= 'new line'; print $string;