print {$file_handle} join( ", ", @array )
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/usr/bin/perl use strict; use warnings; my @array = qw(1 22 333 4 555 6 7777 8 9999 10 11 121212 131313 14 15 16); my $max = 3; # Umbruch nach 3 Werten for my $i ( 0 .. $#array ) { print "\n" if $i and $i % $max == 0; # Newline wenn mehr als $max Werte print $array[$i]; # Wert ausgeben print ", " if $i != $#array; # kein Komma wenn letztes Element }
1
2
3
4
5
6
7
8
9
10
11
12
$ perl -we '
> my @values = 1..10;
> my $max = 3;
> while ( my @parts = splice(@values, 0, $max) ) {
> print join ", ", @parts, ( $#parts == 2 ? "\n" : () );
> }
> print "\n";
> '
1, 2, 3,
4, 5, 6,
7, 8, 9,
10
1
2
3
4
5
6
7
8
9
10
$ perl -we '
my @arr = 1 .. 10;
my $max = 3;
print join ", ", map { $_ == 0 || $_ % $max ? $arr[$_] : "\n$arr[$_]" } 0 .. $#arr;
print "\n";
'
1, 2, 3,
4, 5, 6,
7, 8, 9,
10
Guest Robin G.Warum eigentlich das Dateihandle in geschweifte Klammern?Code: (dl )print {$file_handle} join( ", ", @array )
Guest Robin G.Du meinst aber ein Newline, also ein "\n"?kann ich hier ein /n nach x mal print $_; einbauen ?
1 2 3 4 5 6 7
for ( my $pos = 0 ; $pos < $#$puzzle_chars_ref ; $pos += 9 ) { # for better human readability if ( $pos > 0 and $pos % 27 == 0 ) { print $out "\n" } printf $out "%s%s%s %s%s%s %s%s%s\n", ( @$puzzle_chars_ref[ $pos .. $pos + 8 ] ); }
print join(", ", @array) =~ s/(\d+, ){3}/$&\n/gr;
1 2 3
use feature qw/:5.10/; my @array = qw(1 22 333 4 555 6 7777 8 9999 10 11 121212 131313 14 15 16); say join(',', shift @array, shift @array // (), shift @array // () ) while (@array);
say join(',', splice(@array, 0, 3)) while @array;
1 2 3 4 5 6 7 8 9
#!/usr/bin/env perl use 5.012; use List::MoreUtils qw/natatime/; my @data = (5, 10, 12, 15, 11, 11, 12); for (my $it = natatime 3, @data; my @it = $it->(); ) { say join(', ', @it); }
Guest Robin G.5, 10, 12,
15, 11, 11,
12