Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Regex Confusion

by ysth (Canon)
on Feb 10, 2010 at 14:45 UTC ( #822433=note: print w/ replies, xml ) Need Help??


in reply to Regex Confusion

You shouldn't add or remove elements from an array you are looping over with foreach. Fortunately, you aren't actually using the loop variable $_; even so, you will be accidentally skipping over the element after one you've spliced away, since it will move into the $count position just as you move on to look at $count+1.

Instead, do:

for my $count ( reverse 0..$#content ) { # do stuff with $content[$count], including splicing it out of exis +tence }
--
A math joke: r = | |csc(θ)|+|sec(θ)|-||csc(θ)|-|sec(θ)|| |
Online Fortune Cookie Search
Office Space merchandise


Comment on Re: Regex Confusion
Download Code
Replies are listed 'Best First'.
Re^2: Regex Confusion
by Kelly22 (Novice) on Feb 10, 2010 at 15:18 UTC
    That makes a lot of sense, and explains my confusion concerning why it seemed to work sometimes. Thank you. And thank you to everyone for your rapid responses.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (19)
As of 2015-07-29 16:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (265 votes), past polls