Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Simple Text Manipulation

by Corion (Pope)
on Feb 05, 2011 at 09:37 UTC ( #886380=note: print w/ replies, xml ) Need Help??


in reply to Simple Text Manipulation

You don't show what you've tried so far, so I'll give you a general description of how I'd approach the problem. The problem can be split up into three parts:

  1. Loop through each line of the file
  2. Check whether the current line matches your target ("starts with 'Article'")
  3. Output the reformatted line

The code for each part also is relatively self-contained:

  1. #!perl -w use strict; # loop through the file while (<>) { print };
  2. if (/^Article\b/) { s/\s*$//; # remove trailing whitespace and newlines print "Line [$_] is a heading."; };
  3. $_ = "Article 1 News"; print "\\subsection*{$_}";

You'll have to assemble these parts into a coherent whole and/or ask questions about the parts that are still unclear to you. If you chose a different approach, it will help us to help you better if you show your approach.


Comment on Re: Simple Text Manipulation
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://886380]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2014-12-27 01:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls