Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^2: Simple Text Manipulation

by pseingalt (Initiate)
on Feb 06, 2011 at 11:08 UTC ( #886498=note: print w/replies, xml ) Need Help??

in reply to Re: Simple Text Manipulation
in thread Simple Text Manipulation

Here's the script; I added : because the word "Article" which always begins the line, is followed immediately by a colon. Using the syntax, "$ perl test.tex -w" I'm returned to the command line and the file was not processed.



(I've replaced brackets [] with braces {} since they don't seem to show up here.

Replies are listed 'Best First'.
Re^3: Simple Text Manipulation
by Albannach (Prior) on Feb 06, 2011 at 19:43 UTC
    I think you need to read our responses more carefully. Corion gave you most of the answer, and I helped you with the substitution, noting in my response: "...which you would apply line by line as you read through the file". If you don't understand what Corion wrote, then ask a specific question, but please don't just ignore the advice. As you seem to need a little more fundamental guidance, I'll say this: Perl will let you do what you want in many possible ways, but a basic approach to run your code in a file (your from the Perl command line as you appear to have chosen, that code will have to:

    • open the input file (tip: check out the "null filehandle" in perlop)
    • read lines one by one,
    • apply the substitution regex you want, and
    • write the result somewhere. Your output could go to the console, pipe to a file, get written to a file you opened in your code, or you could even investigate Perl's handy feature for editing a file in place via the -i command line option (read up on this in perlrun).
    All your code (and please do use code tags - see Writeup Formatting Tips just above the editing box when you're composing your message) does is apply a substitution to nothing and ends, so of course you get no result.

    Quick tips on your regex modification: The colon has no special meaning so you need not put it in square brackets. Functionally there is no difference, but using unnecessary characters makes it harder for others to easily pick out what you mean to do. Also, unless you want to accept cases of more than one colon, don't put a + after the colon. Please read up on regular expressions; the + symbol is not used to assemble parts of a regex, it is a quantifier and means 'match one or more of the preceding element'.

    I'd like to be able to assign to an luser

Re^3: Simple Text Manipulation
by Corion (Pope) on Feb 06, 2011 at 11:12 UTC

    I gave you three steps you need to implement for your program. Which of these steps is your program supposed to implement?

    As an aside, if you use <code>...</code> tags around your code (and data), as suggested when you compose a node, your code will render as code, without HTML or bracket interpolation..

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2018-11-17 04:13 GMT
Find Nodes?
    Voting Booth?
    My code is most likely broken because:

    Results (202 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!