$ab = "asljdhashdklasjkl ;dajs;ld";
I want the first 10 characters from $ab
.
Can the splice
function be used?
$ab = "asljdhashdklasjkl ;dajs;ld";
I want the first 10 characters from $ab
.
Can the splice
function be used?
#! /usr/bin/perl
use strict;
my $info = "asljdhashdklasjkl ;dajs;ld";
my @personal = split(//, $info);
print @personal[0..9];
C:\Documents and Settings\Administrator>perl perltest.pl
asljdhashd
C:\Documents and Settings\Administrator>
C:\Documents and Settings\Administrator>type perltest.pl
#! /usr/bin/perl
use strict;
my $info = "asljdhashdklasjkl ;dajs;ld";
my @personal = split(//, $info);
print @personal[0..9];
C:\Documents and Settings\Administrator>
Substr works great for your example. Splice operates on an array, so you would need to round trip it:
#!/usr/bin/perl
my ($ab, @ab, @first_ten, $first_ten);
$ab = "asljdhashdklasjkl ;dajs;ld";
@ab = split(//, $ab);
@first_ten = splice(@ab, 0, 10);
$first_ten = join('', @first_ten);