> How did that help you? Now you have an array of individual
> characters, gotten the hard way.
Originally I was aiming to space each character apart so I could use a space
' ' as the delimiting character when I brought them into an array (to be
analyzed character by character by other following routines).
ie. $input = '12345' -> $input = '1 2 3 4 5'
so I could use:
@chars = split(/ /,$input);
to get the individual characters into their own array items.
Your:
@chars = split //, $input;
Does this all in one bang which is great! Thanks!
Brian's
print join ' ', split //, $input;
doesn't actually change $input's content however.
> From: [EMAIL PROTECTED] (Bob Showalter)
> Newsgroups: perl.beginners.cgi
> Date: Tue, 2 Oct 2001 09:06:01 -0400
> To: "'[EMAIL PROTECTED]'" <[EMAIL PROTECTED]>
> Subject: RE: $variable manipulation question
>
>> -----Original Message-----
>> From: Shannon Murdoch [mailto:[EMAIL PROTECTED]]
>> Sent: Tuesday, October 02, 2001 6:51 AM
>> To: [EMAIL PROTECTED]
>> Subject: Re: $variable manipulation question
>>
>>
>> I found a solution not long after using a loop of sorts. (and
>> killed two
>> birds with one stone, as my next step was to put each item
>> (space delimited)
>> into an array).
>> I made a loop saying, 'as long as $input still has characters
>> in it, put
>> each one (one at a time) into the @front_chars array, then
>> reverse the list
>> order so it's normal again.'
>>
>> $input = "1234";
>>
>> while($input ne undef){
>> push(@front_chars,chop($input));
>> }
>> @front_chars = reverse @front_chars;
>>
>> Not sure if this is helpful to anyone, but it helped me....
>
> How did that help you? Now you have an array of individual
> characters, gotten the hard way. Using split() is the way
> to do this (see perldoc -f split):
>
> @chars = split //, $input;
>
> To print this list out with spaces between, you can:
>
> $" = ' '; # this is the default
> print "@chars"; # double quotes required here
>
> or
>
> print join ' ', @chars;
>
> The split and join can be combined to elminate the intermediate
> array:
>
> print join ' ', split //, $input;
>
> Which was brian's solution.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]