row to column conversion problem

K

kuldeep

Problem statement

Input from a file

010101
110010
010101


to

010
111
000
101
010
101

i.e. Row to column conversion

I was thinking of reading each line as a string and then spitting one
binary elemnt at a time to make big array which can be printed. But i
don't know how to
do that in perl. Is there any function to convert
binary string to hex
spit one bit at a time from a hex value

any better ideas?

thx
Kuldeep
 
G

Gunnar Hjalmarsson

kuldeep said:
Problem statement

Input from a file

010101
110010
010101


to

010
111
000
101
010
101

i.e. Row to column conversion

my @rows;
while (<FH>) {
my $i = 0;
$rows[$i++] .= $_ for split //;
}
 
A

Anno Siegel

Gunnar Hjalmarsson said:
kuldeep said:
Problem statement

Input from a file

010101
110010
010101


to

010
111
000
101
010
101

i.e. Row to column conversion

my @rows;
while (<FH>) {
my $i = 0;
$rows[$i++] .= $_ for split //;
}

You forgot to chomp the lines.

Anno
 
G

Gunnar Hjalmarsson

Anno said:
Gunnar said:
my @rows;
while (<FH>) {
my $i = 0;
$rows[$i++] .= $_ for split //;
}

You forgot to chomp the lines.

Yes, I did. Thanks!

my @rows;
while (<FH>) {
chomp;
my $i = 0;
$rows[$i++] .= $_ for split //;
}
 
A

Anno Siegel

Gunnar Hjalmarsson said:
Anno said:
Gunnar said:
my @rows;
while (<FH>) {
my $i = 0;
$rows[$i++] .= $_ for split //;
}

You forgot to chomp the lines.

Yes, I did. Thanks!

my @rows;
while (<FH>) {
chomp;
my $i = 0;
$rows[$i++] .= $_ for split //;
}

Speaking of chomp reminds me of chop:

chomp( my @lines = <DATA>);
my @cols;
unshift @cols, join( '', map chop, @lines) while length $lines[ 0];

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top