$variable manipulation question

2001-10-02 Thread Shannon Murdoch

Hi all,

I'm trying to get a string (held in a variable) to have all it's characters
spaced apart by a ' ' space.

ie.   $input's content changes from '1234' to '1 2 3 4'

Is there some way to do this?

cheers,
-Shannon


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: $variable manipulation question

2001-10-02 Thread Shannon Murdoch

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

 
 Hi all,
 
 I'm trying to get a string (held in a variable) to have all it's characters
 spaced apart by a ' ' space.
 
 ie.   $input's content changes from '1234' to '1 2 3 4'
 
 Is there some way to do this?
 
 cheers,
 -Shannon
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: $variable manipulation question

2001-10-02 Thread Rajeev Rumale

Thats Great !
Yes this is infact helped me.
I was trying it in a much complicated way.

regards

Rajeev Rumale




- Original Message -
From: Shannon Murdoch [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, October 02, 2001 6:50 PM
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


  Hi all,
 
  I'm trying to get a string (held in a variable) to have all it's
characters
  spaced apart by a ' ' space.
 
  ie.   $input's content changes from '1234' to '1 2 3 4'
 
  Is there some way to do this?
 
  cheers,
  -Shannon
 


 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: $variable manipulation question

2001-10-02 Thread Shannon Murdoch


 $x = join ' ', split //, $x;

That looks like a very compact way of doing it, Brian- is it possible to get
a bit of a rundown of how it works?

cheers,
-Shannon

 From: [EMAIL PROTECTED] (_brian_d_foy)
 Newsgroups: perl.beginners.cgi
 Date: Tue, 02 Oct 2001 06:56:59 -0400
 To: [EMAIL PROTECTED]
 Subject: Re: $variable manipulation question
 
 In article [EMAIL PROTECTED],
 [EMAIL PROTECTED] (Shannon Murdoch) wrote:
 
 I'm trying to get a string (held in a variable) to have all it's characters
 spaced apart by a ' ' space.
 
 ie.   $input's content changes from '1234' to '1 2 3 4'
 
 $x = join ' ', split //, $x;
 -- 
 brian d foy [EMAIL PROTECTED] - Perl services for hire
 CGI Meta FAQ - http://www.perl.org/CGI_MetaFAQ.html
 Troubleshooting CGI scripts - http://www.perl.org/troubleshooting_CGI.html


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: $variable manipulation question

2001-10-02 Thread fliptop

Shannon Murdoch wrote:
 
  $x = join ' ', split //, $x;
 
 That looks like a very compact way of doing it, Brian- is it possible to get
 a bit of a rundown of how it works?

perldoc -f join
perldoc -f split

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: $variable manipulation question

2001-10-02 Thread Roger C Haslock

If you are sure its a string, maybe you can use 'unpack', and then 'join'.

- Roger -

- Original Message -
From: Shannon Murdoch [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, October 02, 2001 11:20 AM
Subject: $variable manipulation question


 Hi all,

 I'm trying to get a string (held in a variable) to have all it's
characters
 spaced apart by a ' ' space.

 ie.   $input's content changes from '1234' to '1 2 3 4'

 Is there some way to do this?

 cheers,
 -Shannon


 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]







-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: $variable manipulation question

2001-10-02 Thread Bob Showalter

 -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]




Re: $variable manipulation question

2001-10-02 Thread Shannon Murdoch

 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]




Re: $variable manipulation question

2001-10-02 Thread _brian_d_foy

In article [EMAIL PROTECTED], 
[EMAIL PROTECTED] (Shannon Murdoch) wrote:

  $x = join ' ', split //, $x;
 
 That looks like a very compact way of doing it, Brian- is it possible to get
 a bit of a rundown of how it works?

start from the right and work your way left. ;)
-- 
brian d foy [EMAIL PROTECTED] - Perl services for hire
CGI Meta FAQ - http://www.perl.org/CGI_MetaFAQ.html
Troubleshooting CGI scripts - http://www.perl.org/troubleshooting_CGI.html

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: $variable manipulation question

2001-10-02 Thread _brian_d_foy

In article [EMAIL PROTECTED], 
[EMAIL PROTECTED] (Shannon Murdoch) wrote:

 Brian's

*ahem* - brian.

 print join ' ', split //, $input;
 
 doesn't actually change $input's content however.

if that is what you wanted then you just need to fill in the
details:

$input = join ' ', split //, $input;
-- 
brian d foy [EMAIL PROTECTED] - Perl services for hire
CGI Meta FAQ - http://www.perl.org/CGI_MetaFAQ.html
Troubleshooting CGI scripts - http://www.perl.org/troubleshooting_CGI.html

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]