Hello again everyone,
Sorry about being so cryptic but I will put my question in code.
I found a way to do what I want but it seems so cumbersome.
I am sure a better way exist. well here is the code
open(XFIL,"var.txt") || die $!;
@main = <XFIL>;
close(XFIL);
open(XFIL,">var.txt") || die $!;
foreach $line (@main) {
$line =~ s/\n/replace/g;
print XFIL $line;
}
close(XFIL);
open(XFIL,"var.txt") || die $!;
@main = <XFIL>;
close(XFIL);
open(XFIL,">var.txt") || die $!;
foreach $line (@main) {
$line =~ s/the line to be replaced/this is the new line/;
$line =~ s/replace/\n/g;
print XFIL $line;
}
close(XFIL);
Hello ,
I have a quick question . Lets say the word data is in
the $string 20 times. I want to only match the first instance
of the word data . How would I do this ?
if ($string =~ m/data/) {
do whatever
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|