Re: inserting dot



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."

.



Relevant Pages

  • Re: inserting dot
    ... > 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 ...
    (comp.lang.perl.misc)
  • Re: Script error in OE6 html email
    ... That makes sense in that it only happens in replies and not new ... It could be that one of those is including the script as a means to ... When it arrives in her inbox, the line of code has been added. ... ::: As well any original emails are from the default account. ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • [HPADM] SUMMARY: Parse file using awk
    ... I received three replies and I ended up using Brett Geer's Script. ... like to add the size and no of files column to get a grand total. ... I am looking for a simple awk snippet. ...
    (HP-UX-Admin)
  • Re: Can I modify the date headers in received messages?
    ... sent (replies) in the same folder, and want those replies to be listed ... The script worked great as an application but for some reason I ... > set currentMessages to the current messages ... > repeat with theMsg in the currentMessages ...
    (microsoft.public.mac.office.entourage)
  • Re: Domain logon script runs minimised
    ... PLEASE post all messages and replies in the newsgroups ... > Windows 2000 Professional workstations. ... > netlogon script from that server's netlogon share. ...
    (microsoft.public.win2000.networking)