in reply to [SOLVED] How to print two different formats to same file without getting an error?

select?
  • Comment on Re: How to print two different formats to same file without getting an error?

Replies are listed 'Best First'.
Re^2: How to print two different formats to same file without getting an error?
by nysus (Parson) on Feb 05, 2014 at 18:45 UTC
    I found the solution. Modified OP with solution.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon";
    $nysus = $PM . $MCF;
    Click here if you love Perl Monks

      I can't test this refactored version of your script because, as toolic pointed out earlier, it's not a complete computer program.

      use strict; use warnings; use autodie qw( open close ); use English qw( -no_match_vars ); my %households; my $household; my $first_name; my $last_name; my $voter_rating; my $support_level; my $phone_number; format Household = @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $household ================================== . format Voter = @<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<< @<< @<<<<<<<<<<<< $last_name, $first_name, $voter_rating, $phone_number . open my $fh, '>encoding(ISO-8859-1)', 'out.txt'; select $fh; for $household (sort keys %households) { local $FORMAT_NAME = 'Household'; write; for my $member (@{ $households{$household} }) { $first_name = $member->{first_name}; $last_name = $member->{last_name}; $voter_rating = $member->{voter_rating}; $support_level = $member->{support_level}; $phone_number = $member->{mobile_number} // $member->{phone_n +umber} // ''; local $FORMAT_NAME = 'Voter'; write; } } close $fh; exit 0;

      Jim

Re^2: How to print two different formats to same file without getting an error?
by nysus (Parson) on Feb 05, 2014 at 17:41 UTC
    I tried select before but either I'm using it wrong or it's not the solution. What I'm confused by is that the file handle is the same as the format.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon";
    $nysus = $PM . $MCF;
    Click here if you love Perl Monks