Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

kcott's version works as you expect. Your modified version (writing lines in a loop to another file) does work here, though output is not what you want.

Run first as perl program.pl -BUG_MODE=0 (kcott's version); then as perl program.pl -BUG_MODE=1 (your version) ...

#!/usr/local/bin/perl -s use warnings; use strict; our $BUG_MODE; printf "** Running in bug mode: %s **\n\n" , map uc( $_ ) , $BUG_MODE +? 'yes' : 'no'; my $re = qr{ \A \s+ ( \d+ ) }x; my $high = 0; my @lines; my $filtered; my $in_fh = \*DATA or die qq[Cannot open DATA: $!]; open (my $out_fh, '>' , \$filtered ) or die qq[Cannot open \$filtered +to write: $!]; while (<$in_fh>) { /$re/ or next; my $num = $1; next if $num < $high; if ( $num > $high ) { $high = $num; @lines = (); } push @lines , $_; $BUG_MODE and print $out_fh @lines; } close ($in_fh); print "Highest number: $high\n"; $BUG_MODE or print $out_fh @lines; close ($out_fh); printf "Filtered output ...\n%s\n" , $filtered ; __DATA__ High fanout nets in the post compile netlist: Fanout Type Name -------------------------- 2 INT_NET Net : c_c Driver: c_pad 2 INT_NET Net : b_c Driver: b_pad 2 INT_NET Net : a_c Driver: a_pad 1 INT_NET Net : sum_c Driver: sum_1_SUM0_0 1 INT_NET Net : N_5 Driver: sum_1_CO0_i
# Output. perl x.pl -BUG_MODE=0 ; perl x.pl -BUG_MODE=1 ; ** Running in bug mode: NO ** Highest number: 2 Filtered output ... 2 INT_NET Net : c_c 2 INT_NET Net : b_c 2 INT_NET Net : a_c ** Running in bug mode: YES ** Highest number: 2 Filtered output ... 2 INT_NET Net : c_c 2 INT_NET Net : c_c 2 INT_NET Net : b_c 2 INT_NET Net : c_c 2 INT_NET Net : b_c 2 INT_NET Net : a_c

In reply to Re^5: Find maximum number in text file and copying its full statement in new text file? by parv
in thread Find maximum number in text file and copying its full statement in new text file? by sumathigokul

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (6)
    As of 2021-01-22 22:46 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Notices?