Hello monks!
I have the following bit of code that I'm having a bit of trouble with. I'm in Iraq right now, so I apologize if a lot of this is something I can search/read about - internet time and books on Perl are in short supply around here.
Basically I have this script that opens a file called ccrutil.pl, and goes through it looking for a tag of "#CCR", then spits that, and the following line, to an html file.
It _kind of_ works, but I'm having two problems - one is that I get an error that says "Use of uninitialized hash element at extract1.pl line 48, <DATA> line (60, 80, 136)" when executing.
Secondly, it's ignoring my entire top section where I build the html header, and I don't know why. Any insight at all would really be appreciated, and thank you as always! :D
#!/usr/bin/perl -w
use strict;
use IO::File;
use Data::Dumper;
use Getopt::Long;
open(DATA,"ccrutil.pl") or die $!;
my $file ="ccrutil.html";
open FILE, ">$file" or die "unable to open $file $!";
print FILE "\<html\>\n"; # Build HTML header
print FILE "\<title\>CCRUTIL.HTML\<\\title\>\n";
print FILE "\<body bgcolor\=\"black\"\>\n";
close FILE;
my %functxt;
while (<DATA>) {
my $line = $_;
chomp($line);
if ($line =~ /^\#CCR/) {
my ($functionName) = $line =~ /^\#CCR-(.*)/;
my $desc = <DATA>; # pull the next line
$functxt{$functionName} = $desc;
}
}
foreach my $func (keys(%functxt)) {
my $text = $functxt{$func};
my $file ="ccrutil.html";
open FILE, ">$file" or die "unable to open $file $!";
print FILE "\<b\>Function $func does $text\<\/b\>\n";
close FILE;
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.