![]() |
dump the real string
my $line = <>; I input "a" and press enter. Now $line should contain 2 bytes: 'a' and end-of-line character. How could I print the content of $line (both bytes) in hex format? -- .~. Might, Courage, Vision. In Linux We Trust. / v \ http://www.linux-sxs.org /( _ )\ Linux 2.4.22-xfs ^ ^ 8:58pm up 2:41 1 user 0.99 0.98 |
Re: dump the real string
"toylet" <toylet_at_mail.hongkong.com> wrote in message news:403c9d1f_2@rain.i-cable.com... > > my $line = <>; > > I input "a" and press enter. > > Now $line should contain 2 bytes: 'a' and end-of-line character. > > How could I print the content of $line (both bytes) in hex format? > perldoc -f substr perldoc -f hex |
Re: dump the real string
>> my $line = <>;
>> >> I input "a" and press enter. >> >> Now $line should contain 2 bytes: 'a' and end-of-line character. >> >> How could I print the content of $line (both bytes) in hex format? > perldoc -f substr > perldoc -f hex hex() should not be relevant as I need to convert from numeric to hex digits. Already knew about substr(). -- .~. Might, Courage, Vision. In Linux We Trust. / v \ http://www.linux-sxs.org /( _ )\ Linux 2.4.22-xfs ^ ^ 9:30pm up 3:13 1 user 1.03 1.00 |
Re: dump the real string
>> my $line = <>;
> perldoc -f substr > perldoc -f hex I tried this: printf(".%x.\n.%x.\n",substr($line,0,1),substr($li ne,1,1)); and perl said substr($line) are not numeric. -- .~. Might, Courage, Vision. In Linux We Trust. / v \ http://www.linux-sxs.org /( _ )\ Linux 2.4.22-xfs ^ ^ 9:34pm up 3:17 1 user 1.11 1.04 |
Re: dump the real string
>> my $line = <>;
>> I input "a" and press enter. and which function will return the length of $line as 2 bytes? $line is already in scalar context. -- .~. Might, Courage, Vision. In Linux We Trust. / v \ http://www.linux-sxs.org /( _ )\ Linux 2.4.22-xfs ^ ^ 9:38pm up 3:21 1 user 1.04 1.01 |
Re: dump the real string
toylet wrote:
>>> my $line = <>; >> perldoc -f substr >> perldoc -f hex > > I tried this: > printf(".%x.\n.%x.\n",substr($line,0,1),substr($li ne,1,1)); > > and perl said substr($line) are not numeric. > got it... they got the c and foxpro function chr() from the doc, I saw ord(). my $line=<> printf(".%x.\n.%x.\n",ord(substr($line,0,1)),ord(s ubstr($line,1,1))); -- .~. Might, Courage, Vision. In Linux We Trust. / v \ http://www.linux-sxs.org /( _ )\ Linux 2.4.22-xfs ^ ^ 9:40pm up 3:23 1 user 1.04 1.01 |
Re: dump the real string
toylet wrote:
>>> my $line = <>; >>> I input "a" and press enter. > > and which function will return the length of $line as 2 bytes? > $line is already in scalar context. > OK, I think it should be length(). -- .~. Might, Courage, Vision. In Linux We Trust. / v \ http://www.linux-sxs.org /( _ )\ Linux 2.4.22-xfs ^ ^ 9:42pm up 3:25 1 user 1.05 1.01 |
Re: dump the real string
>> Already knew about substr().
> Then why did you ask? Not sure whether perl store strings like C. -- .~. Might, Courage, Vision. In Linux We Trust. / v \ http://www.linux-sxs.org /( _ )\ Linux 2.4.22-xfs ^ ^ 10:08pm up 3:51 1 user 1.13 1.10 |
Re: dump the real string
toylet <> wrote:
> my $line=<> > printf(".%x.\n.%x.\n",ord(substr($line,0,1)),ord(s ubstr($line,1,1))); Or, not assuming the length of $line is 2: printf ".%02x.\n", ord foreach (split //, $line); -- Glenn Jackman NCF Sysadmin glennj@ncf.ca |
Re: dump the real string
toylet wrote:
> my $line = <>; > > I input "a" and press enter. > > Now $line should contain 2 bytes: 'a' and end-of-line character. > > How could I print the content of $line (both bytes) in hex format? Why are you asking the same question twice within 3 minutes? jue |
| All times are GMT. The time now is 10:38 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.