in reply to Re: rectangularizing input to become array
in thread rectangularizing input to become array
The many and various uses of pack. I'm glad to have another useful example. What's the A template?
Code replication between readmore tags, invocation, output, then source.
$ ./1.shiraz.pl $raRect = 'abcdef', 'abcdef', 'abcde ', ' bcdef' ; $
#!/usr/bin/perl -w use 5.011; use Data::Dumper; open my $inFH, q{<}, \ <<__EOD__ or die $!; abcdef abcdefg abcde bcdefgh bcd __EOD__ chomp( my @lines = <$inFH> ); close $inFH or die $!; my $width = 6; my $height = 4; my $raRect = makeRect( \ @lines, $width, $height ); print Data::Dumper->Dumpxs( [ $raRect ], [ qw{ raRect } ] ); sub makeRect { my( $raLines, $width, $height ) = @_; my @rect; push @rect, pack qq{A$width}, shift @{ $raLines } for 1 .. $height +; return \ @rect; }
Can you say a few words about this line of code (I've never seen this before in Data::Dumper)?
print Data::Dumper->Dumpxs( [ $raRect ], [ qw{ raRect } ] );Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: rectangularizing input to become array
by johngg (Canon) on Mar 01, 2019 at 12:41 UTC | |
|
Re^3: rectangularizing input to become array
by haukex (Archbishop) on Mar 01, 2019 at 08:43 UTC |