hi! i have a Perl code in here that when ran the program accepts any Perl codes from the user input (<STDIN>, of course use no syntax errors), then after breaking the multiline input, the inputs will be part of the program codes and well executed simoultaneously after breaking the multiline input.
my novice codes as follows:
[CODE=perl]#!/perl/bin/perl
use strict;
if (-e "sign.me") {
unlink "sign.me";
} else {
print "Please enter the Perl codes you want to insert: \n";
my @nEW_cODES_ = <STDIN>;
unshift @nEW_cODES_, "eval {\n";
push @nEW_cODES_, "};\n";
push @nEW_cODES_, "print \"An error occured: \$@\" if \$@;\n";
open FILE, "< ".$0;
my @rEVISED_cODES_ ;
for (<FILE>) {
if ($_ eq "#END\n") {
for (@nEW_cODES_) {
push @rEVISED_cODES_ , $_;
}
}
push @rEVISED_cODES_ , $_;
}
close FILE;
open FILE, "> ".$0;
for (@rEVISED_cODES _) {
print FILE $_;
}
close FILE;
open FILE, "> sign.me";
close FILE;
system "perl ".$0;
exit;
}
#START
#END
print "Hello World!";[/CODE]
a sample of what i inputted was as follows:
[CODE=perl]
print "Enter the First Number: ";
chomp(my $nUM1_ = <STDIN>);
print "Enter the Second Number: ";
chomp(my $nUM2_ = <STDIN>);
print "The Sum of $nUM1_ and $nUM2_ is ",$nUM1_+$nUM2_ ."\n";
[/CODE]
the whole output of the program looks like this:
a brief explanation: any Perl codes you enter on the multiline input is stored on the same source file. when stored, this program calls the Perl interpreter to compile the new source file as well it is run. while after doing the system call the program exit then the new source file takes incharge. giving the look of a program as a single running program.
is there any other way around to embed perl codes on the program source file of the currently running program on the fly?
thanks
From: PerlPhi
my novice codes as follows:
[CODE=perl]#!/perl/bin/perl
use strict;
if (-e "sign.me") {
unlink "sign.me";
} else {
print "Please enter the Perl codes you want to insert: \n";
my @nEW_cODES_ = <STDIN>;
unshift @nEW_cODES_, "eval {\n";
push @nEW_cODES_, "};\n";
push @nEW_cODES_, "print \"An error occured: \$@\" if \$@;\n";
open FILE, "< ".$0;
my @rEVISED_cODES_ ;
for (<FILE>) {
if ($_ eq "#END\n") {
for (@nEW_cODES_) {
push @rEVISED_cODES_ , $_;
}
}
push @rEVISED_cODES_ , $_;
}
close FILE;
open FILE, "> ".$0;
for (@rEVISED_cODES _) {
print FILE $_;
}
close FILE;
open FILE, "> sign.me";
close FILE;
system "perl ".$0;
exit;
}
#START
#END
print "Hello World!";[/CODE]
a sample of what i inputted was as follows:
[CODE=perl]
print "Enter the First Number: ";
chomp(my $nUM1_ = <STDIN>);
print "Enter the Second Number: ";
chomp(my $nUM2_ = <STDIN>);
print "The Sum of $nUM1_ and $nUM2_ is ",$nUM1_+$nUM2_ ."\n";
[/CODE]
the whole output of the program looks like this:
Code:
Please enter the Perl codes you want to insert: print "Enter the First Number: "; chomp(my $nUM1_ = <STDIN>); print "Enter the Second Number: "; chomp(my $nUM2_ = <STDIN>); print "The Sum of $nUM1_ and $nUM2_ is ",$nUM1_+$nUM2_."\n"; ^Z Enter the First Number: 1 Enter the Second Number: 2 The Sum of 1 and 2 is 3 Hello World!
is there any other way around to embed perl codes on the program source file of the currently running program on the fly?
thanks
From: PerlPhi
Comment