F
Franken Sense
With forum help, I've been able to do pretty good damage with using perl
for input. It's *so much* easier than my alternatives with compiled
languages that I really feel like I'm in touch with the virtue of laziness.
I'm simply too immature with perl to, say, populate a binary tree with the
data or do many of the things that I can do with compiled languages, once I
have the data where I want it. This is, I think, a nice final touch by
Mark Krahn:
#!/usr/bin/perl
# perl m13.pl
use warnings;
use strict;
# open input file
my $filename = 'text43.txt';
open(my $fh, '<', $filename) or
die "cannot open $filename for reading: $!";
# open output file
my $filename2 = 'outfile16.txt';
open(my $gh, '>', $filename2) or
die "cannot open $filename2 for writing: $!";
local $/="";
while ( <$fh> )
{
my ( $verse, @s ) = split;
my $script = join ' ', @s;
print $gh "$verse $script\n";
}
# close input and output files
close($gh) or die("Error closing $filename2: $!");
close($fh) or die("Error closing $filename: $!");
# abridged output:
44:004:002 Being grieved that they taught the people, and preached through
Jesus the resurrection from the dead.
44:004:003 And they laid hands on them, and put them in hold unto the next
day: for it was now eventide.
44:004:004 Howbeit many of them which heard the word believed; and the
number of the men was about five thousand.
44:004:005 And it came to pass on the morrow, that their rulers, and
elders, and scribes,
So now I want main to have to call a routine to get the next $verse and
$script.
@anything = get_script( $verse, \@s)
sub get_script
{
my ( $verse, @s ) = split;
my $script = join ' ', @s;
return something;
}
Not exactly beautiful code, but my first efforts rarely look nice. The
reference for this in the camel book is §6 : Passing References. p 224
Then there's the matter of calling a perl subroutine from C.
#include <EXTERN.h>
#include <perl.h>
static PerlInterpreter *my_perl;
int main(int argc, char **argv, char ** env)
{
char *args[] = {Null};
my_perl = perl_alloc();
perl_construct(my_perl);
perl_parse(my_perl, NULL, argc, argv, NULL);
call_argv("get_script", args);
perl_destruct(my_perl);
perl_free(my_perl);
return 0;
}
The reference here is §21 of the camel book, p. 540.
Does any of this look close?
for input. It's *so much* easier than my alternatives with compiled
languages that I really feel like I'm in touch with the virtue of laziness.
I'm simply too immature with perl to, say, populate a binary tree with the
data or do many of the things that I can do with compiled languages, once I
have the data where I want it. This is, I think, a nice final touch by
Mark Krahn:
#!/usr/bin/perl
# perl m13.pl
use warnings;
use strict;
# open input file
my $filename = 'text43.txt';
open(my $fh, '<', $filename) or
die "cannot open $filename for reading: $!";
# open output file
my $filename2 = 'outfile16.txt';
open(my $gh, '>', $filename2) or
die "cannot open $filename2 for writing: $!";
local $/="";
while ( <$fh> )
{
my ( $verse, @s ) = split;
my $script = join ' ', @s;
print $gh "$verse $script\n";
}
# close input and output files
close($gh) or die("Error closing $filename2: $!");
close($fh) or die("Error closing $filename: $!");
# abridged output:
44:004:002 Being grieved that they taught the people, and preached through
Jesus the resurrection from the dead.
44:004:003 And they laid hands on them, and put them in hold unto the next
day: for it was now eventide.
44:004:004 Howbeit many of them which heard the word believed; and the
number of the men was about five thousand.
44:004:005 And it came to pass on the morrow, that their rulers, and
elders, and scribes,
So now I want main to have to call a routine to get the next $verse and
$script.
@anything = get_script( $verse, \@s)
sub get_script
{
my ( $verse, @s ) = split;
my $script = join ' ', @s;
return something;
}
Not exactly beautiful code, but my first efforts rarely look nice. The
reference for this in the camel book is §6 : Passing References. p 224
Then there's the matter of calling a perl subroutine from C.
#include <EXTERN.h>
#include <perl.h>
static PerlInterpreter *my_perl;
int main(int argc, char **argv, char ** env)
{
char *args[] = {Null};
my_perl = perl_alloc();
perl_construct(my_perl);
perl_parse(my_perl, NULL, argc, argv, NULL);
call_argv("get_script", args);
perl_destruct(my_perl);
perl_free(my_perl);
return 0;
}
The reference here is §21 of the camel book, p. 540.
Does any of this look close?