Re: converting scalar to an array of elements
From: James Willmore (jwillmore_at_remove.adelphia.net)
Date: 02/07/04
- Next message: Jürgen Exner: "Re: How to execute a command line in Perlscript"
- Previous message: AlV: "Re: converting scalar to an array of elements"
- In reply to: Chuckb: "converting scalar to an array of elements"
- Next in thread: John W. Krahn: "Re: converting scalar to an array of elements"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 07 Feb 2004 09:02:16 -0500
On Sat, 07 Feb 2004 13:17:33 +0000, 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";
Use 'split' :-)
This is a simple one liner to produce what you wanted ...
prompt> perl -e '$name="Fred";@chars=split //, $name;print join("\n",
@chars),"\n";'
F
r
e
d
prompt>
Salt to taste :-)
HTH
-- Jim Copyright notice: all code written by the author in this post is released under the GPL. http://www.gnu.org/licenses/gpl.txt for more information. a fortune quote ... Monday, n.: In Christian countries, the day after the baseball game. -- Ambrose Bierce, "The Devil's Dictionary"
- Next message: Jürgen Exner: "Re: How to execute a command line in Perlscript"
- Previous message: AlV: "Re: converting scalar to an array of elements"
- In reply to: Chuckb: "converting scalar to an array of elements"
- Next in thread: John W. Krahn: "Re: converting scalar to an array of elements"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|