mpj196884 has asked for the wisdom of the Perl Monks concerning the following question:
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,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: printing a hash
by perliff (Monk) on May 26, 2009 at 06:25 UTC | |
|
Re: printing a hash
by AnomalousMonk (Archbishop) on May 26, 2009 at 08:47 UTC | |
|
Re: printing a hash
by toolic (Bishop) on May 26, 2009 at 15:23 UTC | |
by planetscape (Chancellor) on May 27, 2009 at 10:17 UTC | |
|
Re: printing a hash
by GrandFather (Saint) on May 26, 2009 at 21:46 UTC |