Hello perlmonks

I'm hoping to make my first properly-marked post here. I'm trying to get basic things done in perl. I've written a script that separates comments from scriptures, but I don't seem to have figured out how to print it:

#!/usr/bin/perl # perl gg2.pl use warnings; use strict; my $filename3 = 'ot5.txt'; open(my $hh, '<', $filename3) or die "cannot open $filename3 for reading: $!"; # open output file my $filename2 = 'outfile16.txt'; open(my $gh, '>', $filename2) or die "cannot open $filename2 for writing: $!"; # open output file my $filename4 = 'outfile43.txt'; open(my $hg, '>', $filename4) or die "cannot open $filename4 for writing: $!"; my %Scripts; my %comments; local $/=""; while ( <$hh> ) { my @s = split /\s+/, $_; my $verse = $s[0]; my $counter = 0; if ($s[0] =~ m/^\d/) { my $verse = $s[0]; my $script = join(' ', @s[1..$#s]); $Scripts{$verse} = $script; print $gh $_; } else { $counter++; my $comment = join(' ', @s); $comments{$counter} = $comment; print $hg $_; } } foreach $verse (sort keys %Scripts) { print "$verse => $Scripts($verse)\n"; } # close input and output files close($hh) or die("Error closing $filename3: $!"); close($gh) or die("Error closing $filename2: $!"); close($hg) or die("Error closing $filename4: $!");

Perl.exe complains with the following: C:\MinGW\source>perl gg2.pl Global symbol "$verse" requires explicit package name at gg2.pl line 52. Global symbol "$verse" requires explicit package name at gg2.pl line 54. Global symbol "$Scripts" requires explicit package name at gg2.pl line 54. Global symbol "$verse" requires explicit package name at gg2.pl line 54. Execution of gg2.pl aborted due to compilation errors. C:\MinGW\source>

Fishing for tips,


In reply to printing a hash by mpj196884

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.