Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: Perl code to format the text file by inserting tag in blank line

by Marshall (Canon)
on Feb 13, 2020 at 02:01 UTC ( [id://11112907]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl code to format the text file by inserting tag in blank line
in thread Perl code to format the text file by inserting tag in blank line

I think the OP is probably ok here.
He is using arrays in a "non-Perl" way and with explicit indices starting at 1 instead of 0. Not using array[0] is allowed. $kpi[0] is probably undef.

"Off by one" is one of the most common errors in programming. I personally would rewrite the code so that it doesn't use indices at all like: foreach my $element (@array){} However a re-write like appears to be outside the scope of the question before us. Perl code like that would use index 0. However there would not be any direct reference to that zero index within the code at all. Creating the kpi array would use "push" instead of explicit indices from 1..n. If the OP creates the kpi array with starting with $kpi[1] that just makes index 0 undef (skips it). I don't see any indication that the OP is aware of: push,pop,shift,unshift.

Replies are listed 'Best First'.
Re^3: Perl code to format the text file by inserting tag in blank line
by AnomalousMonk (Archbishop) on Feb 13, 2020 at 06:00 UTC
    I think the OP is probably ok here.

    I'm not so sure. DAN0207 is a self-described Perl "beginner", and looking at other posts by this monk doesn't give me the sense that he or she is necessarily aware of the issue of 0- versus 1-based arrays. We also cannot see anything about how the  @kpi array is initialized. The whole thing made my buggy-sense tingle.

    However, DAN0207 hasn't seen the need to follow up on the point I made here (indeed, replying with a question on a completely different topic), so I guess everything's ok...


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

      Well to completely digest the collective advice given so far would take days, not hours for a beginner. At this point, I figure the OP has learned some bits of what was presented, but not everything presented. If the OP has no further questions at this time, I'm ok with that.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-24 23:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found