On 11-09-06 08:04 AM, Emeka wrote:
Hello All,

Could someone explain what Perl does behind here?

Assign to Substring..
substr($string, 0 , 5) = 'Greetings';


Regards,
Emeka

It replaces the first 5 characters in $string with 'Greetings'.

#!/usr/bin/env perl

use strict;
use warnings;

my $string = 'Hello, world';
print "$string\n";

substr($string, 0 , 5) = 'Greetings';
print "$string\n";

__END__



Can also be written as:

#!/usr/bin/env perl

use strict;
use warnings;

my $string = 'Hello, world';
print "$string\n";

substr($string, 0 , 5, 'Greetings' );
print "$string\n";

__END__



--
Just my 0.00000002 million dollars worth,
  Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software:  Fail early & often.

Eliminate software piracy:  use only FLOSS.

"Make something worthwhile."  -- Dear Hunter

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to