file processing in Perl

file processing in Perl

am 09.11.2007 13:01:49 von 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 = ) {

.....

}

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

Re: file processing in Perl

am 09.11.2007 13:49:14 von jurgenex

thunder wrote:
> 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

Re: file processing in Perl

am 09.11.2007 14:13:57 von Ben Morrow

Quoth thunder :
>
> 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

Re: file processing in Perl

am 09.11.2007 14:16:29 von Paul Lalli

On Nov 9, 7:01 am, thunder wrote:

> Each line of the file consists of a 32-bit hex value.
>
> I am using
>
> while ($input_line = ) {
> .....
> }
>
> 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

Re: file processing in Perl

am 09.11.2007 14:19:46 von krahnj

thunder wrote:
>
> 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 = ) {
> .....
> }
>
> 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
--
use Perl;
program
fulfillment