split a string

split a string

am 14.04.2008 17:45:21 von dermot

Hi,

I am trying to split a string on every 9th character. I thought that this

my @list = split(/.{9}/, $string);

might do it but it doesn't work.

I thought about using splice but the string is a scalar. If I coudl
force it into an array that would help.

Has anyone got any ideas?
Thanx,
Dp.

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: split a string

am 14.04.2008 18:13:08 von chas.owens

On Apr 14, 2008, at 11:45, Dermot wrote:

> Hi,
>
> I am trying to split a string on every 9th character. I thought that
> this
>
> my @list = split(/.{9}/, $string);
>
> might do it but it doesn't work.
>
> I thought about using splice but the string is a scalar. If I coudl
> force it into an array that would help.
snip

This should do it:

my @nines = /.{9}/g;

Unless you don't want the ninth character, in which case this is what
you want

my @eights = /(.{8})./g;


--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/