|
Voltaire posted:i have. Voltaire posted:im not even sure where to start with this one without using split and join. Oh, and if you're going to be in IT professionally, start reading this website daily, starting from now: http://thedailywtf.com And on another note: I think the intent of the exercise is to check if you're actually a Perl programmer or a C(++/#) programmer. Perl has some really powerful tools that C programmers often don't really know about and ignore, as it also has everything they're already used to. As such C programmers trying to do Perl often do more damage than a complete Perl newbie would do. Mithaldu fucked around with this message at 22:10 on Nov 9, 2008 |
# ? Nov 9, 2008 22:04 |
|
|
# ? May 21, 2024 14:02 |
|
What exactly do they forbid or allow? I ask out of curiosity; I'm not going to post a solution for you. The task is yours alone.
|
# ? Nov 9, 2008 22:05 |
|
Voltaire posted:I'm having difficulty writing a program that determines whether a 7 character input is a character. I am not allowed to use arrays, reverse, split, join; just basic perl functions. Here's a naive solution for it, purposefully done poorly: code:
|
# ? Nov 10, 2008 23:21 |
|
Im thinking on this one im not matching enough characterscode:
|
# ? Nov 11, 2008 03:36 |
|
I did it a lot shorter than that but I was going on your initial post of "7 characters"
|
# ? Nov 11, 2008 03:48 |
|
ashgromnies posted:&is_palindrome($str) You do know that & is no longer required on function calls right?
|
# ? Nov 11, 2008 04:27 |
|
Behold my palindrome test:code:
|
# ? Nov 11, 2008 12:03 |
|
heeen posted:Behold my palindrome test: errr... my shell posted:> ./pdrome.pl
|
# ? Nov 11, 2008 13:41 |
|
whoops forgot to add start and end markers to the regexp.code:
|
# ? Nov 11, 2008 15:12 |
|
Much better. Neat little algorithm that is!
|
# ? Nov 11, 2008 15:53 |
|
This seems more clear, but I guess it is probably slower:code:
leedo fucked around with this message at 21:27 on Nov 14, 2008 |
# ? Nov 14, 2008 21:15 |
|
Wow, using every function he was asked to not use, nice.
|
# ? Nov 14, 2008 21:26 |
|
leedo posted:$string eq join '', split //, reverse $string reverse in scalar context will reverse the characters in the string. So just $string eq reverse $string is enough.
|
# ? Nov 14, 2008 21:30 |
|
Whelp, i suck
|
# ? Nov 14, 2008 21:32 |
|
Now you suck a little less. We're all always learning. Don't sweat it.
|
# ? Nov 14, 2008 21:36 |
|
I typed this.code:
Fenderbender fucked around with this message at 22:12 on Nov 14, 2008 |
# ? Nov 14, 2008 22:10 |
|
Fenderbender posted:I typed this. I went with: code:
|
# ? Nov 15, 2008 06:40 |
|
Not a question, but something i just found out and thought i'd share: Ever tried iterating through a hash so you could do something each value in it? The usual solution is to do: code:
code:
|
# ? Nov 15, 2008 14:36 |
|
code:
|
# ? Nov 15, 2008 16:14 |
|
Am i doing something wrong or is map really slow?code:
|
# ? Nov 15, 2008 16:30 |
|
Mithaldu posted:Am i doing something wrong or is map really slow? Well yeah pretty much the latter. For starters, I think foreach is optimized to zip over temporary lists in a less eager fashion. map also needs to create a temporary list and then possibly copy it to @array, and the code block passed to it probably incurs some overhead being called every time compared to a foreach block. Whatever the cause I can say for certain map takes more memory (I just nearly killed my PC testing that) which means more copying is involved so its definitely slower.
|
# ? Nov 16, 2008 08:52 |
|
I have an incredibly basic Perl and IO stuff in general question. I have a database related app that takes about 4 minutes to run. While it does so, it some known variable values to the screen. I just ran this same program but told it to not print the messages and it took only 2 minutes. Nothing is different. The same variables are being collected. The only difference is I am not executing the print statements. What the heck? Does it really take half of the time to print my variables? I'm not sure how much data is sent to the screen during one submission, but I would guess 2MB at most.
|
# ? Nov 17, 2008 22:51 |
|
2MB @ 80 line length is about 25000 lines. 50000 lines at a more likely medium length of 40. Depending on your CPU, that can make a good bit of difference. Also important to think about is: What *exactly* is it printing? How much data does it have to pull from the memory per print? How many references does it have to resolve per variable? etc. etc.TiMBuS posted:map performance sucks
|
# ? Nov 17, 2008 23:04 |
|
Mithaldu posted:Thanks. That's the perfect answer i needed to never again bother with map at all. It's this sort of knee-jerk reaction I really despise among developers. Map isn't inferior to for in every regard and can provide some very special benefits. Thinking that performance is the end-all be-all of feature's usage is to not really understand either performance or the feature. So shame on you, etc.
|
# ? Nov 17, 2008 23:24 |
|
It's not a kneejerk reaction at all. For some reason i have serious problems wrapping my head around map and just plain reading it, as opposed to a for loop. My brain keeps expecting a comma or some parantheses. I also, to some extent, dislike the use of "magic variables" like $_ or functions that implicitly use it. As such, i have never seen map having any readability advantage for me at all. Additionally i have, over the last few years, never had any need to iterate over an array, do something simple enough to fit into one line with map and then retain it while creating a new array for the output. I have literally been looking for advantages of it over the past two weeks and aside from it being a different syntax (which is a disadvantage for me) i have found exactly none. It being slower than for only drives the nail in its coffin of uselessness for me. TL;DR: Don't jump to conclusions and accusations so quickly, eh?
|
# ? Nov 17, 2008 23:57 |
|
mister_gosh posted:What the heck? Does it really take half of the time to print my variables? Console I/O is extremely slow, and I am not at all surprised by the idea that dumping 2MB of data to the console might take two minutes to resolve. As an experiment, try running the same program with output redirected to a file or to /dev/null; if suppressing all output runs in t, I predict the former will clock in at t+5s and the latter will be almost exactly t.
|
# ? Nov 18, 2008 01:05 |
|
This code uses LWP to follow redirects. I will handle the redirects better in the future but does anyone know why I can't print out the location where the random link takes me?code:
|
# ? Nov 18, 2008 02:11 |
|
EVIR Gibson posted:This code uses LWP to follow redirects. I will handle the redirects better in the future but does anyone know why I can't print out the location where the random link takes me? Because the final response, which is what you're examining, was not a redirect, so it does not have a Location header. You probably want $res->request->uri, which should return the URI of the request that actually generated the final response.
|
# ? Nov 18, 2008 02:31 |
|
Mithaldu posted:I have literally been looking for advantages of it over the past two weeks and aside from it being a different syntax (which is a disadvantage for me) i have found exactly none. It being slower than for only drives the nail in its coffin of uselessness for me. It makes code a hell of a lot more readable ... code:
|
# ? Nov 18, 2008 15:18 |
|
fansipans posted:It makes code a hell of a lot more readable ... Edit: I think my problem is that i mentally translate every code i see into actual english sentences. That works very well for most constructs of Perl unless golfed. Map is impossible for me to translate into an english instruction. Mithaldu fucked around with this message at 15:45 on Nov 18, 2008 |
# ? Nov 18, 2008 15:32 |
|
Mithaldu posted:Not to me. Looks more like perl golf than anything else. That reminds me of learning Spanish back in High School. There were kids who did all their homework, memorized every word in the book, and got straight A's. But when it came time for spoken exams, you'd see their eyes roll up to the ceiling, and the words come out one at a time. Then there were a few kids that could flip a switch, and speak almost entirely in Spanish. They'd often have a few pet phrases that they'd incessantly discuss in a variety of situations. Mine was "vaca", the word for cow. "The cow has gone to the police station to complain about the loud children and their annoying cars", "The drunken cow sang a song using the broccoli as a microphone", etc. These kids would accidentally keep speaking Spanish when they left class. They might not remember the word for brakes on a car, but instead they'd just say "la machina para hacer parar" (the machine to make to stop) Both types of student could certainly survive if stranded in Madrid or Mexico City, but the latter would probably have much more fun
|
# ? Nov 18, 2008 16:13 |
|
I'm not entirely sure what you're trying to say with that, but honestly, I'd see myself as the latter kind of guy. When i read my Perl code it is really just *reading*, like one would usually do with a book. I see the code and effortlessly know the intent of the instruction. Certain things however just gently caress with that flow, so i work around them. It's not that i can't do it, it's just that they slow me down too much. I know what it does, but that reading seems entirely backwards to my mind. vvvv Mithaldu fucked around with this message at 17:17 on Nov 18, 2008 |
# ? Nov 18, 2008 16:44 |
|
It's funny, because for many people (myself included), the functional approach of map seems much easier to translate into english.code:
code:
|
# ? Nov 18, 2008 17:05 |
|
Mithaldu posted:It's not a kneejerk reaction at all. For some reason i have serious problems wrapping my head around map and just plain reading it, as opposed to a for loop. My brain keeps expecting a comma or some parantheses. I also, to some extent, dislike the use of "magic variables" like $_ or functions that implicitly use it. As such, i have never seen map having any readability advantage for me at all. No, he has a point. I know on lifevis you are concerned chiefly with optimizing the performance but its a big mistake to just decide you are never going to care to learn about functional programming. Even though I don't understand it particularly well, its helped me a lot on seeing problems in a new light If/when you really get the hang of map and lamba calculus a whole bunch of things will slide into place mentally and you'll start addressing a lot of problems in a new way. There could be bottlenecks in your lifevis code that would disappear if you formulated a functional solution, for example. The ability to not care about state and getting parallization for free easily make functional programming worth learning about.
|
# ? Nov 18, 2008 20:14 |
|
I didn't say anything about functional programming, just about map in the context of Perl. In fact, i have this on my "to read" list: http://gigamonkeys.com/book/
|
# ? Nov 18, 2008 20:25 |
|
Mithaldu posted:I didn't say anything about functional programming, just about map in the context of Perl. Oh, well ignore me then. I've noticed that Map is slow in python as well, at least compared to list comprehensions.
|
# ? Nov 18, 2008 20:34 |
|
I'm having a problem using a class I wrote in a different file (in the same folder). When I try to run 'nodeTest.pl' which just tries to call the class constructor which is contained in the class definition in 'WorkerNode.pm'.code:
Thanks in advance!
|
# ? Nov 19, 2008 01:00 |
|
Modules need to return a "true" value to indicate they loaded successfully. However, since the main body of code in a module isn't inside a function, you can't actually use a "return" statement, you need to place a statement at the end of the module that implicitly returns a true value. In short, add code:
|
# ? Nov 19, 2008 01:02 |
|
Mithaldu posted:In fact, i have this on my "to read" list: http://gigamonkeys.com/book/ Higher order perl by mjd is well worth a read too.
|
# ? Nov 19, 2008 01:06 |
|
|
# ? May 21, 2024 14:02 |
|
http://returnvalues.useperl.at/ 42 seems to be another commonly used one. Mario Incandenza fucked around with this message at 07:00 on Nov 19, 2008 |
# ? Nov 19, 2008 06:58 |