in reply to Easiest way to do something only on first iteration of loop
#!/usr/bin/perl # http://perlmonks.org/?node_id=1162396 use strict; use warnings; # display_paragraph(array_ref, indentation) # # print lines of array, indenting all but first line. # Note: use strict and use warnings are in effect, # so must declare 'my' vars! # sub display_paragraph { my $aref = shift; my $indentation; for my $line (@$aref) { print ' ' x ($indentation // 0), "$line\n"; $indentation //= shift; } } display_paragraph( [ qw( one two three four five )], 2);
|
|---|