http://www.perlmonks.org?node_id=504388

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

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; }