Re: converting scalar to an array of elements
From: John W. Krahn (krahnj_at_acm.org)
Date: 02/08/04
- Next message: Gunnar Hjalmarsson: "Re: Novice - help with pattern matching needed"
- Previous message: Uri Guttman: "Re: Reference overloading helps inheritance"
- In reply to: Chuckb: "converting scalar to an array of elements"
- Next in thread: David H. Adler: "Re: converting scalar to an array of elements"
- Reply: David H. Adler: "Re: converting scalar to an array of elements"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 07 Feb 2004 23:54:20 GMT
Chuckb wrote:
>
> I should know this but, what is the quickest way to convert a scalar value
> into an array?
> Ex: $name="Fred";
> so that
> $arrayname[0]="F";
> $arrayname[1]="r";
> $arrayname[2]="e";
> $arrayname[3]="d";
I don't know which is the quickest, you'll have to use Benchmark for that.
my @arrayname = split //, $name;
my @arrayname = $name =~ /./sg;
my @arrayname = unpack 'a' x length $name, $name;
my @arrayname = map substr( $name, $_, 1 ), 0 .. length( $name ) - 1;
TMTOWTDI :-)
John
-- use Perl; program fulfillment
- Next message: Gunnar Hjalmarsson: "Re: Novice - help with pattern matching needed"
- Previous message: Uri Guttman: "Re: Reference overloading helps inheritance"
- In reply to: Chuckb: "converting scalar to an array of elements"
- Next in thread: David H. Adler: "Re: converting scalar to an array of elements"
- Reply: David H. Adler: "Re: converting scalar to an array of elements"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|