On Wed, 2004-05-26 at 12:09, Jose Alves de Castro wrote:
> > What I am supposed to do is 
> > 
> > 1)       parse a file and search for included files and insert those
> > included files in the file.

Lets get step by step with my solution (just so you understand what it
is doing)

> Try this:

(It's pretty simple)

> #!/usr/bin/perl -i -pw

The -i switch lets you edit the file in-place.
The -p switch prints every line of the file (after running your code on
them)

> use strict;
> 
> s/^Include\s*(.*)/

So, you happen to find a statement to include file, you just substitute
it by...

>   open(FILE,$1) || die "could not open file $1 ($!)\n";

you open the file...

>   while (<FILE>) {

and for each line...

>     print;

you print it...

>   }
>   close(FILE);

then you close it

>   '';

and you substitute the line with the "Include" statement with an empty
line (because -p will have it being printed)

>  /e;

the /e switch on the substitution makes your substitution be evaluated
(i.e., instead of having the "Include" line replaced by something, you
have it replaced by the result of some code)

Now that we got that how of the way, I would also suggest the
substitution starting with something like this:

s/^Include\s*(.*)\n/

(just so it doesn't print an extra line than you expected)

HTH,

jac

-- 
Josà Alves de Castro <[EMAIL PROTECTED]>
Telbit - Tecnologias de InformaÃÃo


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to