RE: Split based on length

2003-09-22 Thread NYIMI Jose (BMB)
. -Original Message- From: zsdc [mailto:[EMAIL PROTECTED] Sent: Saturday, September 20, 2003 10:06 AM To: NYIMI Jose (BMB) Cc: [EMAIL PROTECTED] Subject: Re: Split based on length NYIMI Jose (BMB) wrote: I have an other request : code review :-) Below is my final code. I'm sure that you

RE: Split based on length

2003-09-19 Thread NYIMI Jose (BMB)
] Subject: RE: Split based on length On Sep 18, Bob Showalter said: Stephen Hardisty wrote: for(split(/(..)/, $string)) { print *$_ if $_; } Gorgeous :o) @parts = grep length, split /(..)/, $string; WHY are we using split() for this? Why are we using a method that returns a list twice

RE: Split based on length

2003-09-19 Thread NYIMI Jose (BMB)
please ? Thanks, José. -Original Message- From: Rob Dixon [mailto:[EMAIL PROTECTED] Sent: Friday, September 19, 2003 4:47 PM To: [EMAIL PROTECTED] Subject: Re: Split based on length Nyimi Jose wrote: IMHO $string =~ /.{1,$len}/g; Is the best suggestion i have seen so far ;) I have

Re: Split based on length

2003-09-19 Thread Rob Dixon
Nyimi Jose wrote: I need some explanation on following: 1. my skill of perl tells me so far to handle exceptions and write : open(FH,$file) || die can not open $file : $! \n; I've tried your code with a wrong file_name and got following message: Can't open in.txt1: No such file or directory

RE: Split based on length

2003-09-18 Thread Bob Showalter
NYIMI Jose (BMB) wrote: ... I was thinking about unpack function but how to make it dynamic ? I mean writing : my @items = unpack('A2 A2', $str); Will work for $str='abdc'; Not for $str='abcdef'; How about something like: my $s = 'abcdefghij'; my @x; ([EMAIL PROTECTED],$s) =

RE: Split based on length

2003-09-18 Thread Bob Showalter
Stephen Hardisty wrote: for(split(/(..)/, $string)) { print *$_ if $_; } Gorgeous :o) or, @parts = grep length, split /(..)/, $string; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

RE: Split based on length

2003-09-18 Thread Jeff 'japhy' Pinyan
On Sep 18, Bob Showalter said: Stephen Hardisty wrote: for(split(/(..)/, $string)) { print *$_ if $_; } Gorgeous :o) @parts = grep length, split /(..)/, $string; WHY are we using split() for this? Why are we using a method that returns a list twice the size that we want, that we then have

Split based on length

2003-09-17 Thread NYIMI Jose (BMB)
Hello, I have a string which i know, it is a concatenation of fixed length of substring. I would like to split it based on this known length and get as result An array containing each substring. Let say the known length is 2. If the string is 'abcd', my array should be ('ab', 'dc') And if my

RE: Split based on length

2003-09-17 Thread Stephen Hardisty
Hi, you can use split for this sort of thing. For example: my $string = hello there; # add an extra '.' for every character you want my @pairs = split(/(..)/, $string); The only thing you want to be careful about is empty quotes/nothing (e.g. ''). For example, if we wanted to print the

RE: Split based on length

2003-09-17 Thread Charles K. Clarkson
NYIMI Jose (BMB) [EMAIL PROTECTED] wrote: : : I mean writing : : my @items = unpack('A2 A2', $str); : Will work for $str='abdc'; : Not for $str='abcdef'; : : Any ideas ? use POSIX 'ceil'; my $size = 4; my @items = unpack A$size x ceil( (length $string) / $size ), $string; OR: use

Re: Split based on length

2003-09-17 Thread Jeff 'japhy' Pinyan
On Sep 17, NYIMI Jose (BMB) said: Let say the known length is 2. If the string is 'abcd', my array should be ('ab', 'dc') And if my string is 'abcdef', my array should be ('ab', 'dc', 'ef'). I'd just use: @groups = $string =~ /../g; # use ... for three, or .{3}, etc. You don't need

Re: Split based on length

2003-09-17 Thread Rob Dixon
Nyimi Jose wrote: I have a string which i know, it is a concatenation of fixed length of substring. I would like to split it based on this known length and get as result An array containing each substring. Let say the known length is 2. If the string is 'abcd', my array should be ('ab',

RE: Split based on length

2003-09-17 Thread NYIMI Jose (BMB)
, 2003 5:28 PM To: [EMAIL PROTECTED] Subject: Re: Split based on length Nyimi Jose wrote: I have a string which i know, it is a concatenation of fixed length of substring. I would like to split it based on this known length and get as result An array containing each substring. Let say

Re: Split based on length

2003-09-17 Thread Jeff 'japhy' Pinyan
On Sep 17, Jeff 'japhy' Pinyan said: On Sep 17, NYIMI Jose (BMB) said: Let say the known length is 2. If the string is 'abcd', my array should be ('ab', 'dc') And if my string is 'abcdef', my array should be ('ab', 'dc', 'ef'). I'd just use: @groups = $string =~ /../g; # use ... for three,

Re: Split based on length

2003-09-17 Thread John W. Krahn
Nyimi Jose wrote: Do you see any pitfall if i remove the 'm' on the regexp And use $string =~ /.{1,$len}/g; instead ? I have tried without the 'm', it works as well :-) If you use // to delimit the regular expression then the 'm' is not required. In other words, m// and // are exactly the

RE: Split based on length

2003-09-17 Thread Dan Muey
Hi, Howdy you can use split for this sort of thing. For example: my $string = hello there; # add an extra '.' for every character you want my @pairs = split(/(..)/, $string); The only thing you want to be careful about is empty quotes/nothing (e.g. ''). For example, if we wanted to

Re: Split based on length

2003-09-17 Thread Stephen Hardisty
for(split(/(..)/, $string)) { print *$_ if $_; } Gorgeous :o) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]