Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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; }

In reply to Help needed with file output and hashes. by Seventh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-18 10:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found