Re: converting scalar to an array of elements

From: James Willmore (jwillmore_at_remove.adelphia.net)
Date: 02/07/04


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" 


Relevant Pages

  • Re: Everything tastes of SALT!!!!hope this helps u
    ... Can anyone explain why everything I eat and drink tastes of salt even ... I have asked my doctor and pharmacist but neither seems to ... salt you can taste the slightest hint of salt in any food. ... The chemical composition of saliva may change in response to hydration. ...
    (sci.med)
  • Re: l-arginine and blood pressure
    ... >> And David's advice on sodium intake was also spot on. ... >> processed or packaged foods, salad dressings, boxed meal preparations. ... as low-sodium foods taste like shit. ... When I first made myself quit salt "cold turkey", ...
    (misc.fitness.weights)
  • Re: Is There a Good Tasting Salt Substitute?
    ... > Is there a good tasting salt substitute that doesn't raise BP? ... no. Taste is a matter of taste though and not ... Bay leaf, marjoram, nutmeg, onion, pepper, sage, thyme ...
    (sci.med.cardiology)
  • Re: Change One Thing
    ... >> stimulates ALL of the different kinds of taste buds in your mouth. ... >all over our tongue, although there may be increased sensitivity to ... >it lingered more on the salt regions of the tongue, ... nations and civilizations. ...
    (rec.arts.sf.written)
  • Re: Avoiding leg cramps
    ... Marketting to America was an afterthought. ... Not a great taste, but it it isn't barf time. ... Think of ocean water being your source of fluid. ... be it salt, sweet or specific flavors tend to get repulsive over time. ...
    (rec.running)