LanceDeeply has asked for the wisdom of the Perl Monks concerning the following question:
unpackin(); sub unpackin { my $text = 'girl,you,really,got,me,now,you,got,me,so,i,dont,know,w +hat,im,doin,666,777,99.99'; my @ar = split /,/, $text ; my @lens = map { length } @ar ; my $index = 0; my $format = ''; foreach my $len (@lens) { $format .= "A$len" . 'A'; } my $odd= 1; my @words = grep { ($odd) ? ($odd=0)+1 : ($odd=1)-1 ;} unpack($for +mat, $text ); print "( @ar )\n"; print "( @lens )\n"; print "format = $format\n"; print join "|", @words; print "\n"; }
i'd love to be able to do this without having to skip every other element in the result aray...( girl you really got me now you got me so i dont know what im doin 66 +6 777 99.99 ) ( 4 3 6 3 2 3 3 3 2 2 1 4 4 4 2 4 3 3 5 ) format = A4AA3AA6AA3AA2AA3AA3AA3AA2AA2AA1AA4AA4AA4AA2AA4AA3AA3AA5A girl|you|really|got|me|now|you|got|me|so|i|dont|know|what|im|doin|666| +777|99.99
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: unpack format string for ignoring chars
by BrowserUk (Patriarch) on Feb 13, 2004 at 21:32 UTC | |
by LanceDeeply (Chaplain) on Feb 13, 2004 at 21:51 UTC |