M
MJS
The following is what I have and I can't figure out how to do it. I
read faq and I don't get the output what I intent to. I am having
difficulties with proper indentation and white/blank lines.
User has to enter an integer. Depending on that, the pattern should be
repeated the number of times the user specified. Everytime the pattern
is repeated, there should be an increament somewhere in the pattern.
The output is stored in a file.
For example: the exact pattern with the spaces is
"Can someone help
me with
problem number1 => "
This pattern should be replaced by
"This is
solution
number 1, <= "
"This is
solution
number 2, <= "
and so on depending on the user input.
========================================================
use strict;
my $number;
my $pattern;
my $replace;
# data.txt is the file containing the text pattern
open(OUTPUT,"> result.txt") or die("Couldn't open data.txt :$!");
print "Please enter a positive integer for Address = ";
chomp( my $number = <STDIN> );
if ($number =~ tr/1-9// != length ($number)) {
print "You did not enter an interger";
}
else {
$pattern=~/Can someone help
me with
problem number1 =>/;
$replace=~/"This is
solution
number /;
while(<OUTPUT>){
for (my $n=1; $n<=$number; $n++){
s/$pattern/$replace."$n". '<='/gsm;
}
}
}
close(OUTPUT);
======================================
read faq and I don't get the output what I intent to. I am having
difficulties with proper indentation and white/blank lines.
User has to enter an integer. Depending on that, the pattern should be
repeated the number of times the user specified. Everytime the pattern
is repeated, there should be an increament somewhere in the pattern.
The output is stored in a file.
For example: the exact pattern with the spaces is
"Can someone help
me with
problem number1 => "
This pattern should be replaced by
"This is
solution
number 1, <= "
"This is
solution
number 2, <= "
and so on depending on the user input.
========================================================
use strict;
my $number;
my $pattern;
my $replace;
# data.txt is the file containing the text pattern
open(OUTPUT,"> result.txt") or die("Couldn't open data.txt :$!");
print "Please enter a positive integer for Address = ";
chomp( my $number = <STDIN> );
if ($number =~ tr/1-9// != length ($number)) {
print "You did not enter an interger";
}
else {
$pattern=~/Can someone help
me with
problem number1 =>/;
$replace=~/"This is
solution
number /;
while(<OUTPUT>){
for (my $n=1; $n<=$number; $n++){
s/$pattern/$replace."$n". '<='/gsm;
}
}
}
close(OUTPUT);
======================================