file processing in Perl

T

thunder

Hello

I am trying to read a file in perl and then process it.

Each line of the file consists of a 32-bit hex value.

I am using

while ($input_line = <IN_FILE>) {

.....

}

However, for each line i read i want to interpret it as a data value
and do some shifting to this data value. But perl still thinks this
is a string value and won't allow me to do the shifting.


QS; How do i convert the string value of the line read to a scalar/
data value?

Any other suggestions greatly appreciated.


Thanks in advance


J
 
J

Jürgen Exner

thunder said:
Each line of the file consists of a 32-bit hex value.

However, for each line i read i want to interpret it as a data value
and do some shifting to this data value. But perl still thinks this
is a string value and won't allow me to do the shifting.
QS; How do i convert the string value of the line read to a scalar/
data value?

Well, but strings _are_ scalars as well as data.

Maybe you are looking for unpack()?

jue
 
B

Ben Morrow

Quoth thunder said:
I am trying to read a file in perl and then process it.

Each line of the file consists of a 32-bit hex value.
However, for each line i read i want to interpret it as a data value

You mean 'as a number'. You want unpack with the 'H' format.

Ben
 
P

Paul Lalli

Each line of the file consists of a 32-bit hex value.

I am using

while ($input_line = <IN_FILE>) {
.....
}

However, for each line i read i want to interpret it as a data
value and do some shifting to this data value. But perl still
thinks this is a string value and won't allow me to do the
shifting.

QS; How do i convert the string value of the line read to a scalar/
data value?

Your question is nonsensical. A string IS a scalar, and IS data.

What is it you actually want to do? Provide sample input and desired
output to demonstrate.

Paul Lalli
 
J

John W. Krahn

thunder said:
I am trying to read a file in perl and then process it.

Each line of the file consists of a 32-bit hex value.

I am using

while ($input_line = <IN_FILE>) {
.....
}

However, for each line i read i want to interpret it as a data value
and do some shifting to this data value. But perl still thinks this
is a string value and won't allow me to do the shifting.

$ perl -le' $data = q[ABCDEF01]; printf "%X\n", hex $data '
ABCDEF01
$ perl -le' $data = q[ABCDEF01]; printf "%X\n", hex( $data ) >> 8 '
ABCDEF
$ perl -le' $data = q[ABCDEF01]; printf "%X\n", hex( $data ) >> 10 '
2AF37B



John
 

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,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top