I need to understand the working of this particular program, It seems to be quite complicated, could you please see if you could help me understanding what this program in Perl does, I am a beginner so I hardly can understand whats happening in the code given on the following link below, Any kind of guidance or insights wrt this program is highly appreciated. Thank you…:)
This program is called premove.pl.c
Its associated with one more program premove.pl,
Its code looks like this:
#!perl
open (newdata,">newdata.txt")
|| die("cant create new file\n");#create passwd file
$linedata = "";
while($line=<>){
chomp($line);
#chop($line);
print newdata $line."\n";
}
close(newdata);
close(olddata);
__END__
I am even not sure how to run the two programs mentioned here. I wonder also what does the extension of the first program signify as it has “pl.c” extension, please let me know if you know what it could mean. I need to understand it asap thats why I am posting this question, I am kind of short of time else I would try to figure it out myself, This seems to be a complex program for a beginner like me, hope you understand. Thank you again for your time.
First, regarding the perl code you posted:
See:
This is some atrociously bad code. I rewrote it for you without all the obfuscation and foolishness. This should be a bit more understandable.
The main thing that is likely to be confusing is the
<>or null filehandle read. Here it grabs a line from any files listed in program args, or if no arguments provided, it reads STDIN.This script is essentially
cat filename > newdata.txtAs for premove.pl.c, I’m no internals expert, but it looks like the author took an example for how to embed a Perl interpreter in a C program and pasted it into an oddly named file.
It looks to me like its will compile down to something equivalent to
perl. In short, another useless artifact. Was the person who produced this paid by the line?If this is the state of the code you’ve inherited, I feel sorry for you.