C
Chris Marshall
Hi
I am trying to use something like the script below (perl 5.6.0) to
iterate through the data at the bottom of the script several times (and
put an incremented parameter in there). However it does not seem
possible to seek back to the start of DATA. Can this be done in this
way or would I be better off using a here doc for the data and
iterating over the string many times ?
thanks,
Christian
cat ./test.pl
#!/usr/bin/perl
use warnings;
use strict;
for my $num (1..5){
while(<DATA>){
s/XX_NUM_XX/$num/;
print;
}
seek DATA, 0, 1;
print "seek $num\n"; #debug
}
__DATA__
hello XX_NUM_XX
world XX_NUM_XX
output:
../test.pl
hello 1
world 1
seek 1
seek 2
seek 3
seek 4
seek 5
I am trying to use something like the script below (perl 5.6.0) to
iterate through the data at the bottom of the script several times (and
put an incremented parameter in there). However it does not seem
possible to seek back to the start of DATA. Can this be done in this
way or would I be better off using a here doc for the data and
iterating over the string many times ?
thanks,
Christian
cat ./test.pl
#!/usr/bin/perl
use warnings;
use strict;
for my $num (1..5){
while(<DATA>){
s/XX_NUM_XX/$num/;
print;
}
seek DATA, 0, 1;
print "seek $num\n"; #debug
}
__DATA__
hello XX_NUM_XX
world XX_NUM_XX
output:
../test.pl
hello 1
world 1
seek 1
seek 2
seek 3
seek 4
seek 5