foreach problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Cal Lidderdale

    foreach problem

    My datafile is:

    abc 234
    def 888
    keyword1
    ------- -------
    1234 202 want it
    2345 305 want it
    34567 7732 want it
    secondkeyword
    more lines

    I do: (somewhat psydo-code)

    $data = file ("mydatafile ");
    foreach ($data as $line) {
    if ( secondkeyword ) $on = 0;
    if ( $on == 1 ) {
    grab numbers in case statment;
    }
    if ( strstr ($line, "keyword1") ) $on = 1; loose keyword1 line
    }

    My question is: is there a way to do $data++; when
    the first keyword is seen to skip the "----- ------"
    line? Or do I have to brute force code around it?
    In AWK I would just put "getline" with the $on = 1
    entry.

    Tks
    Chuck


  • Cal Lidderdale

    #2
    Re: foreach problem

    Cal Lidderdale wrote:[color=blue]
    > My datafile is:
    >
    > abc 234
    > def 888
    > keyword1
    > ------- -------
    > 1234 202 want it
    > 2345 305 want it
    > 34567 7732 want it
    > secondkeyword
    > more lines
    >
    > I do: (somewhat psydo-code)
    >
    > $data = file ("mydatafile ");
    > foreach ($data as $line) {
    > if ( secondkeyword ) $on = 0;
    > if ( $on == 1 ) {
    > grab numbers in case statment;
    > }
    > if ( strstr ($line, "keyword1") ) $on = 1; loose keyword1 line
    > }
    >
    > My question is: is there a way to do $data++; when
    > the first keyword is seen to skip the "----- ------"
    > line? Or do I have to brute force code around it?
    > In AWK I would just put "getline" with the $on = 1
    > entry.
    >
    > Tks
    > Chuck
    >
    >[/color]
    Forgot to put this in:
    foreach ($data as $key => $line)
    is there a way to modify $key?

    Comment

    Working...