Loading ...
Sorry, an error occurred while loading the content.
 

printing from one filehandle to another

Expand Messages
  • Noah
    Hi there, I am attempting to print (output) the data from one filehandle called OLD to another called COMMUNITY. In the following code I have modified the
    Message 1 of 2 , Sep 5, 2006
      Hi there,

      I am attempting to print (output) the data from one filehandle called
      OLD to another called COMMUNITY. In the following code I have modified
      the newline structure using the undefined '$/' and would like to dump
      that to a filehandle called COMMUNITY.

      Here is the code:

      foreach $old_file (@files) {
      my %community;
      ($new_file = $old_file) =~ s/txt/new.txt/;
      open NEW, ">$new_file" || die "Couldn't open file: $!";
      open OLD, "<$old_file" || die "Failed to open $old_file: $!";
      open COMMUNITY, "<it" || die "Failed to open $old_file: $!";
      undef $/;

      while (<OLD>) {
      print COMMUNITY "$_";
      @as_paths_used = m/from\s+policy\s+ap-(\d+)/g;
      @community_used = m/from\s+policy\s+cl-(\d+)/g;
      @prefix_list_used = m/from\s+policy\s+pl-(\S+)/g;
      @route_map_used = m/from\s+policy\s+rm-(\S+)/g;
      $as_path_count = s/policy-statement\s+ap\S+\s+\{.*?\}\s*\}\s+//gs;
      $community_count = s/policy-statement\s+cl\S+\s+\{.*?\}\s*\}\s+//gs;
      $routemap_count = s/\brm-//gs;
      $prefix_count = s/\bpl-//gs;
      @as_paths_defs = m/as-path\s+(\S+)\s+\"/g;
      @community_defs = m/community\s+(\S+)\s+members/g;
      @prefix_list_defs = m/community\s+(\S+)\s+members/g;

      #remove certain configuration policies and the references


      $/ = "\n";
      @lines = split (/\n/);
      }

      close(COMMUNITY);
      die;
      }



      [Non-text portions of this message have been removed]
    • merlyn@stonehenge.com
      ... Noah open COMMUNITY,
      Message 2 of 2 , Sep 5, 2006
        >>>>> "Noah" == Noah <admin2@...> writes:

        Noah> open COMMUNITY, "<it" || die "Failed to open $old_file: $!";

        Noah> print COMMUNITY "$_";

        Those two don't make sense. If you're opening for input, you can't
        write for output.

        --
        Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
        <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
        Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
        See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
      Your message has been successfully submitted and would be delivered to recipients shortly.