.
-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
]
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
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
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
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) =
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]
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
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
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
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
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
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',
, 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
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,
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
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
for(split(/(..)/, $string)) { print *$_ if $_; }
Gorgeous :o)
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
17 matches
Mail list logo