sanju.shah wrote: > > I am looking for some suggestions on any advanced functions Perl might > have that i might be missing. > > Basically, I have an array with column widths. Next I have a string. I > would like to extract the number of characters based on the column- > widths in the array. I have already tried using substr but is there > any other way of extracting? > > eg: > > @col_width = (4,2,17); > my $str = 'Perl is amazing language'; > > I'd like a one-line command (if possible) to store 'Perl' in $a, 'is' > in $b & 'amazing language' in $c.
Except that the last column is sixteen characters long rather than seventeen, this should suit your purpose. HTH, Rob use strict; use warnings; my @col_width = (4,2,16); my $str = 'Perl is amazing language'; my @words; $str =~ /(.{$_})\s*/g and push @words, $1 for @col_width; print "$_\n" foreach @words; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/