Re: inserting dot
- From: "Dr.Ruud" <rvtol+news@xxxxxxxxxxxx>
- Date: Wed, 12 Oct 2005 16:11:13 +0200
cooldaddy schreef:
> thanks for your replies, I looked into the substr thingy, and made
> this little script.. but i'm getting this strange error message:
> useless use of addition (+) in void context at test.pl line 7, and
> then it hangs... how come ?
>
> #!/usr/bin/perl -w
> use CGI;
> print "Content-type: text/html\n\n";
> $tekst="abcdefghijklmnopqrstuvwxyz";
>
> for ($count=1; $count<=length($tekst); $count+3){
> substr($tekst,$count,0)=".";
> }
> print $tekst;
Not a bad attempt.
1. You obviously didn't read (or remember) the posting guidelines:
always code 'use strict;'.
2. Some lines in your code are not needed for your test and some are
missing, as Paul Lalli already said.
3. You are inserting at every 2nd position (so not at every 10th as you
first said) but start too soon, maybe because you don't know that the
index starts at 0, see also your '<='.
4. You didn't indent nor space your code properly.
Some suggestions:
#!/usr/bin/perl
use strict;
use warnings;
my $tekst = "abcdefghijklmnopqrstuvwxyz";
my $step = 5;
for (my $count = $step; $count < length($tekst); ($count += $step)++)
{
substr($tekst, $count, 0) = ".";
}
print $step, ':', $tekst, "\n";
Variant (that changes $step):
for (my $count = $step++; $count < length($tekst); $count += $step) {
--
Affijn, Ruud <http://www.pandora.com/?sc=sh770781&cmd=tunermini>
"Gewoon is een tijger."
.
- References:
- inserting dot
- From: cooldaddy
- Re: inserting dot
- From: Josef Moellers
- Re: inserting dot
- From: cooldaddy
- Re: inserting dot
- From: Josef Moellers
- inserting dot
- Prev by Date: Re: inserting dot
- Next by Date: [OT] teddy bears (was: Re: Sorting a nested array (table) (alphabetically))
- Previous by thread: Re: inserting dot
- Next by thread: Re: inserting dot
- Index(es):
Relevant Pages
|