Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   string and time question (http://www.velocityreviews.com/forums/t899484-string-and-time-question.html)

a 08-15-2006 06:16 AM

string and time question
 
Hi,
Have two questions.
1> Let say,
my $str = "abcd";
How can I do the following,
$str = $str + 1 make $str becomes "abce"?

2> Is it possible to do the following?
for(k=1;k<9;k++){
do something
wait for 10second
}

Thanks



Simon Taylor 08-15-2006 06:27 AM

Re: string and time question
 
a wrote:
> Hi,
> Have two questions.
> 1> Let say,
> my $str = "abcd";
> How can I do the following,
> $str = $str + 1 make $str becomes "abce"?


The auto-increment operator ++ will do this for you.

See the "Auto-increment and Auto-decrement" section in perldoc perlop
or online at:


http://perldoc.perl.org/perlop.html#...o-decrement---

- Simon Taylor
--
http://www.perlmeme.org

Simon Taylor 08-15-2006 06:34 AM

Re: string and time question
 
Hello again 'a'

> 2> Is it possible to do the following?
> for(k=1;k<9;k++){
> do something
> wait for 10second
> }



Try

perldoc -f sleep

ie:

for (my $k=1;$k<9;$k++){
print 'doing something' . "\n";
sleep 10;
}

or using the '..' range operator:

for (1..8) {
print 'doing something' . "\n";
sleep 10;
}


- Simon Taylor
--
http://www.perlmeme.org

Jürgen Exner 08-15-2006 02:09 PM

Re: string and time question
 
a wrote:
> 1> Let say,
> my $str = "abcd";
> How can I do the following,
> $str = $str + 1 make $str becomes "abce"?


Auto-increment works on strings jsut fine:

$str++

> 2> Is it possible to do the following?
> for(k=1;k<9;k++){
> do something
> wait for 10second
> }


Sure:

for my $k (1..9){
do something;
sleep 10;
}

jue



anno4000@radom.zrz.tu-berlin.de 08-16-2006 01:31 PM

Re: string and time question
 
Jürgen Exner <jurgenex@hotmail.com> wrote in comp.lang.perl.misc:

> Auto-increment works on strings jsut fine:

^^^^ <-----+
|
|
Hey! ----------------------------+

Anno


All times are GMT. The time now is 11:22 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.