bingohighway has asked for the wisdom of the Perl Monks concerning the following question:
So the code above is split into two sections. The main code, and the code to be read (temp.txt). The if statement in temp.txt is signified by a "#" and the 'if' command can be recognised by a regex. The bit within the brackets ($var == 100) I would like to just dump straight into a real if statement, (or even just execute 'if($var == 100)'). The reason for dumping is to avaid having to code all those operators and brackets!#main Perl file my $var = 100; my $filename = "temp.txt"; open my IN, '<', $filename or die "Can't read '$filename': $!"; while (defined (my $line = <IN>)) { if($line =~ /^#/){ #execute perl if statement here #Do something based on if statement processed }; }; ## File to be read, temp.txt## Some random text, not Perl. #if($var == 100) output this text to a file #endif
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reading and executing Perl
by targetsmart (Curate) on Apr 02, 2009 at 12:15 UTC | |
by bingohighway (Acolyte) on Apr 02, 2009 at 12:20 UTC | |
by bingohighway (Acolyte) on Apr 02, 2009 at 12:27 UTC | |
|
Re: Reading and executing Perl
by jethro (Monsignor) on Apr 02, 2009 at 12:26 UTC | |
|
Re: Reading and executing Perl
by ELISHEVA (Prior) on Apr 02, 2009 at 12:43 UTC | |
|
Re: Reading and executing Perl
by Ish (Acolyte) on Apr 02, 2009 at 12:25 UTC | |
by jethro (Monsignor) on Apr 02, 2009 at 12:51 UTC | |
by Ish (Acolyte) on Apr 02, 2009 at 12:56 UTC |