User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » any Perl gurus out there? Page [1] 2 3, Next  
AstralEngine
All American
3864 Posts
user info
edit post

I am having a tough time figuring out how to make something work. I have a string:

$String = "68 74 74 70 3a 2f 2f 31 36 30 2e 31 35 33 2e 34 33 2f 00 00 00 00 00 18"

This string is hex, but perl thinks it's decimal when it gets assigned like that because when I try to unpack it into ascii, I get the wrong ascii characters.

Does someone know a good way to convert this string into a string interpreted as hex so that I can convert it into an ascii string?

thanks

8/4/2009 5:44:25 PM

dakota_man
All American
26584 Posts
user info
edit post

1) http://perldoc.perl.org/functions/unpack.html
1) http://perldoc.perl.org/functions/split.html
2) http://perldoc.perl.org/functions/hex.html

?

[Edited on August 4, 2009 at 5:51 PM. Reason : that's not what unpack does, apparently]

[Edited on August 4, 2009 at 6:01 PM. Reason : actually, nm. I don't know much about pack/unpack but it looks like you could make unpack do it...]

8/4/2009 5:49:36 PM

Solinari
All American
16957 Posts
user info
edit post

I'm sorry but since this question doesn't have anything to do with administering a webserver or answering tech-support questions, you'll have a hard time getting any productive responses.

However, I am here to help. Check out the 'pack' command:
http://perl.active-venture.com/pod/func/pack.html

8/4/2009 7:08:40 PM

AstralEngine
All American
3864 Posts
user info
edit post

Did you even read it, I'm trying to use pack already. The problem is that the string is a decimal representation (as far as perl is concerned) but is hex (as far as what I know it is).

I can't pack it into hex first, it is hex so I'll get the wrong values. I also can't convert is straight to ascii, perl thinks it's decimal, so I'll get the wrong values.

8/4/2009 9:06:17 PM

dakota_man
All American
26584 Posts
user info
edit post

unpack could theoretically do it, but it would help if the string was more like 0xAA0x12etc, etc. The string you have looks like it is the RESULT of the pack command, converting ASCII characters into a hex string. If that was the case, unpack will do it, I just couldn't figure out how to account for the space in between the values.

So using pack again is closest to the opposite of what needs to happen.

Like I linked, you could use split to slice up the string and get an array, and then use hex to get the integers corresponding to the proper ASCII values for each character. I haven't tried this, but it should work. There is, however, probably some super leet one line way to do it with a regex, but split/hex would at least do what you want.

8/4/2009 9:23:51 PM

Fail Boat
Suspended
3567 Posts
user info
edit post

Look, you're a 22 yr old sr in computer science. You shouldn't have to turn to the wolfweb for this.

8/4/2009 9:26:09 PM

AstralEngine
All American
3864 Posts
user info
edit post

^^ Yeah, good call, I can unpack it with the hex() call and it works perfectly.

^ I don't know what illusionary world you live in, but the NC State computer science department doesn't teach everything you need to know about anything, much less perl and the built in functions that help solve problems you may have

8/4/2009 9:51:08 PM

AstralEngine
All American
3864 Posts
user info
edit post

pack("H*", join '', split / /, $string) is the one liner that takes care of it, fyi

8/5/2009 9:01:20 AM

Fail Boat
Suspended
3567 Posts
user info
edit post

Know, the CSC department hasn't figured out a way to implant the knowledge of all languages into your brain, but they definitely should have you to the point where you can google around, try shit out, and read documentation. I know the department is mildly lackluster, but it isn't that.

8/5/2009 9:09:07 AM

dakota_man
All American
26584 Posts
user info
edit post

lol, wow. I guess pack is what you want to use. Can you do the same thing with unpack? To me that string looks like something that's was generated from an ASCII string with pack - packing each character into hex and separating with a space.

8/5/2009 10:55:34 AM

Solinari
All American
16957 Posts
user info
edit post

I feel vindicated. Thx for the update AstralEngine

8/5/2009 11:25:05 AM

Pikey
All American
6421 Posts
user info
edit post

My new blackberry Tour kicks the Perl's ass.

8/5/2009 11:36:42 AM

AstralEngine
All American
3864 Posts
user info
edit post

It was not generated with pack, it's the hex returned from a SCSI target

^x4 Fantastic, Fail Boat's idea of "what you're supposed to get out of college" is a mediocre skill at searching google for the answers to your questions. I, for one, feel that NC State has succeeded at this menial task.....



......


Oh wait, I could already search google for this shit, and have been. There's nothing wrong with asking people who may be more knowledgeable for the answer, though

8/5/2009 2:04:19 PM

Fail Boat
Suspended
3567 Posts
user info
edit post

Excellent, not only can you not think for yourself, but your reading comprehension is terrible. Guys like you make me glad that I somehow was attracted to ECE and not CSC.

8/5/2009 3:15:20 PM

dakota_man
All American
26584 Posts
user info
edit post

How long have you been at your current position?

8/5/2009 3:36:40 PM

Fail Boat
Suspended
3567 Posts
user info
edit post

I'm not sure what at all that has to be with being too inept to figure out the most simple of problems.

What stellar line of work do you do?

8/5/2009 3:56:48 PM

dakota_man
All American
26584 Posts
user info
edit post

And I'm not sure what anything you've posted in this thread has to do with figuring out the best way to parse/convert that string in Perl. Asking something that you could figure out with Google isn't always retarded - it's not like you can have a real discussion about a question with a search engine.

But since we figured out the Perl question, what should the thread be about now? The CSC department, asking questions in tech talk, your unemployment, or my job?

[Edited on August 5, 2009 at 4:29 PM. Reason : grammar]

8/5/2009 4:28:38 PM

Stein
All American
19842 Posts
user info
edit post

The guy bitching about reading comprehension is also the guy who showed on this page he didn't know the different between "Know" and "No".

Lets just chalk it up to sand lodged some place pretty uncomfortable.

Also, everyone knows that dakota_man is a successful restauranteur.

8/5/2009 4:38:22 PM

dakota_man
All American
26584 Posts
user info
edit post

Aw, shucks.

8/5/2009 4:53:01 PM

Fail Boat
Suspended
3567 Posts
user info
edit post

Since you missed the memo Stein, here it is again

message_topic.aspx?topic=570112

Quote :
"And I'm not sure what anything you've posted in this thread has to do with figuring out the best way to parse/convert that string in Perl."


You're exactly right I haven't because something this mundane from a senior in CSC blows my mind. Given the CSC departments less than wonderful reputation in this section, I'm not exactly surprised, but it isn't like he was doing something so bizarre or different that a little trial and error couldn't get the problem solved.

Quote :
"it's not like you can have a real discussion about a question with a search engine."

Oh, right, that is exactly what he was doing, wanting to have a discussion about it, not just someone to tell him what he was fucking up.
I mean come on, this isn't mind blowing perl right here pack("H*", join '', split / /, $string)

Quote :
"Also, everyone knows that dakota_man is a successful restauranteur."

Clearly everyone knows this!

8/5/2009 11:07:46 PM

Stein
All American
19842 Posts
user info
edit post

Dude, I'm not going to read an ignored thread you post so that I can understand your terrible posting habits.

That's asking me to believe that somehow despite constant shit posts, your threads are going to come up diamonds.

8/5/2009 11:34:58 PM

Fail Boat
Suspended
3567 Posts
user info
edit post

You read the thread dipshit.

8/5/2009 11:35:58 PM

Stein
All American
19842 Posts
user info
edit post

Actually, I clicked the link, saw you were the first poster and closed it.

You might have actually tricked me into reading it if you'd used one of your like other aliases!

8/5/2009 11:40:27 PM

Fail Boat
Suspended
3567 Posts
user info
edit post

You're a terribly boring troll.

8/5/2009 11:50:43 PM

AstralEngine
All American
3864 Posts
user info
edit post

No wonder you're 40 and unemployed. I, on the other hand, have a job this summer with a great company and will more than likely have a full time position here after graduation.

Perhaps my ability to communicate and willingness to not only seek out, but also share, information matched with my not-troll personality (read "not fail boat") make me a considerably better candidate in the job market.

I bet you go out of your way to be a dick in real life, too... Explains a lot about your current jobless situation.

Good luck with that

8/6/2009 10:17:14 AM

Fail Boat
Suspended
3567 Posts
user info
edit post

I managed guys like you at my last job. Just sayin.

8/6/2009 10:19:53 AM

AstralEngine
All American
3864 Posts
user info
edit post

You also lost your last job.


Just sayin

8/6/2009 10:26:05 AM

dakota_man
All American
26584 Posts
user info
edit post

Quote :
"Soap Box 2.0"


Fuck yeah.

Quote :
"You're exactly right I haven't because something this mundane from a senior in CSC blows my mind. Given the CSC departments less than wonderful reputation in this section, I'm not exactly surprised, but it isn't like he was doing something so bizarre or different that a little trial and error couldn't get the problem solved."


Just because it's conceptually easy doesn't mean it's easy, especially in Perl. If they haven't changed it, NCSU has a 1 hr scripting course that "teaches" Perl. I mean, if you got your CSC degree to process text with Perl, you're doing it wrong. Then there's the problems with Perl in general, http://www.perlmonks.com/?node_id=561229 covers a little of that. It's pretty hard to grasp if you've never done it before or if you're used to more consistent high level languages -- which is what you'd expect from somebody still in school for computer science. The only reason I know anything about it is because I was forced to use it on a project while I was a co-op at IBM. The only reason I've used it since (besides the 1 hr course) is to parse log files that were output by applications written in other programming languages.

Quote :
"Oh, right, that is exactly what he was doing, wanting to have a discussion about it, not just someone to tell him what he was fucking up.
I mean come on, this isn't mind blowing perl right here pack("H*", join '', split / /, $string)"


Asking a question on a message board might get you exactly the answer you want the first time, but it probably won't. Same thing with google, except you can't go back and forth with google to get what you want the way you can with other people on a message board.

Further, pasting the one line answer the OP found after the fact and calling it easy or trivial just makes you sound retarded. Again, because it's Perl, the "correct" solution to something like that is usually compact - and the fact that it's compact doesn't mean it's trivial.

The other thing that makes you look retarded is the thread you made that basically says "fyi if I fuck up in the future it's because I'm doing it on purpose, so if you call me out on it then it's really you who fucked up."

Maybe you should get out of your ivory basement and use your prestigious ECE degree to make contributions to tech talk; or, you know, at least to the economy.

[Edited on August 6, 2009 at 10:30 AM. Reason : grammar]

8/6/2009 10:29:12 AM

FroshKiller
All American
51911 Posts
user info
edit post

ahahahaha holy shit this mug dropped "ivory basement"

dakota, i love you

i have missed you so much

8/6/2009 10:36:15 AM

dakota_man
All American
26584 Posts
user info
edit post

you had me at 'ahahahaha'

8/6/2009 10:45:32 AM

Fail Boat
Suspended
3567 Posts
user info
edit post

Quote :
"You also lost your last job."


My last company went bankrupt because

1) Dram prices in the last 90s were retardo
2) Microsoft Vista was going to be a dram lover requiring tons more memory
3) It takes multiple multiple billions to build fabs
4) The Asians mfg costs are super cheap compared to Americans and Germans
5) Global economic crisis

But if it helps you to feel better about your inability to figure out something so simple, then you can just assume that I caused all of the above and that is why I am in the job market.

Quote :
"Just because it's conceptually easy doesn't mean it's easy, especially in Perl. If they haven't changed it, NCSU has a 1 hr scripting course that "teaches" Perl."

Yeah, I took it with Borwick.
Quote :
"I mean, if you got your CSC degree to process text with Perl, you're doing it wrong. "

Reading comprehension ftl.

Quote :
"It's pretty hard to grasp if you've never done it before or if you're used to more consistent high level languages -- which is what you'd expect from somebody still in school for computer science."

Maybe I jumped the gun but I assume based on the nature of the question that he was a little more advanced than total noob.

Quote :
"Asking a question on a message board might get you exactly the answer you want the first time, but it probably won't. Same thing with google, except you can't go back and forth with google to get what you want the way you can with other people on a message board."

Hey, if message boards and google are always around anytime you get stuck on a problem, then I see no reason to resort to them. I still contend the problem wasn't such that he should have needed either, and he certainly should have been able to figure it out on his own (and he did) without having someone else do the work for him.

Quote :
"Further, pasting the one line answer the OP found after the fact and calling it easy or trivial just makes you sound retarded. Again, because it's Perl, the "correct" solution to something like that is usually compact - and the fact that it's compact doesn't mean it's trivial."

That solution is a pretty long way from a classic perl "one liner".

Quote :
"The other thing that makes you look retarded is the thread you made that basically says "fyi if I fuck up in the future it's because I'm doing it on purpose, so if you call me out on it then it's really you who fucked up.""

Actually, know. I made that thread in response to the grammar nazi's and when I think about it I purposefully put grammar and spelling errors in the post. I would have assumed sticking "know" there would have been so glaringly obvious that no normal person would actually take the time to point it out. It gives me a micro amount of pleasure to no people here just can't stand not pointing them out over and over again.


Quote :
"
Maybe you should get out of your ivory basement and use your prestigious ECE degree to make contributions to tech talk"

Well, Solinari more or less called it, there isn't anything "tech" that goes on here. I made a thread awhile back about what haxor projects were you working on and it got a few posts. It's all phones, computer specs, web programming questions, game consoles. I actually did contribute to the last real ECE thread that was posted
http://thewolfweb.com/message_topic.aspx?topic=572301

Quote :
"or, you know, at least to the economy"

Yeah, the 16.5% of us that are unemployed/underemployed will just invent our own job, pay ourselves with our own money, and sell products to other unemployed/underemployed people.

Maybe we can start a company to do mundane google searches and solve simple programming problems for summer job having CSC kids? How much do you think they'd be willing to pay for that service, more or less than UI pays me now?

8/6/2009 10:54:49 AM

AstralEngine
All American
3864 Posts
user info
edit post

You mean the 16.5% of YOU

8/6/2009 10:57:57 AM

Fail Boat
Suspended
3567 Posts
user info
edit post

I'm fairly certain when I said us I meant us.

8/6/2009 11:00:53 AM

AstralEngine
All American
3864 Posts
user info
edit post

I just wanted to make it clear that I'm not in the fail boat with you.

8/6/2009 11:06:37 AM

qntmfred
retired
40726 Posts
user info
edit post

Quote :
"Maybe we can start a company to do mundane google searches and solve simple programming problems for summer job having CSC kids? How much do you think they'd be willing to pay for that service, more or less than UI pays me now?"


stackoverflow.com seems to be doing pretty well maybe you should ask them for a job

8/6/2009 11:07:15 AM

Fail Boat
Suspended
3567 Posts
user info
edit post

You mean they pay for crowd sourced content there? Seems like the only one who makes money on that is Joel and co.

8/6/2009 11:15:56 AM

AstralEngine
All American
3864 Posts
user info
edit post

Since the topic has changed for new ways to help Fail Boat make money, I decided to post this thread for you.

message_topic.aspx?topic=559587

Hopefully the money you earn will help pay for your operation

8/6/2009 11:22:46 AM

dakota_man
All American
26584 Posts
user info
edit post

Quote :
"Reading comprehension ftl."


I thought it was pretty clear my statement addressed CSC majors, not you.

Quote :
"That solution is a pretty long way from a classic perl "one liner"."


I agree that it's not a ridiculously complicated regex, but it is a one line combination of three different functions and pretty fucking far from self-explanatory (and I still don't see where you would figure that out from the pack() documentation (http://perldoc.perl.org/functions/pack.html) or from any of the numerous links I looked at on google without already having more Perl experience than I do). It definitely exemplifies the spirit of "classic" Perl, even if not in the most extreme way.

Quote :
"there isn't anything "tech" that goes on here"


I definitely agree with that. That's why I like to see threads like this - because I occasionally use Perl to parse log files. I wish there were more people that participated in threads about more advanced programming instead of a bunch of administrators, tech-support people, and web "developers" (not that there's anything wrong with having those jobs, I just don't care).

edit: that sounds like I'm calling Perl "more advanced programming". I'm not, it's just barely inside the realm of things that are interesting enough for me to respond to.

[Edited on August 6, 2009 at 11:51 AM. Reason : edit:]

8/6/2009 11:48:46 AM

Fail Boat
Suspended
3567 Posts
user info
edit post

The whole point is, he didn't seem to do any sort of rudimentary debug or problem solving to figure out what perl was spitting back at him and why it was different.

Quote :
"This string is hex"

Well, no it isn't, it's hex characters separated by spaces. You should at least know scalars and lists in perl context, and the very first line of the documentation should be a big "oh, durr" moment

Quote :
"Takes a LIST of values "

So, I'm not really surprised it pukes on a scalar, or rather a "hex string" with spaces in it to be more accurate.

Quote :
"but perl thinks it's decimal when it gets assigned like that because when I try to unpack it into ascii, I get the wrong ascii characters"

The first thing I would have done would have been to chop it down to just 68 and see what I got, and assuming that worked I'd add the " 74". Once that failed I might would try removing the space. Ah hah.

Engineering is problem solving and if you can't think critically about what the software/functions are doing, especially with such a simple task, you're going to be hopeless when the complexity gets worse.

Quote :
"but it is a one line combination of three different functions and pretty fucking far from self-explanatory (and I still don't see where you would figure that out from the pack() documentation"

Uh, why not?

pack TEMPLATE,LIST

I think split/join can be found in the first 20 pages of the little perl book from O'Reilly (sp?). I'll give it to you if you don't know much about perl at all then yes, that might look foreign, and I'll reneg and say that yes, that is a classic one liner, but not the "one liners" anyone that who has dealt with perl at all is aware of.

[Edited on August 6, 2009 at 12:12 PM. Reason : .]

8/6/2009 12:12:02 PM

AstralEngine
All American
3864 Posts
user info
edit post

Just because I had asked the question without a list of stuff I had already tried doesn't mean I haven't tried stuff.

The string WAS hex. It was a STRING of hex characters... I'm not entirely sure how that's different, or how you wouldn't have gotten my meaning unless you're an idiot.

when I chopped it down to just 68, it gave me the ascii character associated with DECIMAL 68 and not HEX 68, which is where the whole description of the problem was going.

when I read the documentation, it seemed to me like pack("H*"...) would pack the values it took INTO hex, which is not what I thought I wanted at the time, since I thought Perl would have tried to pack decimal 68 into it's hex representation. Which, as I've learned now, was wrong.

I hope you were more helpful to the people you "managed" at your old job, because this "you should be able to figure out everything on your own without asking for anyone's help" attitude is definitely not the way you help people be more productive.

I hope you don't bring that up in interviews, because no wonder you haven't been rehired.


[Edited on August 6, 2009 at 12:44 PM. Reason : ]

8/6/2009 12:37:05 PM

dakota_man
All American
26584 Posts
user info
edit post

Quote :
"Uh, why not?

pack TEMPLATE,LIST

I think split/join can be found in the first 20 pages of the little perl book from O'Reilly (sp?). I'll give it to you if you don't know much about perl at all then yes, that might look foreign, and I'll reneg and say that yes, that is a classic one liner, but not the "one liners" anyone that who has dealt with perl at all is aware of."


Yeah, split and join by themselves are a little more straightforward (see my original post in this thread). I wasn't aware part of the pack call would take those function results, but I didn't really think about it like that. I looked at it and said to myself "it looks like it's been 'packed' into hex somehow and so unpack should do the job." -- and then I started looking at the unpack documentation and concentrating on the format of the TEMPLATE. My point is the documentation doesn't make it clear that the pack function will handle the OP's case, at least it doesn't if you've literally never used pack. If I had to do that, I would have done the first thing I thought of, which is to split the string and loop over the elements, using hex to build the result. It would have worked fine, taken 30 seconds, and I'd have never bothered to think there might be a better way. That's part of the benefit of making topics for questions like this - now I'm aware of something I wasn't before, and it wasn't even my question.

8/6/2009 2:28:19 PM

Ernie
All American
45943 Posts
user info
edit post

I like how Chance always touts his ECE degree like it makes him the champion of Tech Talk or something. Dude always takes potshots at software and web dev people (I think he called it a war or something once) but he still can't find a job. I love this guy.

8/6/2009 8:40:42 PM

Fail Boat
Suspended
3567 Posts
user info
edit post

My ECE degree has nothing to do with this thread. The only reason it was mentioned is to point out that when those topics come up, I comment on them.

If similar guys rolled up in this thread doing stupid circuit shit, they'd get called out as well. Ask joenumbers how well his voltage regulator question he had for a candidate at a career fair once went when he posted it here. Quinn knows what I'm talking about.

And I think it's great how you guys keep talking shit about my job situation in the worst downturn in 70 years. The funny thing is, I'll be employed in another month or so again making more money than you software guys can sniff at.

8/6/2009 9:02:17 PM

Solinari
All American
16957 Posts
user info
edit post

This thread should've ended with the third post, when I pointed AstralEngine to the pack command.

dakota_man: its ok that you're not a perl guru. no one's judging you for it, and you shouldn't judge the language or the documentation for such a nitpicky thing. learning curves are learning curves.

chance: srsly?

8/6/2009 9:10:49 PM

Ernie
All American
45943 Posts
user info
edit post

Quote :
"The funny thing is, I'll be employed in another month or so again making more money than you software guys can sniff at."


Did you preemptively make a thread about purposefully dropping nearly unintelligible sentences or can I go ahead and call you out on this one?

8/6/2009 9:13:40 PM

Fail Boat
Suspended
3567 Posts
user info
edit post

He was already working with pack you stupid son of a bitch. Get the fuck out with your standard weak trolling you incompetent fuck.

^ I'm sorry you can't comprehend a perfectly understandable sentence.

[Edited on August 6, 2009 at 9:14 PM. Reason : .]

8/6/2009 9:13:58 PM

Ernie
All American
45943 Posts
user info
edit post

Oh, I get it, you're going to be making more money than me when you get a job "in a month or so."

Cool, you'll be needing to play some catch-up anyway.

8/6/2009 9:15:20 PM

Solinari
All American
16957 Posts
user info
edit post

yea, "in a month or so".... lol

good catch

8/6/2009 9:16:52 PM

Fail Boat
Suspended
3567 Posts
user info
edit post

No, my starting salary will be more than you're making now. The money I made in 2008 is more than you made. The money I make in 2010 will be more than you make.

It's the benefit of getting through the ECE curriculum.

8/6/2009 9:24:24 PM

Ernie
All American
45943 Posts
user info
edit post

Another benefit appears to be the transformation into a raging, money-grubbing douchebag.

[Edited on August 6, 2009 at 9:26 PM. Reason : and lololol at "will be"]

8/6/2009 9:25:52 PM

 Message Boards » Tech Talk » any Perl gurus out there? Page [1] 2 3, Next  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.39 - our disclaimer.