IMHO $string =~ /.{1,$len}/g; Is the best suggestion i have seen so far ;) I have an other request : "code review" :-) Below is my final code. I'm sure that you guys will find Some better style to write it ...
#!/usr/local/bin/perl -w use strict; #------------------ #Global variables #------------------ my $group_len=64; my $index_len='A1'; my $name_len='A6'; my $way_len='A3'; my $delim_len='x1'; my $meas_len='A5'; my $nof_meas=9; #------ #Main #------ my $file=$ARGV[0]; open(FH,$file) || die "can not open $file : $! \n"; while(my $line=<FH>){ next if $. < 3; my($date,$dummy,$str)=$line=~/(\d{2}-\d{2}-\d{4}:\d{3})\s+(\d{2})(.+)/; for( &split_len($str,$group_len) ){ print $date."\t", join( "\t",&get_fields($_) ),"\n"; } } close(FH); #------------ #Subroutines #------------ sub split_len{ my ($str, $len) = @_; $str =~ /.{1,$len}/g; } sub get_fields{ my($str)[EMAIL PROTECTED]; my $format="$index_len $name_len $way_len"; $format.=" $delim_len $meas_len" x $nof_meas; unpack($format,$str); } -----Original Message----- From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED] Sent: Friday, September 19, 2003 12:17 AM To: Bob Showalter Cc: Stephen Hardisty; [EMAIL PROTECTED] 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 the size that we want, that we then have to filter through? @parts = $string =~ /.{1,$len}/sg; and you're done. -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] **** DISCLAIMER **** "This e-mail and any attachment thereto may contain information which is confidential and/or protected by intellectual property rights and are intended for the sole use of the recipient(s) named above. Any use of the information contained herein (including, but not limited to, total or partial reproduction, communication or distribution in any form) by other persons than the designated recipient(s) is prohibited. If you have received this e-mail in error, please notify the sender either by telephone or by e-mail and delete the material from any computer". Thank you for your cooperation. For further information about Proximus mobile phone services please see our website at http://www.proximus.be or refer to any Proximus agent. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]