in reply to Split at specific spaces

Yet another way using split on spaces but with a capture so the spaces are retained. Discard every 6th element then join five at a time.

$ perl -E ' > $_ = q{1 AC2 34 TRP A 6 ALA A 7 ILE A 14 GLY A 15}; > @e = grep { ( ++ $i ) % 6 } split m{(\s+)}; > say join q{}, map { shift @e } 1 .. 5 while @e;' 1 AC2 34 TRP A 6 ALA A 7 ILE A 14 GLY A 15 $

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^2: Split at specific spaces
by k_manimuthu (Monk) on May 12, 2010 at 09:26 UTC

    And Another One Way

    $name=qq(1 AC2 34 TRP A 6 ALA A 7 ILE A 14 GLY A 15); split (/ /, $name); ### Process the temp array for ( $i=0; $i<=$#_; $i++) { push @get, (join ' ', @_[$i..$i+2]); $i=$i+2; } print "\n$_" for @get;
      While this code does produce correct results in this case, you are ignoring a warning message because you do not use strict and warnings:
      Use of implicit split to @_ is deprecated