in reply to Re: how to capture the max value of the array
in thread how to capture the max value of the array

hi Hauke

sorry on the mismatch. it was a typo on the input source. can you show me please the full code in using the while(<>){...} ? i only pasted a part of the code that lists down operation between the PIN vcc until END vcc.

input source
PIN vcc aaaa bbbb Port LAYER m2 ; END CCC DDD Port LAYER m1 ; END EEE FFF Port LAYER m0 ; END END vcc
my code :
if (/PIN vcc/../END vcc/) { if(/LAYER\s+m(\S+)/) { push(@num, $1); print "@num" ; }

Replies are listed 'Best First'.
Re^3: how to capture the max value of the array
by AnomalousMonk (Archbishop) on May 20, 2016 at 05:46 UTC
    if (/PIN vcc/../END vcc/) {
               if(/LAYER\s+m(\S+)/) {
                 push(@num, $1);
                 print "@num" ;

    Only some schematic suggestions. Basically, follow the advice given above by haukex:

    • Get rid of the  print "@num" ; statement in the if-blocks within your while-loop and replace it with a
          pp \@num;
      statement if you want to see the array grow while the file is being processed.
    • After the while-loop terminates, another  pp \@num; statement can show the final state of the array. Then, get the maximum value with some statement like
          my $max_LAYER_m_number = max @num;
      and you're off to the races.
    If you're still having problems, please show us some brief and complete working code and associated input data and tell us how the output produced falls short of what you need.


    Give a man a fish:  <%-{-{-{-<