shockme has asked for the wisdom of the Perl Monks concerning the following question:

I've just written my first module, and (predictably) it's causing me some problems. When I execute the script which calls the module, I get the following:

Can't find string terminator "`" anywhere before EOF at /usr/local/lib/perl/5.6.1/BuildLink.pm line 59.
Compilation failed in require at ./test.pl line 4.
BEGIN failed--compilation aborted at ./test.pl line 4.

I'm just playing with some code and trying out some new things, so please don't expect the following code to be nirvana.

Here's the script which calls the module:

#!/usr/bin/perl -w use strict; use BuildLink; my $file = "/www/htdocs/shock/history.php"; my @words = buildLinks($file); print @words;

Not much to that. Here's the module:

package BuildLink; use strict; use Exporter; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); $VERSION = 1.00; @ISA = qw(Exporter); @EXPORT = (); @EXPORT_OK = qw(&buildLinks); %EXPORT_TAGS = ( DEFAULT => [qw(&buildLinks)]); my @linkedFile = buildLinks(@_); return @linkedFile; sub buildLinks { my $FileName = shift; my @wordList = bustFile($FileName); } sub bustFile { my $FileName = shift; open(IN, "$FileName") || die "Cannot open $FileName: $!\n"; my @text = do {local $/; <IN> }; @pieces = split_text(@text); @pieces = check_links(@pieces); return @pieces; } sub split_text { $_[0] =~ /("[^"]*"|[^\s"]+)/g; $_[0] =~ s/\.$//g; $_[0] =~ s/^\.//g; $_[0] =~ s/\s$//g; $_[0] =~ s/^\s//g; } sub check_links { my @pieces = @_; my @list; open(WORDLIST,"/www/htdocs/data/linklist.txt") || die "Cannot open /www/htdocs/data/linklist.txt: $!\n"; foreach my $word (@pieces){ open(WORDLIST,"/www/htdocs/data/linklist.txt") || die "Cannot open /www/htdocs/data/linklist.txt: $!\ +n"; my ($checkLine, $checkWord, $checkLink); while ($checkLine = <WORDLIST>) { ($checkWord, $checkLink) = split(/\t/, $checkLine); if ($word eq $checkWord) { $word = "<a href=\"$checkLink\">$word</a>";` } push @list, $word; last if ($checkWord gt $word); } close WORDLIST; } return @list; } 1;

Any thoughts on how to correct this error would be great. Thanks!

If things get any worse, I'll have to ask you to stop helping me.

Replies are listed 'Best First'.
Re: Can't find string terminator
by BeernuT (Pilgrim) on Mar 25, 2002 at 05:00 UTC
    if ($word eq $checkWord) { $word = "<a href=\"$checkLink\">$word</a>";` <--- }
    should be
    if ($word eq $checkWord) { $word = "<a href-\"$checkLink\">$word</a>"; }
    better yet
    if ($word eq $checkWord) { $word = qq{<a href="$checkLink">$word</a>}; }
    You also opened WORDLIST twice in your &check_links sub, 1 before you looped through @pieces and then you on each iteration of @pieces.

    Also your perl -c complained about @pieces being global when i checked it against your mod.

    -bn
      Oh, for crying out loud . . . maybe my wife is right and I should go to bed . . . thanks!

      If things get any worse, I'll have to ask you to stop helping me.

(Ovid) Re: Can't find string terminator
by Ovid (Cardinal) on Mar 25, 2002 at 05:06 UTC

    Update: aargh! Late again :)

    In &check_links, you'll see the following line of code:

    $word = "<a href=\"$checkLink\">$word</a>";`

    No doubt you're wondering about that single quote after the semicolon :)

    By the way, you also forgot to declare @pieces.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.