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

I am sure that the solution to this problem will be simple but it clearly eludes me at the moment. I'm writing out to two files, #1 = volcano and #2 = label.txt. I added the label routine so I could check on the whether the data was fresh or stale.

I'm getting an error,

"my" variable $outfile masks earlier declaration in same scope at ./vo +lcano/volcano_parsing_2 line 14.</p> <p> syntax error at ./volcano/volcano_parsing_2 line 14, near "open "
and it's not clear to me what Perl is really complaining about. I'm not declaring things twice.

Here's the full script:

#!/usr/bin/perl -w use strict; use warnings; use XML::FeedPP; use HTML::TreeBuilder::XPath; # input my $source = 'http://www.volcano.si.edu/news/WeeklyVolcanoRSS.xml'; # output my $markers_dir = "/Users/coblem/xplanet/markers"; my $outfile = "$markers_dir/volcano"; my $labelfile = "$markers_dir/label.txt" open my $fh,">",$outfile or die "$!"; open my $label, ">", $labelfile or die "$!"; # initialize report_header(); my $volcano_color = "Chocolate"; label_header($markers_dir); close $label; # process my $feed = XML::FeedPP->new( $source ); foreach my $volcano( $feed->get_item() ) { my $title = $volcano->get('title'); my $name = substr($title, 0, index($title, '(', 0)-1); my $locn = $volcano->get('georss:point'); print $fh <<EOF \# Title : $title \# Name : $name \# Location : $locn $locn "" color=Yellow symbolsize=4 $locn "" color=Orange symbolsize=8 $locn "$name" color=$volcano_color align=Below EOF } close $fh; sub report_header { my $cur_time = localtime; print $fh <<EOF # This Volcano file created by script "volcano_parsing_1" # Matt Coblentz; Perl version v5.12.4 # For more information, see the website $source # Last Updated: $cur_time EOF } sub label_header { my $update_time = localtime; print $label <<EOF -65 -1 "Volcano Infomation Last Updated $update_time" color=Green i +mage=none position=pixel; EOF }
I will probably be embarrassed again about the error but I'm stumped!

Replies are listed 'Best First'.
Re: Opening filehandles
by Anonymous Monk on Jun 21, 2013 at 18:49 UTC
    my $labelfile = "$markers_dir/label.txt" # missing ; ^
    poj
      Thanks! I knew it had to be something simple!