Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Cannot find the error

by choroba (Archbishop)
on Apr 03, 2020 at 12:58 UTC ( #11114990=note: print w/replies, xml ) Need Help??


in reply to Cannot find the error

The check for a new section start is in the
$row =~ /^[t]/
condition (the regex is equivalent to /^t/, BTW). It's located inside the YES-branch of the
if ($newsection <= 0)
but the end of the previous section sets $newsection to 1, so this condition can't be reached.

I'd move the /^t/ condition into the ELSE part of the outermost if, and initialize $newsection with 1 at the very start.

Also, I miss strict and warnings.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: Cannot find the error
by gudmo (Novice) on Apr 03, 2020 at 14:01 UTC
    It's just a cut down version of the real script, that's why there are no strict or warnings. But anyhow. The ELSE part of the outermost is only to review the section saved and if the value is found in the section then do the output. The script is supposed to look at each line, starting with t and until it reaches T and save all that into @section. When it finds T it goes to the start with $newsection = 1 and then goes to ELSE to check if the section should be saved. It then clears the @section array and goes to the start of the loop. But why it only checks the ^t at start I don't known, and it doesn't seem to matter if I put it second as an elsif. I am convinced now that everytime the section is reset and the loop starts to write into the array the first iteration is lost.
      > everytime the section is reset and the loop starts to write into the array the first iteration is lost

      It's not lost, it's missed by your script. Every iteration of the loop reads one line from the array. Even the execution of the outermost "else" part processes one line - and it's supposed to be the /^t/ line. That's why I suggested to move the check there.

      Another option would be to add a

      redo
      as the last command in the outermost else, to restart the loop without reading a line.

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
        I fixed it with, for some reason it went to this section after matching t the second time and cleared the array.
        } $backin = shift(@section); undef(@section); push(@section,$backin); } } close ($fh); exit;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11114990]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2020-06-01 17:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (6 votes). Check out past polls.

    Notices?