Newbie question

Discussion in 'Perl Misc' started by MM, Feb 14, 2008.

  1. MM

    MM Guest

    Hi all,

    I am trying to write a perl script to do some simple modifications to a text
    file. Amongst other things it has to delete a few lines. Here is a relevant
    part of my script:

    LINE: while ($line = <OF>) {
    if ((/END_ADDRESS_SPACE/) && ($count2 < 3)) {
    $count2 += 1;
    $line = <OF>;
    do {
    $line = <OF>;
    } until ($line == /ADDRESS_SPACE/);
    next LINE;
    }
    print NF $line;
    }

    The lines that I am trying to skip contain forward slashes and that seems to
    confuse the match in the until statement...

    END_ADDRESS_SPACE;

    ///////////////////////////////////////////////////////////////////////////////
    //
    // Processor 'ppc405_0' address space
    'plb_bram_if_cntlr_1_bram_combined' 0xFFFE8000:0xFFFEFFFF (32 KB).
    //
    ///////////////////////////////////////////////////////////////////////////////

    ADDRESS_SPACE plb_bram_if_cntlr_1_bram_combined RAMB16
    [0xFFFE8000:0xFFFEFFFF]



    Thanks,
    /Mikhail
    MM, Feb 14, 2008
    #1
    1. Advertising

  2. MM wrote:
    > I am trying to write a perl script to do some simple modifications to a text
    > file. Amongst other things it has to delete a few lines. Here is a relevant
    > part of my script:
    >
    > LINE: while ($line = <OF>) {
    > if ((/END_ADDRESS_SPACE/) && ($count2 < 3)) {


    if (($line =~ /END_ADDRESS_SPACE/) && ($count2 < 3)) {
    ---------^^^^^^^^

    > $count2 += 1;
    > $line = <OF>;
    > do {
    > $line = <OF>;
    > } until ($line == /ADDRESS_SPACE/);


    } until ($line =~ /ADDRESS_SPACE/);
    --------------------^

    > next LINE;
    > }
    > print NF $line;
    > }
    >
    > The lines that I am trying to skip contain forward slashes and that seems to
    > confuse the match in the until statement...


    What makes you think that would have anything to do with it?

    You should enable strictures and warnings, which will help you detect
    many types of errors.

    use strict;
    use warnings;

    I marked a couple of obvious things above.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Feb 14, 2008
    #2
    1. Advertising

  3. MM

    MM Guest

    "Gunnar Hjalmarsson" <> wrote in message
    news:...
    >
    > I marked a couple of obvious things above.


    Thanks a lot. It works as expected now.

    /Mikhail
    MM, Feb 14, 2008
    #3
  4. "MM" <> wrote:
    > } until ($line == /ADDRESS_SPACE/);


    Are you absolutely certain that you want to compare the numerical(!) value
    of $line with the logical return value of the pattern match against $_ ?
    That seems wrong to me.

    jue
    Jürgen Exner, Feb 14, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jerry C.
    Replies:
    8
    Views:
    206
    Uri Guttman
    Nov 23, 2003
  2. Kruno Saho
    Replies:
    0
    Views:
    125
    Kruno Saho
    Apr 7, 2013
  3. Dave Angel
    Replies:
    0
    Views:
    109
    Dave Angel
    Apr 7, 2013
  4. rusi
    Replies:
    0
    Views:
    99
  5. Miki Tebeka
    Replies:
    0
    Views:
    74
    Miki Tebeka
    Apr 7, 2013
Loading...

Share This Page