English 中文(简体)
包装和包装功能
原标题:Perl pack and unpack functions
  • 时间:2012-01-14 00:50:09
  •  标签:
  • perl

I am trying to unpack a variable containing a string received from a spectrum analyzer:

#42404?û¢-+Ä¢-VÄ¢-oÆ¢-8æ¢-bÉ¢-ôÿ¢-+Ä¢-?Ö¢-sÉ¢-ÜÖ¢-¦ö¢-=Æ¢-8æ¢-uô¢-=Æ¢-Å¢-uô¢-?ü¢-}¦¢-=Æ¢-)...

格式是32种,其中使用4种 by来储存每值。 第42404号是现有4个特质,2404/4 = 601个点。 数据始于第42404号之后。 现在,我收到这一文件,使之成为一个巨大的变量,

$lp = ibqry($ud,":TRAC:DATA? TRACE1;*WAI;");

我不敢肯定,如何将这一数据转化为一系列的数字:...... 我是否应该像追随者那样做?

@dec = unpack("d", $lp);

我知道这一点并不有效,因为我没有获得正确的价值观,而数据点的数量肯定不是601。

最佳回答

首先,你必须删除<代码>#42404,并希望以下双向数据不会成为ASCII号。

$lp =~ s{^#d+}{};

我不敢确定“Real 32”是什么样的格式,但我会想到,它是一个单一精确的浮动点,长32个轨道。 查阅d为64 bits。 因此,I d 尝试f,即“单一精准”。

@dec = unpack("f*", $lp);

Whether your data is big or little endian is a problem. d and f use your computer s native endianness. You may have to force endianness using the > and < modifiers.

@dec = unpack("f*>", $lp);  # big endian
@dec = unpack("f*<", $lp);  # little endian
问题回答

第1条<代码>4 在浮标之前编码其余数字(2404)。

my @dec = unpack "x a/x f>*", $lp;

<代码>x skips the main #,a/x 读到一位数位数位数和数位数,其中有许多特性,f>*将其余标示作为32个大端浮动的顺序。 (如果产出看上去,则使用<代码>f<*。)





相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签