http://www.perlmonks.org?node_id=1126207


in reply to Multiply the numbers in a text file

Divide your problem in smaller chunks

1-You will need to acces to the input file values, so study how to create a filehandle with the function open. Open a terminal and write perldoc PerlIO for the man pages.

2-You'll need to select your desired numbers. How to do this depend on what is your strategy to pick a number and discard another but you will need probably a regexp. See perldoc perlrequick for a short intro and perldoc perlre for a more extensive and complete manual

3-Replace all non-zero values. See "search and replace" in perldoc perlrequick. Register your values to a variable and then multiply your var with something like '$mynevvalue = $myoldvalue * 5'

4-print out the text file: you'll need an output filehandle. Read 'perldoc PerlIO' and study the function open.

5-don't forget to close both filehandles with the function close

  • Comment on Re: Multiply the numbers in a text file