title: put formatted output in a file, perl format
body: <p>If we set a specified format like this. Is there any way that we can copy the output and put it in a file.</p>
  
  <p>ps: when i use strict, it shows "Global symbol "$counter" requires explicit package name at aggregator.pl line 19". What caused this? I have used local to define its scope, so i got a bit confused. Hope someone can give me a reponse. thx a lot</p>
  
  <pre><code>enter code here
  
  # Setup includes
  # use strict;
  use XML::RSS;
  use LWP::UserAgent;
  # Declare variables for URL to be parsed
  my $url2parse;
  # Get the command-line argument
  my $arg = shift;
  # Create new instance of XML::RSS
  my $rss = new XML::RSS;
  # Get the URL, assign it to url2parse, and then parse the RSS content
  $url2parse = get($arg);
  die "Could not retrieve $arg" unless $url2parse;
  $rss-&gt;parse($url2parse);
  #create arrays to hold data
  my @titles;
  local $counter = 0;
  
  #open file and write .txt output to it
  open my $fh, "&gt;output.txt" or die "File creation failed: $!";
  
  # Print the channel items
  foreach my $item (@{$rss-&gt;{'items'}}) {
       $titles[$counter] = $item-&gt;{'title'};
   &amp;format_output($item-&gt;{'title'});
   $counter++;
  }
  sub get { 
      my $url = shift; 
      my $ua = LWP::UserAgent-&gt;new(); 
      my $res = $ua-&gt;get($url); 
      die ("Could not retrieve $url: " . $res-&gt;status_line) unless($res-&gt;is_success); 
      return $res-&gt;content; 
  } 
  
  sub format_output {
      local($title) = @_;
      $~ = "MYFORMAT";
      write;
      print $fh @_;
  }
  format MYFORMAT = 
  
  =======================
    Title :~ ^&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;
  $title
  =======================
  .
  </code></pre>