On Aug 6, 2014, at 10:55 AM, ESChamp wrote:

> The program begins
> 
> #!/usr/bin/perl

You really should add these two lines:

  use strict;
  use warnings;

here and correct the mistakes they reveal.


> use Tie::File;
> use File::Copy 'copy';
> use File::Spec;
> 
> my $copy="000000-copy.htm";
> my $recapfile="000000recap.txt";
> my $htmfile="000000.htm";
> my $ct;
> 
> tie my @bfile, 'Tie::File', $recapfile or die "cannot tie recapfile and
> bfile $!";
> tie my @hfile, 'Tie::File', $copy or die "cannot tie copy and hfile $!";
> 
> ## hfile is the array of the lines of htmfile
> #
>    print "$copy \n";
>    print "hfile: --$hfile-- \n";
>    print "bfile: --$bfile-- \n";

You are printing $hfile and $bfile, which are separate variables from @hfile 
and @bfile and are undefined. You should print $#hfile and $#bfile here 
instead, which will show you the largest indices of the two arrays.

>    for ($ct = 0; $ct < $#hfile; $ct++)    {

You probably want '$ct <= $#hfile' as your condition here, since $#hfile is the 
greatest index of @hfile and not the number of elements, so your loop will not 
print the last element of @hfile.

>       print "$hfile[$ct] \n";
>   }
> 
> The output looks like this
> 
> 000000-copy.htm
> hfile: ----
> bfile: ----

You can also use these to print the contents of an array:

print @hfile;

print for @hfile;

for ( @hfile ) {
  print;
}


> I thought that $recapfile would be "tied" to @bfile and $copy to @hfile.
> That is, that each line of $recapfile would become an element of the
> bfile array, etc.
> 
> What have I done wrong?

Nothing major. Your program should work (with a few minor bugs). Are you sure 
there is data in 000000-copy.htm?



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to