toniax has asked for the wisdom of the Perl Monks concerning the following question:
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
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 ?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);
if ($string =~ m/data/) { do whatever }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: search one instance
by roboticus (Chancellor) on Nov 03, 2010 at 14:58 UTC | |
Re: search one instance
by d5e5 (Beadle) on Nov 03, 2010 at 15:08 UTC | |
Re: search one instance
by eff_i_g (Curate) on Nov 03, 2010 at 15:47 UTC | |
Re: search one instance
by suhailck (Friar) on Nov 03, 2010 at 15:03 UTC | |
by raybies (Chaplain) on Nov 03, 2010 at 16:24 UTC | |
by AnomalousMonk (Archbishop) on Nov 03, 2010 at 19:22 UTC | |
by suhailck (Friar) on Nov 04, 2010 at 01:11 UTC | |
Re: search one instance
by AnomalousMonk (Archbishop) on Nov 03, 2010 at 19:38 UTC | |
Re: search one instance
by d5e5 (Beadle) on Nov 04, 2010 at 20:34 UTC | |
A reply falls below the community's threshold of quality. You may see it by logging in. |
Back to
Seekers of Perl Wisdom