If you don't grok perl, you are pitiful

Message Bookmarked
Bookmark Removed
BEST PROGRAMMING LANGUAGE EVER

Jonathan Williams (ex machina), Friday, 8 November 2002 16:40 (twenty-three years ago)

Nerd.






















;-)

nathalie (nathalie), Friday, 8 November 2002 16:50 (twenty-three years ago)

bloated hack upon hack of AWK.

C and Assembly is the true way.

Mr Noodles (Mr Noodles), Friday, 8 November 2002 16:53 (twenty-three years ago)

Jonathan is right! and Perl 6 looks like it will be even nicer...
[if you get a chance to hear Damian Conway's Perl 6 talk, take it]

michael (michael), Friday, 8 November 2002 16:56 (twenty-three years ago)

Hahaha I shall haxx0r yr arse with my fabulous knowledge of FORTH! (and Atari ST BASIC => C *boingboing*)

Sarah (starry), Friday, 8 November 2002 17:14 (twenty-three years ago)

LET'S NOT FORGET ABOUT INTERCAL

Jonathan Williams (ex machina), Friday, 8 November 2002 17:17 (twenty-three years ago)

Forth is like programming... but on ACID!!! Ahahahahah doo yoo see?

Sarah (starry), Friday, 8 November 2002 17:19 (twenty-three years ago)

Forth rawks my booty! Anything that can run an observatory and be undocumented for a decade and have its own chips is down with me.

Mr Noodles (Mr Noodles), Friday, 8 November 2002 18:24 (twenty-three years ago)

also: COLOR FORTH.... !!!

Jonathan Williams (ex machina), Friday, 8 November 2002 18:29 (twenty-three years ago)

(cons 'LISP (cons 'is (cons 'the (cons 1 (cons 'true (cons 'language NIL))))))

Dan Perry (Dan Perry), Friday, 8 November 2002 19:00 (twenty-three years ago)

oh no functional programming, run while you can oh no

Mr Noodles (Mr Noodles), Friday, 8 November 2002 19:29 (twenty-three years ago)

OCAML!!!!

Jonathan Williams (ex machina), Friday, 8 November 2002 19:38 (twenty-three years ago)

Pah. BRAINFUCK PWNZ ALL J00 LAM0RZ!!!!!!1

(I wrote a quine once for a programming assignment, I sweated blood over getting it to be exact char-for-char and was very proud of it, and then the tutor went, "What is this gibberish? You were only supposed to call your source code 'bla' and get it to cat the file 'bla', you idiot." I don't know if he realised that it did actually display its own source code as the question requested, I suspect he thought it was just a mass of random junk. Weep.)

ANYWAY, I am getting really smug and proud about being pitiful clueless dozeluser now, it might mean that nobody will give me a job and it might be crushing to admit that not only am I too nerdy to integrate into normal society but that I am entirely shit at the only thing I ever thought I might be any good at and no geeks want to know me either (and most of them are better with Real People too), but at least I'm not as tiresomely sanctimonious as some of the rabid linux advocates I've had to endure bitching through their 1337th conversation of the day about IP ranges, car engines or how k-rad they are for getting linux to run on a really shit old computer but how they really need to buy the newest shiniest most expensive gadgets out there anyway.

Although - on the strength of this post alone and in general too - I am pretty damn tiresomely sanctimonious and bitchy and I'm getting worse every day so, uh, please, please, someone kill me soon. (Yes, indie sceeeenes make me feel the same way too; no, quoting records on Teenbeat doesn't mean that any of them want anything to do with me either, and I can't even go, "oh well, they're all beardy and scary loners so NER," because, well, they aren't, but look at me. No, don't, it makes me nervous. Shyly coy and nervous, get in the sli*BANG* *innards spray everywhere*)

Rebecca, mixing like a monkey, don't be coy and jumpy (reb), Friday, 8 November 2002 20:06 (twenty-three years ago)

Proper quining is tricksome and cool, damn yr tutor (unless it was Geraint (who I really think should be on ILE sometimes)(but not talking about Ruby))

Perl is all very well at what it does, but is such an ugly, nasty kludge it makes Fortran 77 look like a sensibly designed language in comparison. Haskell smacks down ML variants in any fite ever as well(if I'm refereeing anyhow)

RickyT (RickyT), Friday, 8 November 2002 23:40 (twenty-three years ago)

R33|_ |-|/-\X0RZ J00Z J00n!KS, Y0!@#!@#

R3PR4Z3|\|T.

PS J0R /-\LL 0\/\/|\|3|)

N0RM4N PH4Y, Friday, 8 November 2002 23:58 (twenty-three years ago)

PPS R3B3((/-\ = TEH L33T35T, obv.

N0RM4N PH4Y, Saturday, 9 November 2002 00:00 (twenty-three years ago)

BTW Ricky, "Geraint" wouldn't be the one from Swansea by any chance?

N0RM4N PH4Y, Saturday, 9 November 2002 00:02 (twenty-three years ago)

Nah, I liked that tutor, and I probably did misunderstand the question (I mean, I'll happily defend my reading as a valid interpretation, but not the one the question writer intended or one that anyone else doing the paper followed without doing it the simpler way too). Think he left before you got there though.

I often think of *xn*tters who might enjoy Ask A Drunk (I assume M Morris, whose return I was pleased to see, has been on both), and I was tempted to link from the euphemisms thread to the f*ce p*jama page, but then I remembered how scared I'd be if anyone of the people I was thinking of actually did turn up.

I will not be ontopic, dammit. Otherwise I will remember either that there's a very simple perl script that I should've done months ago and haven't and now I can't remember all the very basic perl I learnt last time or how much I hate my ex and his perl t-shirts and the fact he's probably infinitely happier than I am at any given moment. [Talking of obfuscated languages, someone needs to write a syntax-highlighting either-or matcher for my posts, they must be unreadable.]

(Though I have been quoted on perl mailing lists, hahaha. But unsurprisingly not for perl gurudom, just an offhand moment of angst that bizarrely and embarrassingly ended up in a proper perl guru's sig.)

Rebecca (reb), Saturday, 9 November 2002 00:20 (twenty-three years ago)

PS thxX0rz |<-\/\/R4D! PWNAGE!!!

PH34R TEH N0RM4N SK!LLZ... PH4Y R0X0RZ J00R PUNY B0X3N, F3WLIOZ~$%^*)~

Erm, yes. Where was I? w00t, an' all that.

Rebecca (reb), Saturday, 9 November 2002 00:27 (twenty-three years ago)

Erm, isn't every third person from Swansea called Geraint?

RickyT (RickyT), Saturday, 9 November 2002 01:09 (twenty-three years ago)

I haven't played with it in a few years, but LINC machine language is fun.

Dave Fischer, Saturday, 9 November 2002 01:24 (twenty-three years ago)

Gah, sorry Norman, drunken arsiness.This is the Geraint I was talking about, though his own particular wonderfulness is not readily apparent from those pages (*this might be a lie if you speak welsh).

R, I know what you mean about *xn*tt*rs and FAD. I'd be verrrry worried about any of the pedant mob turning up here, even if a C*l*n B*tch*l*r versus combined mass of ILX intellect might be v.funny.

RickyT (RickyT), Saturday, 9 November 2002 01:38 (twenty-three years ago)

I grok Perl, but it's a piece of shit. If you're after a nice interpreted scripting language, choose PHP. Is nice!

As for "the greatest", well, I do like C. I'm not too familiar with x86 Assembler, but 6800 assembler is pretty nice. (I wrote a Nintendo game with it once) Whoever said Haskell is good in any way should perish in a firey inferno. I'm a firm believer that you're only pitiful if you can't pick up whatever language you need to do the job.

Rebecca, knowing that you're a) female, b) able to code, and c) able to code in Brainfuck, makes you extremely attractive. To me at least. God, I suck.

Andrew (enneff), Saturday, 9 November 2002 02:13 (twenty-three years ago)

What's wrong with Haskell then? (geek fite here we come)

RickyT (RickyT), Saturday, 9 November 2002 02:28 (twenty-three years ago)

It is completely, utterly retarded. Practical applications? I can't think of a single algorithm that, implemented in Haskell, would be at least 10 times as slow as it's C equivalent. Even doing simple things require recursive functions (bye bye stack space), which if done imperitively would use a fraction of the memory to perform.

Not only that, but you have to do mental hurdles to put yourself into the 'Haskell Mindset' - procedural/imperitive/oo languages more closely mirror my mental process.

Andrew (enneff), Saturday, 9 November 2002 03:26 (twenty-three years ago)

I can't code much at all, let alone Brainfuck, though I did play with it once. That's why all the RAGE. Er, the fact that I can't code, not that Brainfuck has left permanent psychological damage, although maybe, just maybe... (always looking for something to blame)

Somehow I suspect "occasionally taking about 300 times longer than should be necessarily to kludge together broken Visual Basic and running in fear from real languages" doesn't sound very attractive at all. In fact, I have yet to think of anything about me that does. But why do I correct people who'll never meet me anyway? Ahem. YES I am the world's greatest and not a feeble braindead dropout who can't get a job at all. I am also stunningly beautiful and fascinating and fun to be around, which is why my entire life consists solely of sitting around all alone boring people to death on the internet. Mmm CATCH.

Rebecca (reb), Saturday, 9 November 2002 03:32 (twenty-three years ago)

does grok = love and if so, why when and who

ron (ron), Saturday, 9 November 2002 03:35 (twenty-three years ago)

grok = Heinlein. perl = zzz. HTH HAND AARDVARK etc.

Rebecca (reb), Saturday, 9 November 2002 03:45 (twenty-three years ago)

Okay, so you're a hideous troll. Fair enough.

'grok' means 'understand', basically.

Andrew (enneff), Saturday, 9 November 2002 04:44 (twenty-three years ago)

why don't you fucktards go and show your dicks to the footie players down the road - they used to do shit like this.

Queen G (Queeng), Saturday, 9 November 2002 10:02 (twenty-three years ago)

Rebecca in actually being just like the real people she fears SHOCKAH!

I am also stunningly beautiful and fascinating and fun to be around

At least two of these are true.

Graham (graham), Saturday, 9 November 2002 15:04 (twenty-three years ago)

stop it yr all making me jealous!

why can't i be a master programming genius? why why why why why???

sand.y, Saturday, 9 November 2002 21:29 (twenty-three years ago)

Ah, the little tin god of efficiency. If you feel that strongly about it you can always go and code in assembler or Fortran. I love Haskell because once I got over the initial bump of having to think in a non-procedural way it fitted my thought processes much better and enabled me to write code that was both much clearer and much more concise. First class functions, lazy evaluation and total referential transparency are really, really powerful, not to mention the sheer niceness of static type inference and argument pattern matching.

RickyT (RickyT), Saturday, 9 November 2002 22:44 (twenty-three years ago)

Any attempt to make programming sound cool is doomed to failure. Some people now call themselves 'code poets', and you can buy 'code poet' t-shirts. Might as well have "I AM A WANKER" tattooed across your forehead.

(For those who don't already know: programming is a significant part of my job, too, but I am not fool enough to think it makes me cool.)

Martin Skidmore (Martin Skidmore), Saturday, 9 November 2002 23:17 (twenty-three years ago)

"Ah, the little tin god of efficiency. If you feel that strongly about it you can always go and code in assembler or Fortran."

Sod off. If ilxor was written in Haskell, the server would have keeled over and died a long, long time ago. The efficiency benefits of Assembler over C are quite small, whereas those of C over Haskell are massive. Just out of interest, what do you actually use Haskell for?

Andrew (enneff), Sunday, 10 November 2002 02:00 (twenty-three years ago)

I used to grok Psion OPL but have surely forgotten all of i by now (grey level graphics window, I still love you and I want to get in touch again. Do you?), but currently all I'd claim to grok is ilXor PHP.

Graham (graham), Sunday, 10 November 2002 20:58 (twenty-three years ago)

Mmm Fortran. I am better at old skool programming than the lot of you and with my ATARI ST BASIC TO C book I shall soon be an unemployed programmer like the lot of you. I have the lingo down.

"Bloody build processes!"

er

"I really think I am being underpaid!"

"ERROR REDO FROM START!"

Back to the photocopying then.

Sarah (starry), Monday, 11 November 2002 10:31 (twenty-three years ago)

two years pass...
okay, i wanna learn this shit. i got a coupla books from the library, but i need some sorta way to learn this in windoze.

kingfish maximum overdrunk (Kingfish), Wednesday, 18 May 2005 04:04 (twenty years ago)

windoze perl = get an account somewhere on a unix/linux box that you can ssh to, or install Active State. Best way to learn is probably to think up a hoonja something you want to make & go write it.

lyra (lyra), Wednesday, 18 May 2005 04:24 (twenty years ago)

okay, i've found ActiveState...

kingfish maximum overdrunk (Kingfish), Wednesday, 18 May 2005 04:29 (twenty years ago)

Get one camel book.

Ed (dali), Wednesday, 18 May 2005 05:03 (twenty years ago)

yeah, but i need shell access. i haven't had a university account in two years.

kingfish maximum overdrunk (Kingfish), Wednesday, 18 May 2005 05:22 (twenty years ago)

man perl is good tho too. (of course, when i say that, there are like many chapters to it, so i don't mean just that one main man page.)

m.

msp (mspa), Wednesday, 18 May 2005 05:22 (twenty years ago)

> yeah, but i need shell access

not if you have active state installed, you can just run it locally. i learnt perl on my win98 box. (or doesn't windows come with a command line anymore?).

(i'd install cygwin so at least you don't have to suffer the dos command line)(i'd also learn php rather than perl, you still have all the associative arrays and stuff but the syntax is easier)(the other big problem that i've seen people have with all this stuff is knowing how to edit files (using text editor, not some wysiwysg thing) and where the files actually are (because windows abstracts this too much, encourages you to stick them all on the same disk as the operating system = madness))

koogs (koogs), Wednesday, 18 May 2005 06:59 (twenty years ago)

XEMACS. I'm pretty sure that there is a windows version around somewhere.

If you really want a shell account and don't want to set up and administer a linux box yourself (not too hard, but securing it at the start can be a bitch), I'll recommend itshosted.com -they provide web hosting space, but you can get ssh access to it and goof around. The big advantage then is that they have to worry about all the security patches, not you.

lyra (lyra), Wednesday, 18 May 2005 13:23 (twenty years ago)

a shell account:
http://www.freeshell.org/

cygwin + active state perl are a bit iffy together if i recall. path issues perhaps? active state perl wanting windows paths and cygwin bash wanting *nix style paths. use google and double check before you pull your hair out. if i'm on my xp box, i usually just use the dos command line. it sucks, yes, but sometimes you do what you have to do. i run fedora on another machine, but it's cumbersome sometimes to have to use remote tools, etc. (yeah yeah yeah, i know there are a gajillion work arounds like samba+ssh... if i spent more time hackin perl i might care.)

my personal top 5 favorite (aka most used) perl things to know:
1. regular expressions and those sed/awk like operators
2. hashes and lists and combinations of those two things (LoL and HoL and LoH, etc etc)
3. split/join/string manip functions
4. HEREDOCUMENTS
5. pushpopshiftunshiftsplice array manip fuctions

i use all of those things in almost every perl script i write.
m.

msp (mspa), Wednesday, 18 May 2005 13:50 (twenty years ago)

I hate here-documents.

Doesn't cygwin come with its own version of Perl anyway? It's probably not in the default install, but I think it's in there somewhere.

caitlin (caitlin), Wednesday, 18 May 2005 14:12 (twenty years ago)

yeah... it's non-default, but it's there.

the only reason i like here docs is that if you've got extensive text to output, it's so much more trivial than a ton of prints, so much more efficient than string building, etc etc.

but yeah, probably the biggest source of errors ever.

i'm curious tho, any suggestions for handy ways not to use here docs? if there's a wiser solution, please share.
m.

msp (mspa), Wednesday, 18 May 2005 14:25 (twenty years ago)

I love the title of this thread! It makes me feel like I am maybe not pitiful to ELITE FOLX (although obv this isn't actually true as my perl is limited to sorta cutesy amateur stff)

Gravel Puzzleworth (Gregory Henry), Wednesday, 18 May 2005 14:28 (twenty years ago)

To be honest, I don't think I ever write anything that has extensive blocks of static-ish text to print out. When I have done, I've used here-docs.

The main reason I don't like them, I guess, is that they mess up the auto-formatting in Emacs Perl mode. See also: output formats (which I've generally found more useful, but have the same problem).

caitlin (caitlin), Wednesday, 18 May 2005 14:28 (twenty years ago)

but what MEANING does assigning an array to an int have

Assigning an array to an int: not useful.

Assinging an array to a pointer: very useful.

(YES I KNOW INT[] IS ACTUALLY INT*)

Stop talking crap then.

Forest Pines (ForestPines), Thursday, 21 July 2005 06:30 (twenty years ago)

i've always preferred $#array. or foreach to avoid the array length where applicable.

I'm trying to stop using $#array for two reasons:

a) I can never remember which is less, $#array or scalar @array. Just dealing with one will make life easier.

b) I'm trying *now* to stop using syntax that's not in Perl6. $#array is going.

Well what else would it do? How can you convert an array to a scalar?

Returning the number of elements seems obvious with hindsight. It's not, though. Why should scalar @array return the length and not the highest valid index like $#array does? If you're coming from C/C++, returning an array reference would be the obvious implementation. For that matter, why shouldn't scalar @array do the same as scalar %hash?

Forest Pines (ForestPines), Thursday, 21 July 2005 06:34 (twenty years ago)

> Should I bother to learn C? As someone who mostly just dabbles in programming, using Perl for web apps, but who wouldn't mind making simple apps for the Mac. And who is generally interested in learning such languages.

C is good for learning more how a computer does things, like they said, it's little more than a bunch of functions on top of assembler. that said, sometimes you don't need to know how a computer does things. which is why its less fashionable these days (and why i see a lot of people brought up on java having trouble with, say, bitwise operators). C's lack of standard stuff like hashes and vectors annoys me though (although gnu libraries help)

if you know perl but want to write 'applications' then have a look at tk/tcl which basically lets you get stuff on screen (windows, file choosers etc) and has a perl binding. failing that i'd say java (which is transferable to other machines) or objective c. (is glade available on mac?)

koogs (koogs), Thursday, 21 July 2005 07:36 (twenty years ago)

I've written things using perl/tk and hated it. It's easy to do, but the results look nasty (to my eyes).

is glade available on mac?

Probably, but I wouldn't like to say so for sure. Given that GTK works and libxml (presumably) works, I don't see why not.

Forest Pines (ForestPines), Thursday, 21 July 2005 07:43 (twenty years ago)

http://www.monodevelop.com/images/screenshots/macosx.jpg

mono / gtk# / glade on a mac

koogs (koogs), Thursday, 21 July 2005 09:43 (twenty years ago)

i see a lot of people brought up on java having trouble with, say, bitwise operators

Rule #1 of good coding: don'to optimize (yet)

The compiler knows enough to turn mult and div by powers of two into bits shifts.

(Yes I know there are other reasons to use them, but I see this all the time.)

OLD SPICE® CHEMTRAILS!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ex machina), Thursday, 21 July 2005 10:48 (twenty years ago)

Ugh, no native GTK+ yet? Fucking X11!

OLD SPICE® CHEMTRAILS!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ex machina), Thursday, 21 July 2005 10:49 (twenty years ago)

does anybody know, is there performance bonuses to relying on fun stuff like $_ and so on? i could see a little less namespace clutter equaling less memory... less to parse = quicker... shorter, smaller, etc... but i wonder if there's any significant difference between the processing times of two different programmers essentially writing the same code... explicit vs. implicit...

I'll put it this way- if you care about that infimestimal speed difference, you're on the wrong language. Even mod_perl is slow as all get out. When you need things super fast, go use C. But when you're writing web apps, you can get away with perl, because the slowness of using perl is tiny compared to the time to make the http requests. If you're using a mod_perl server on a well tuned apache web server, you'll be fast enough in comparison to the time to travel over the network.

don't you mean:
die "sorry sucker i died on you";

Not really- I use eval when I suspect something might die on me, but I don't want the whole webpage/perl script to be taken down by it. So I'd throw a warning that something isn't available and then carry on. There's not too much of a point in catching dies in evals and then dying yourself right after- even if you want a custom _DIE_ handler, you can just overload that directly & save yourself the trouble of eval'ing.

lyra (lyra), Thursday, 21 July 2005 14:38 (twenty years ago)

s/infimestimal/infinitesimal/;
$self->pour_another_cup(what=>'coffee');

lyra (lyra), Thursday, 21 July 2005 14:40 (twenty years ago)

Lyra, you really overestimate the performance benefits of C. Java performs nearly as fast for scientific computing. No one does CPU grinding applications in Perl.

OLD SPICE® CHEMTRAILS!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ex machina), Thursday, 21 July 2005 14:51 (twenty years ago)

Lyra, you really overestimate the performance benefits of C. Java performs nearly as fast for scientific computing. No one does CPU grinding applications in Perl. My point wasn't that Perl was fast though, just explaining the mechanics of how it worked.

OLD SPICE® CHEMTRAILS!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ex machina), Thursday, 21 July 2005 14:52 (twenty years ago)

My speed comment about not worrying about variables in perl was actually directed at msp, who asked the question. Anyway, I should note that I'm SO not a C/C++/Java programmer, I mentally lump them all together as 'those languages that I only know enough of to hack together a few line fixes in every so often'.

lyra (lyra), Thursday, 21 July 2005 15:04 (twenty years ago)

In a lot of cases, it is cheaper to buy more hardware than pay someone to make C code run faster.

OLD SPICE® CHEMTRAILS!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ex machina), Thursday, 21 July 2005 15:11 (twenty years ago)

two weeks pass...
Jon, isn't Perl itself written in C?

k/l (Ken L), Wednesday, 10 August 2005 17:16 (twenty years ago)

Yes, it is.

Perl5 is in C, at least. Perl6 might be in C++; I'm not 100% sure on that.

Forest Pines (ForestPines), Wednesday, 10 August 2005 17:18 (twenty years ago)

The first public usable implementation of Perl 6 is written in Haskell. Yes, that Haskell, as discussed several miles up this very thread. No, I know, but it really is (well, ok, it really exists, my exact description may be inaccurate). Still a work in progress, but then I don't think the design of Perl 6 itself is completely agreed upon yet.

Apparently it's sparked a lot of interest in Haskell. Just thinking about it breaks my brain a little, since I thought of a number-crunching mini-task to throw together in Hugs recently, until after 20 minutes and much garbage collection and not very many iterations I decided to do it in perl, which gave me an answer in a split second. My fault for not thinking about efficiency, sure, but... well, ouch.

Oh yeah, the more official perl 6 development work is on the Parrot project, which I think is still written in C, but it's at this point that I stop even being able to pretend I know what I'm talking about, and I only wanted to mention the Haskell thing to amuse and horrify the people here who've used it.

Rebecca (reb), Wednesday, 10 August 2005 20:23 (twenty years ago)

Uh-oh, that sent a trackback ping to perl.com. I probably didn't want to do that. Sorry. [looks around nervously]

Rebecca (reb), Wednesday, 10 August 2005 20:27 (twenty years ago)

eight months pass...
I don't grok perl :(

What is the difference between:
($thing) = @_
and
$thing = @_ ?

Gravel Puzzleworth (Gregory Henry), Saturday, 15 April 2006 19:41 (nineteen years ago)

#1 is assigning to a list of a single element. that element is $thing
#2 is assigning to a list named $thing

Fight the Real Enemy -- Tasti D-Lite (ex machina), Saturday, 15 April 2006 19:51 (nineteen years ago)

I think I understand! Is #1 ever useful?

Gravel Puzzleworth (Gregory Henry), Saturday, 15 April 2006 19:56 (nineteen years ago)

Wait ignore that! I get it now. Thanks Jon!

Gravel Puzzleworth (Gregory Henry), Saturday, 15 April 2006 19:59 (nineteen years ago)

We were playing around with a computer yesterday, and the manual warned
about subtle grounding problems during programming. THAT'S low-level
programming.
(Yea analog computers!)

shieldforyoureyes, Sunday, 16 April 2006 12:37 (nineteen years ago)

#1 is assigning to a list of a single element. that element is $thing
#2 is assigning to a list named $thing

You have #1 right, but a clearer answer would be: it behaves the same as $thing = $_[0]

#2 is wrong; $thing isn't a list. It assigns the length of @_ to $thing, because the left-hand side puts the expression into scalar context. You're thinking of $thing = \@_

Forest Pines (ForestPines), Sunday, 16 April 2006 13:56 (nineteen years ago)

(I assume, thinking about it, this must be from an exercise to demonstrate the difference between list context and scalar context. In #1, the left hand side is a list, therefore the right hand side is in list context; you get the contents of the array. In #2, the left hand side is a scalar, so the right hand side is in scalar context; you get the length of the array)

Forest Pines (ForestPines), Sunday, 16 April 2006 13:59 (nineteen years ago)

is this one of the earliest jw posts on ILE?

the unbearable lightness of peeing (orion), Sunday, 16 April 2006 16:22 (nineteen years ago)

Thank you, FP. For a second I thought I was crazy.

Casuistry (Chris P), Sunday, 16 April 2006 16:58 (nineteen years ago)

Perl: if you think it's ungrokable now, just you wait!

http://www.ozonehouse.com/mark/blog/code/PeriodicTable.png

mikef (mfleming), Sunday, 16 April 2006 17:21 (nineteen years ago)

FP's answer helped me, too, thanks!

Another question: how clever is perl about $_? Like, if I have an implicit for loop, and I call a sub from it, presumably the sub can't have anything that alters $_ in it, such as another implicit for loop?

Gravel Puzzleworth (Gregory Henry), Sunday, 23 April 2006 18:17 (nineteen years ago)

but doesn't passing parameters to a sub already alter $_? Or at least @_?

Gravel Puzzleworth (Gregory Henry), Sunday, 23 April 2006 18:27 (nineteen years ago)

Passing parameters only alters @_, not $_

As to the first question: yes, you can, in that case. This is because foreach loops are special (I assume you meant foreach rather than for, because for doesn't use implicit $_) in that the iterator returns to its previous value after the loop is finally exited.

Forest Pines (ForestPines), Sunday, 23 April 2006 18:46 (nineteen years ago)

this is still one of my favorite thread titles ever.

Tracey Hand (tracerhand), Sunday, 23 April 2006 18:51 (nineteen years ago)

(sorry, I forgot that for and foreach are really the same thing - so you could be talking about either. I prefer to use 'for' for loops with C-style control expressions and 'foreach' for ones with iterator variables. Another thing that might be relevant here is that if you call a sub from within a foreach, the iterator is accessable within the sub, but not modifiable.)

Forest Pines (ForestPines), Sunday, 23 April 2006 18:51 (nineteen years ago)

FP's answer helped me, too, thanks!

Another question: how clever is perl about $_? Like, if I have an implicit for loop, and I call a sub from it, presumably the sub can't have anything that alters $_ in it, such as another implicit for loop?

-- Gravel Puzzleworth (mostlyconnec...), April 23rd, 2006 8:17 PM. (Gregory Henry) (later)

but doesn't passing parameters to a sub already alter $_? Or at least @_?

-- Gravel Puzzleworth (mostlyconnec...), April 23rd, 2006 8:27 PM. (Gregory Henry) (later)

Passing parameters only alters @_, not $_

As to the first question: yes, you can, in that case. This is because foreach loops are special (I assume you meant foreach rather than for, because for doesn't use implicit $_) in that the iterator returns to its previous value after the loop is finally exited.

-- Forest Pines (il...), April 23rd, 2006 8:46 PM. (ForestPines) (later)


You're just playing a geekx0r version of Mornington Crescent, aren't you.

Markelby (Mark C), Sunday, 23 April 2006 20:01 (nineteen years ago)

Hahahaha!

It could be worse - Perl really does have some bizarre hidden corners.

Forest Pines (ForestPines), Sunday, 23 April 2006 20:06 (nineteen years ago)

roffle @ usage of "grok"

jinx hijinks (sanskrit), Sunday, 23 April 2006 20:34 (nineteen years ago)

ooh i got soned.... I am usually more clear with array lengths... I must have been using php too often

JW (ex machina), Monday, 24 April 2006 03:12 (nineteen years ago)

one year passes...

I'm guessing this should be simple for someone who actually knows perl (i.e. not me): I'm trying to search a string like this:

blah blahblahblah blahblah 1.1&1.8&2.5&3.3blah blah

for every occurrence of a number dot number (more specifically, /[1-9]\.\d/ because 1.8 should be the smallest return), and then to put that $& into an array. But I'm only using =~ so that only the first occurrence gets returned. Anybody help please?

Leee, Thursday, 12 July 2007 21:37 (eighteen years ago)

end your regexp with /g for all matches

http://perl.active-venture.com/pod/perlretut-usingregexp.html

alternatively split on & then check each of the results?

koogs, Friday, 13 July 2007 10:37 (eighteen years ago)

Smalltalk 4evah!

anatol_merklich, Friday, 13 July 2007 11:02 (eighteen years ago)

two months pass...

New question. I've built a database of documents that includes past versions, e.g.:

Doc001 document description V0.1

Doc001 document description V0.2
Doc001 document description V1.0
Doc002 document description V0.1

(Tab-delimited.)

However, I sort each line in the list as a string, so when the document description changes, it can alter the order of the documents like so:

Doc001 dacument description V1.0

Doc001 document description V0.1
Doc001 document description V0.2

Do I need a hash? I'm not very good with those.

Leee, Tuesday, 2 October 2007 23:48 (eighteen years ago)

It's not so much that you need a hash as that you need a data structure of some sort. And yes, in Perl, hashes are pretty much the the data structure, especially when dealing with string and numerical data. You'll probably need a few foreach() loops to unwind the data in preferred order, coupled with sort, and so on.

If you have a huge amount of data, then the right thing to do is probably to ASCII-encode the data with fixed-length fields so that the sort order corresponds with ASCII order.

libcrypt, Wednesday, 3 October 2007 00:18 (eighteen years ago)

six months pass...

OK this one hopefully has a quick and easy answer.

I have a hash of arrays of hashes, e.g. a bunch of data of a bunch of people. The first classifying criteria is gender. Each gender is an array of entries, with each entry including multiple key/value pairs (female #124: height, weight, bust size, etc.). How do I figure out how many women and how men are in the list -- without using loops?

Leee, Wednesday, 30 April 2008 20:35 (seventeen years ago)

Use loops. This ain't no relational data structure, dude.

libcrypt, Wednesday, 30 April 2008 20:55 (seventeen years ago)

$count = scalar keys %hash;

f. hazel, Wednesday, 30 April 2008 21:11 (seventeen years ago)

I kind of hate sigils in Perl. Ruby's sigil's as explicit scoping is better imo

Catsupppppppppppppp dude 茄蕃, Wednesday, 30 April 2008 21:22 (seventeen years ago)

Hm, I forgot about the scalar function and am now wondering if it's bad form to throw in an explicit call to scalar to stop future generations scratching their heads at a particularly inscrutable (to the non-perl-grokker like the coworker most likely to need to change the script in a hurry) implicit forcing of scalar context.

(Or I could just write two lines of comments, or turn 1 line of code into 3 with needless intermediate variable)

a passing spacecadet, Wednesday, 30 April 2008 21:46 (seventeen years ago)

six months pass...

Hi again. I'm parsing a text file for certain keywords (let's call them "alpha," "beta", "gamma"), and for convenience sake, I use a local hash to hold those parameters. (E.g. $hash{alpha} = some value.) I want all of these parameters to be defined before I return from the subroutine, so I have

while ( !(defined $hash{alpha}) or !(defined $hash{beta}) or !(defined $hash{gamma}))

But now, depending on certain conditions, I might want to look for additional keywords (e.g. "delta", "epsilon"). Assuming I initialize all these keys to undef before I enter the loop, is there an expression I can use for the while condition that basically sez "Keep looping until all existing keys are defined"?

Leee, Tuesday, 25 November 2008 23:28 (seventeen years ago)

http://pastie.org/324034

J0hn D., Tuesday, 25 November 2008 23:46 (seventeen years ago)

Actually figured it out myself; I stored the scalar of the keys in a $num_keys, then

while (scalar grep { defined $hash{$_} } @keys < $num_keys)

Leee, Wednesday, 26 November 2008 04:04 (seventeen years ago)

one year passes...

New one: I'm trying to write my own Mysql module that extends DBI and DBD::mysql. My custom connect() method works fine, but when I try to write a query() method that takes care of both methods in DBD::mysql -- e.g. prepare() and execute() -- I get a compiler error saying that it can't find the prepare method. Is there something weird going on with DBD::mysql that makes it more involved to extend?

Daleks in NYC (Leee), Tuesday, 15 June 2010 22:43 (fifteen years ago)


You must be logged in to post. Please either login here, or if you are not registered, you may register here.