Dear Fellow Monks,

I am doing a script for my temple. I hope you can help out to help me seek enlightenment in this script.
I was thinking of using a perl module to search a line from a test file and replace one of the value.

The sample text file at /home/shaolin/public_html/monkmeals.txt :

chinwoo=bun
wongfai=water
leeming=nothing
hailoo=bun

I wanted to make a function to change the meal of leeming. How can I use a perl function to loop through each line of the text file to look for leeming's meal using regex and change it to leeming=$value ?

Here is the pseudo code:
sub loadmeal { my($meal) = $_[0]; my($name,$value); open(meal,"/home/shaolin/public_html/monkmeals.txt"); LOOK FOR LEEMING=SOMETHING AND CHANGE IT TO LEEMING=$meal close(LANG); }

Please help us. Our temple's meal management system will depend on your guys. You will be helping put the right meals on the table of 100s of monks. On the behalf of the temple, I thank you in advance.

Edited by davido: Code tags added.


In reply to Dear fellow monks, I need help in regex by perlbuddy

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.