LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-29-2011, 11:01 AM   #1
gfem
Member
 
Registered: Apr 2003
Distribution: Fedora
Posts: 126

Rep: Reputation: 15
Ruby to Perl need help converting a function


I am new to both Ruby and Perl so I am requesting a translation for the following functions. I understand how the commands work,up to the ".collect" but cant wrap my mind around what the join does and how it gets the result.

I am trying to duplicate the result of the following commands in a Perl script. The data I get back from my socket connection is " b&WjP&Wl~'jb&Wj`P&Wl~'jb&WðèP&Wl " and I am trying to convert it into hex ex(02621426570F6B06 262142657f6b66 250142657176c7e276b6 ).

Ruby Code listed below. I can attach the whole script if needed.

def hexlify(msg)
msg.split("").collect { |c| c[0].to_s(16) }.join
end

def unhexlify(msg)
msg.scan(/../).collect { |c| c.to_i(16).chr }.join
end

Thank you.

-Gregg
 
Old 09-29-2011, 01:39 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Did you have a look at the ri information for join.

Simply put it will join the resulting item together based on the default output field separator ($,)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl vs. Ruby vs. Python vargadanis Programming 53 12-31-2010 12:37 PM
Ruby vs Perl vs Python coolgreen1 Programming 15 12-13-2010 01:36 AM
Perl or Ruby or Python? Or something else? MasterOfTheWind Programming 18 05-07-2009 12:43 PM
ruby equivalent of PHP's print_r(); function?? opioid Programming 1 04-08-2005 01:23 PM
Perl exec function in linux (and system-function) nazula Programming 1 04-19-2004 12:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration