[Israel.pm] splitting a string

Tal Kelrich tal at musicgenome.com
Wed Sep 27 05:41:35 PDT 2006


On Wed, 27 Sep 2006 14:58:30 +0200
"Benrey Yosi" <YosiB at pelephone.co.il> wrote:

> $a="123456";
> ($b,$c)=(substr($a,0,length($a)/2),substr($a,length($a)/2,length($a)/2))
> ;
> 

This only works if your string contains an even number of characters,
so isn't very good.
you could use the following, but it's equally silly, IMHO.

$a="1234567";
$hlen=int(length($a)/2);
($b,$c)=(substr($a,0,$hlen),substr($a,$hlen)) ;
print "$b - $c" 

-- 
Tal Kelrich
PGP fingerprint: 3EDF FCC5 60BB 4729 AB2F  CAE6 FEC1 9AAC 12B9 AA69
Key Available at: http://www.hasturkun.com/pub.txt
----
I don't have an eating problem. I eat. I get fat. I buy new clothes. No
problem.
----
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://perl.org.il/pipermail/perl/attachments/20060927/38cc2e77/attachment.pgp 


More information about the Perl mailing list