I preface this by noting that I know very little about formats, so what follows could be completely wrong.

AFAICT, the question you ask about should be the least of your worries. The code you posted doesn't even compile. (It looks like one big cut-and-paste charlie foxtrot.) It has numerous other problems, IMO, but I'll confine myself to your question.

I've edited your code minimally to do what I think you want it to do (i.e. I've retained stuff in the original, such as the abuse of @_, that I'd never do in my own code). Even if I didn't get it right, it should give you some idea of what you should do. The code is untested.

sub showAvman(){ $dbh = DBI->connect ("dbi:Pg:dbname=NPMS"); $res=$dbh->prepare("select \"name\", \"address\", \"type\", \"pollint\", \"protocol\" from \"avman\" order by \"name\""); $res->execute; format AVMAN_TOP = Name IP Address Type Pollint Pr +otocol . format AVMAN = @<<<<<<<<<<<<<<<< @<<<<<<<<<<<< @<<<<<<<<<<<< @<<<<<<<<<<<< @ +<<<<<<<<<<<< $row->{name}, $row->{address},$row->{type} ,$row->{pollint},$r +ow->{protocol} . { my $old_handle = select STDOUT; $^ = 'AVMAN_TOP'; $~ = 'AVMAN'; select $old_handle; } while ($row=$res->fetchrow_hashref()) { if ($row->{type} eq "SNMP") { @_=split(/:/,$row->{protocol}); $row->{protocol} = "Interface $_[1]"; } write STDOUT; } $res->finish; $dbh->disconnect; } sub showEvents(){ $var=NPMS::getGlobals(); $maxEvent=$var->{maxevent}; $dbh = DBI->connect ("dbi:Pg:dbname=NPMS"); $res=$dbh->prepare("select t.\"status\", to_char(l.\"time\",\'Dy DD Mon YYYY HH12:MI am\') as t +ime, l.\"extra_text\", t.\"desc\", l.\"userid\", l.\"device\", l.\"number\" from \"events\" t, \"event_log\" l where t.\"id\" = l.\"id\" and l.\"ack\" = \'0\' order by \"number\" DESC limit $maxEvent"); if (!defined $res) { die "Cannot prepare statement\n"; } $res->execute; format EVENTS_TOP = STATUS USERID TIME DEVICE DESC . format EVENTS = @<<<<<<<<<<<< @<<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<< +<<<<< $row->{status},$row->{userid},$row->{device},$row->{desc} . { my $old_handle = select STDOUT; $^ = 'EVENTS_TOP'; $~ = 'EVENTS'; select $old_handle; } while ($row=$res->fetchrow_hashref()) { write STDOUT; } $res->finish; $dbh->disconnect; }

the lowliest monk


In reply to Re: formatting STDOUT more than once by tlm
in thread formatting STDOUT more than once by bahadur

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.