Newbie question

M

MM

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
 
G

Gunnar Hjalmarsson

MM said:
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.
 
J

Jürgen Exner

MM said:
} 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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top