Your followup post still is a little vague, but it makes it look as though you want to remove the word 'score' and the very next word that follows it. And then you want to modify the actual number, and finally insert the stuff you chopped off back into the string. ...more or less... See the following example, and then adapt its philosophy for your own situation.

my $score = 'score SOME_WORD 3.0 3.0 3.0 3.0'; my $removed_word = $score =~ s/^(score\s\b\w+\b\s)//; # $removed_word now contains 'score' plus whatever # unknown word you removed, plus trailing single space. # $score now is left only with what comes after the removed word, # and preceding whitespace has been removed. # Now you can do whatever processing you wish. # Then to put it back together: $string = $removed_word . $score;

The supplied regexp captures and then removes 'score', followed by a single whitespace, followed by an unknown "word" (the \b word boundry zero-width assertion may be unnecessary, but to me it makes it clear that you're going for a single word), followed by the single whitespace preceding the number.

$removed_word gets all the stuff we just captured and removed. $string is left with what follows, which, as you state, is the score you want to show on the webpage.

I'm aware that I didn't give you a cut-n-paste snippit, using your variable names, etc. I chose not to because I didn't want to have my example cut-n-pasted into your code, and risk my improperly using your variable names due to not seeing enough of your original code. But if you take a moment and understand what is going on in my example, you'll probably see how to modify your code to get it to do what you want.

I also recommend looking at perldoc perlre (the regular expression Perl documentation page) and perlretut (the regular expression tutorial Perl documentation page). If you have Perl, you have those pages on your computer too. They will help you to broaden your base so that you can work through this type of question on your own.

A good way to get a clear answer is to post a clear question along with a snippet of stand-alone example code to illustrate your question. Try to boil your example code down to the lowest common denominator. If all you're asking is how to extract a portion of a string, and then delete the portion that you extracted, post sample code that creates the string, and illustrates what you've attempted in reaching your goal, uncluttered by mysterious arrays and variable names that are peripheral to the core question. Often when you take this little step of isolating your question and illustrating it in stand-alone code, you will find the answer yourself along the way. This is just a suggestion, but I've found many times that it works for me.

One more tip. If you're taking keyed input directly from a user on the web and writing it out to a file, you should realize that the input is tainted until you've thoroughly washed it. When you write user input to a file, you're opening the back door to trouble. At very minimum, run your script with the -T option (Taint checking).

Dave

"If I had my life to do over again, I'd be a plumber." -- Albert Einstein


In reply to Re: Re: Re: take out section of a string then put it back by davido
in thread take out section of a string then put it back by mr_evans2u

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.