T
Ting Wang
Hallo all,
I wanted to add a line (e.g #include "some.h") at the begin of all .c files
in a directory.
I try to change one .c file with one line Perl command
perl -i.org -p -e 'BEGIN{print "#include \"some.h\"\n";}'
But this doesn't work, "#include "some.h"" will be printed into STDOUT.
I did it with a 'long' Perl script:
my $f = shift;
my $fm = $f.".org";
`touch $fm`;
open F, $f or die "can not open file $f $!";
open FM, "> $fm" or die "can not open file $fm $!";
select FM;
print "#include \"some.h\"\n";
while (<F>)
{
print;
}
close F;
close FM;
`mv $fm tmp`;
`mv $f $fm`;
`mv tmp $f`;
Is there another way to do it (a one line Perl command)?
Thanks alot
Ting
I wanted to add a line (e.g #include "some.h") at the begin of all .c files
in a directory.
I try to change one .c file with one line Perl command
perl -i.org -p -e 'BEGIN{print "#include \"some.h\"\n";}'
But this doesn't work, "#include "some.h"" will be printed into STDOUT.
I did it with a 'long' Perl script:
my $f = shift;
my $fm = $f.".org";
`touch $fm`;
open F, $f or die "can not open file $f $!";
open FM, "> $fm" or die "can not open file $fm $!";
select FM;
print "#include \"some.h\"\n";
while (<F>)
{
print;
}
close F;
close FM;
`mv $fm tmp`;
`mv $f $fm`;
`mv tmp $f`;
Is there another way to do it (a one line Perl command)?
Thanks alot
Ting