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)

It does seem to take awhile to get the bracketing straight.

Ken L (Ken L), Wednesday, 18 May 2005 14:31 (twenty years ago)

here docs is definitely annoying on the auto-formatting stuff. i'll have to check out output formats. kind of avoided it. "there's more than one way to do it." = one of the biggest reasons i've always liked perl. want to vs. have to.

m.

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

Get one Camel book and get one Mac.

Casuistry (Chris P), Wednesday, 18 May 2005 15:44 (twenty years ago)

"Grok" may be the stupidest word ever.

jaymc (jaymc), Wednesday, 18 May 2005 15:45 (twenty years ago)

i like heinlein... but yeah, i probably am not "at one with" perl. i actually had to look it up. i am the art of pretend programming.
m.

msp (mspa), Wednesday, 18 May 2005 16:08 (twenty years ago)

pfff perl is sooooo 1997 get one book on css and javascript. javascript sucks, but director and flash mx 2k4 use an embedded version of it called actionscript which has finally subsumed javascript and integrated it with its internals a lot better.. director with plugins and libs is more the futurewave.

</fucking hipster programmer elite, and this "l33t" garbage is for children. shuh>

donut fucking programming hipsterfuck (donut), Wednesday, 18 May 2005 16:19 (twenty years ago)

er, who said anything about writing web pages? some of us actually use perl for reports and file munging.

koogs (koogs), Wednesday, 18 May 2005 16:23 (twenty years ago)

OK, to seriously be helpful here, in the context of web development...

Perl is great to learn, and it won't be waste of time ever, but as far as conventional web jobs go, not too many of them use Perl heavily on a regular basis. There are major exceptions.. Amazon.com for instance. If Perl is used in anything at this point, it's mainly with PHP/MySQL stuff.. and even then, programming language marriage last as long as human marriages do i.e. not too long.

I do actually recommend at least a cursory book on Javascript and a book on CSS, as both of those get used heavily in web development these days (if the goal is to get a web development job). Just keep in mind that every permutation of browser X platform is going to behave different for each basic use of CSS or Javascript.. The O'Reilly books do a pretty good job at keeping up to date with these little gotchas, if you always get the latest edition of these books.

But those gotchas are not going to go away anytime soon, so get used to them. Knowing the gotchas is more than half the battle, in many cases.

Also, some cursory book on XML would be helpful.. or even just a good XML tutorial. It's becoming used in almost every application, no matter how vague the purpose. It's also easy as fuck to learn if you already know HTML (which, retrogressively, is an instance of XML anyway)

Sure, there is ASP, PHP, etc. but I think these are best referred to online than being purchased, as learning the above will prepare you to learn these guys pretty damn quickly.

Actually, if you enjoy programming languages, you'll find almost any web programming language easy.

Getting into a career of tech development, my recommendation is to take courses in C++... NOT C#, C++. It's VERY important to learn what pointers are. People are graduating from Comp Sci programs without knowing what a pointer is.. this is a problem for this specific career path, IMHO.

er, who said anything about writing web pages? some of us actually use perl for reports and file munging.

You're absolutely correct. However, given that Perl is great for manipulating/evaluating text and regular expressions, and given that the standard for web programming are text based atoms, Perl is often said in the same breath as web programming.

donut debonair (donut), Wednesday, 18 May 2005 16:28 (twenty years ago)

yeah, depends on what you want to do. javascript can be massively useless.
m.

msp (mspa), Wednesday, 18 May 2005 16:29 (twenty years ago)

It can be massively useful, too! It's a humongous language which allows 20 different ways to do the same thing, but there's only ever one really awkward way to do that thing if you want it to work on all browsers on all platforms... if you're lucky.

donut debonair (donut), Wednesday, 18 May 2005 16:33 (twenty years ago)

agreed. and in the context of web dev, javascript probably is more important, cause there are several server side languages. yet you really wouldn't want to use vbscript or anything else client side.

perl just has wide ranging abilities and in *nix land, i'd rather use perl over c, c++, and java. (well, depends on the app i guess.) but for many things, perl just gets you much farther, much faster.

i find it hard to believe comp sci grads aren't learning about pointers. that's a crime. even tho i've barely ever used one in my professional career, that's still a level of ignorance about how things work below that seems shameful. everybody should have to slave through at least one semester of assembly language and/or C/C++. if not more than one semester!
m.

msp (mspa), Wednesday, 18 May 2005 16:40 (twenty years ago)

i'll have to check out output formats

The obvious use of output formats is to format plain-text tables, but you can use them for other things to. The first thing that comes to mind out of what I've done with them myself: producing invoice emails.

er, who said anything about writing web pages? some of us actually use perl for reports and file munging.

The most recent sizeable thing I've been doing with Perl has been all about Win32::OLE - reading data from a Lotus Notes database and creating an Excel workbook containing reports on the data.

caitlin (caitlin), Wednesday, 18 May 2005 17:56 (twenty years ago)

mmmmm MASON.

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.

Do you know how to use qq() and qw()? Instead of
my $stuff =

lyra (lyra), Thursday, 19 May 2005 02:22 (twenty years ago)


ARGH... that didn't work so well. this is what got eaten:

instead of my $stuff = < <END
something
something
END

you can use qq like so:

my $stuff = qq(
something
something else
);

lyra (lyra), Thursday, 19 May 2005 02:25 (twenty years ago)

I miss writing FORTH. I still use sed and awk which more then I can say for PERL, piece of shit language.

Rufus 3000 (Mr Noodles), Thursday, 19 May 2005 02:35 (twenty years ago)

for emacs formating and perl heredocs get one MMode! I have a schmancy setup that took some time to get right, but does Javascript, CSS, PHP, and HTML. I have another for Perl/HTML with heredocs. It fuxors up the autotabbing, but a small price to pay. Als o, yay folding!

perl will always be helpful because you will always have big stupid documents with semi-regularly formatted text where you need to extract and munge it in simple but bizarre ways to make it usable.

i'm going to be working on a project li ke that tomorrow -- grabbing lotsa stuff from similar but somewhat distinct static html documents and throwing it into sql so it can be served up all dynamic and pretty-like. so a perlscript that i write once and use once is still way better than crawling through that whole mess by hand.3

Sterling Clover (s_clover), Thursday, 19 May 2005 02:39 (twenty years ago)

sed and awk are fine for simple stuff, but writing logic in them is awful -- altho, maybe for this project i could get away with awk now that i think about it.h

Sterling Clover (s_clover), Thursday, 19 May 2005 02:40 (twenty years ago)

I think cut also tends to be underrated for datamunging. Although if you're grabbing data from HTML docs, it might not particularly be helpful for you.

lyra (lyra), Thursday, 19 May 2005 02:48 (twenty years ago)

word up, who's down with larry wall?

Stormy Davis (diamond), Thursday, 19 May 2005 03:05 (twenty years ago)

Larry Wall seems rad, and it's sad that he's been so sick lately.

And I really like Perl a lot. Oh, that reminds me that I downloaded Scheme recently! Not that I really have time to learn it, so much.

Casuistry (Chris P), Thursday, 19 May 2005 05:55 (twenty years ago)

larry's given some cool talks/speeches/whatever.

Do you know how to use qq() and qw()?

i know qq and qw but have generally used it only when i'm quoting and double quoting in the text too much.

i miss emacs. even with a linux box, i've been in windows land too long... (and somewhat stuck with visual studios and textpad and so on.)

i rarely fuss with set ups. too many tools, not enough time to tweak them. (because i obviously spend too much damned time on message boards! doh!)

i need to write a bot to post for me here so i can get my shit in order. lwp...

I downloaded Scheme recently

scheme is cool. our intro to cis class (the first core class in the cis dept) was almost all scheme. it's a shame i haven't touched it since. i'd be interested to see what's come of it and lisp in recent years now that lisp especially has gotten all trendy/cool in some circles. unfortunately, it's all libraries that really affect whether or not i get to play with something.
m.

msp (mspa), Thursday, 19 May 2005 07:12 (twenty years ago)

i miss emacs. even with a linux box, i've been in windows land too long...

It does work on Windows too, you know. I use it for all my Perl-on-Windows developing.

caitlin (caitlin), Thursday, 19 May 2005 10:28 (twenty years ago)

yeah... but since i have to be in visual studio for things like source control, it's pointless to have it.

i may have to download it anyway though.
m.

msp (mspa), Thursday, 19 May 2005 12:55 (twenty years ago)

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

unfortunately, they also wanyt $36 to use their compiler resources...


anybody know anyplace else? most of the places i've checked from here:

http://www.ductape.net/~mitja/freeunix.shtml

aren't accepting new accounts right now...

kingfish maximum overdrunk (Kingfish), Friday, 20 May 2005 03:31 (twenty years ago)

Just install Cygwin!

A homunculus of Darby Crash, .... created for the purposes of *EVIL* (ex machina, Friday, 20 May 2005 05:14 (twenty years ago)

i'm working on it, but i think a free shell acct might come in handy, too

kingfish maximum overdrunk (Kingfish), Friday, 20 May 2005 05:58 (twenty years ago)

How big is your hard drive? You could partition it and install linux on one partition.

lyra (lyra), Friday, 20 May 2005 14:10 (twenty years ago)

"unfortunately, they also wanyt $36 to use their compiler resources..."

ouch! back in the day, they didn't charge. used to have an account with them 5 or 6 years ago.
m.

msp (mspa), Friday, 20 May 2005 14:15 (twenty years ago)

dammit. now my cygwin and perl installs are in two different places and don't want to walk to each other.

this is bringing back bad memories of 5+ years ago, repeatedly editing thru my .cshrc file...

kingfish maximum overdrunk (Kingfish), Saturday, 21 May 2005 04:36 (twenty years ago)

use the perl that comes with cygwin. (and those error messages you get when trying to use getcwd, just ignore them, i do!)

koogs (koogs), Saturday, 21 May 2005 16:52 (twenty years ago)

Reading over this thread leads me to ask: How the FUCK do you guys know all this shit?!?!?!

Mr. Snrub (Mr. Snrub), Saturday, 21 May 2005 18:32 (twenty years ago)

We pick it up as we go along.

caitlin (caitlin), Saturday, 21 May 2005 18:43 (twenty years ago)

The basic syntax is virtually indentical to PHP. The only thing I don't know REALLY well right now are:

use Strict;
scoping rules
OO

jw, Saturday, 21 May 2005 18:44 (twenty years ago)

The big syntactical difference with PHP is the different symbols for different types of variable.

caitlin (caitlin), Saturday, 21 May 2005 21:27 (twenty years ago)

Reading over this thread leads me to ask: How the FUCK do you guys know all this shit?!?!?!

I wish I knew. Maybe if could forget some perl I could remember useful stuff, like where in the parking garage I parked my car last night.

lyra (lyra), Sunday, 22 May 2005 00:10 (twenty years ago)

OO is weird. I think I "get" it but I don't use it except when I'm blindly following instructions ($q->p("This is a paragraph!")).

Casuistry (Chris P), Sunday, 22 May 2005 07:19 (twenty years ago)

OO in perl5 is a bit of a hack; I don't like it because of the way it's so obviously just tacked on top of everything else. I've heard that in perl6 it's more fundamental, but I don't know how that affects it in use - I've a sneaking suspicion that the nastier parts will hang around for compatibility reasons.

caitlin (caitlin), Sunday, 22 May 2005 08:29 (twenty years ago)

Perl 6 has that roles stuff that should be in it. I was at 2 talks where Damian Conway explained them very nicely, so I'm excited about it. Of course he is capable of making perl geeks get excited about anything, as per the Quantum Perl talk.

lyra (lyra), Sunday, 22 May 2005 15:40 (twenty years ago)

I've a sneaking suspicion that the nastier parts will hang around for compatibility reasons.

haha, DID YOU KNOW: that the perl people are trying to AUTOMATE perl5-%gt;6 conversion of code?

Perl6 will be cool because of the parrot VM. I wonder if someone is working on getting gcc to target it as well....?

A homunculus of Darby Crash, .... created for the purposes of *EVIL* (ex machina, Sunday, 22 May 2005 16:41 (twenty years ago)

The phrase "automated code conversion" generally makes me want to curl up in fear in a dark corner.

caitlin (caitlin), Sunday, 22 May 2005 19:38 (twenty years ago)

one month passes...
TS: split / / vs. split " "

k/l (Ken L), Wednesday, 20 July 2005 16:59 (twenty years ago)

The correct answer is: split " ".

k/l (Ken L), Wednesday, 20 July 2005 20:31 (twenty years ago)

perl: write once, run away.

mikef (mfleming), Wednesday, 20 July 2005 20:34 (twenty years ago)

Correct answer:
split;

OLD SPICE® CHEMTRAILS!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ex machina), Wednesday, 20 July 2005 20:37 (twenty years ago)

spliff \***"""''''

kingfish (Kingfish), Wednesday, 20 July 2005 20:38 (twenty years ago)

Yeah, of course JW, but if you've gotta specify WHAT you're splitting, the " " works more like the regular split without any arguments.

k/l (Ken L), Wednesday, 20 July 2005 20:41 (twenty years ago)

My understanding was that the first arg defaults to /\w+/ not " ".

OLD SPICE® CHEMTRAILS!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ex machina), Wednesday, 20 July 2005 20:48 (twenty years ago)

You mean /\s+/, don't you?

In any case, if you need to provide an EXPR to split, you're forced to give it a pattern, aren't you?

split /PATTERN/, $foobar

If you give it " " for the /PATTERN/, it behaves properly. Other things might give a spurious extra first field because of leading whitespace, leave on carriage returns, newlines, etc.

k/l (Ken L), Wednesday, 20 July 2005 21:01 (twenty years ago)

You mean /\s+/, don't you?
:D

If you give it " " for the /PATTERN/, it behaves properly. Other things might give a spurious extra first field because of leading whitespace, leave on carriage returns, newlines, etc.
Err isn't it *the other way around?*

OLD SPICE® CHEMTRAILS!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ex machina), Wednesday, 20 July 2005 21:03 (twenty years ago)

See entry for split in Chapter 29 of the Camel book, bottom of page 794. Or did you write the book?

k/l (Ken L), Wednesday, 20 July 2005 21:16 (twenty years ago)

Actually now that I read it more carefully, you don't need any pattern at all you can just put

split     , EXPR

But see also page 796.

k/l (Ken L), Wednesday, 20 July 2005 21:21 (twenty years ago)

perl: write once, run away.

Heh. Write once, get assigned to another project, pretend you are deaf when you hear 'point release' coming your way.

I write most of my regexen with | as a delimiter, good one to use if you always are parsing URLs. Also, we were a little goofy at lunch the other day and discussing data structures in perl and I had to lament the lack of stacks in perl. My dog goes to work with me, so he sits under my desk while I program, and our running joke is that his favorite data structure is stacks of milkbones. But in perl he has to settle for references to milkbones, not nearly as satisfying. (Yes, we are sick, smack me now.)

lyra (lyra), Thursday, 21 July 2005 01:39 (twenty years ago)

Wait! There are totally stacks in perl!!!!!!!!!!

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

Eh? There are arrays, and you can fake stacks by writing a wrapper to enforce FILO, but I'm pretty sure stacks aren't native to perl.

lyra (lyra), Thursday, 21 July 2005 01:44 (twenty years ago)

Well, you can't "enforce" anything. But you can push() and pop() arrays and they behave like they should.

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

But, but, it's still an array!
</pedantic>

lyra (lyra), Thursday, 21 July 2005 01:49 (twenty years ago)

I love push, though. It's in my top 10 favorite perl functions, right next to the beauty that is scalar @array. I have learned to carefully read code reviews when C++ programmers check in changes to code I've written where I use that, they nevah understand what it's supposed to be doing.

lyra (lyra), Thursday, 21 July 2005 01:55 (twenty years ago)

I was the most senior student programmer at my school's web team and I can't count the number of times freshmen would fuck my shit up.

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

God help us if theres a war, etc.

Trayce (trayce), Thursday, 21 July 2005 02:14 (twenty years ago)

I can't really blame non-perl progammers for not following what scalar @array does. (For the non-perl-dweebs, if any are reading this, doing my $c = scalar @array puts the size (aka number of elements in it) of the array into $c.)

If you just look at it, it looks like it's changing the type of @array to a scalar or something, not counting its size. Perl in built-in-obfuscation shocker.

lyra (lyra), Thursday, 21 July 2005 03:05 (twenty years ago)

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

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

In perl you don't, but C++ supports typecasting (aka forcing one type of variable to act as another). Also, one of the programmers who horked me by changing a scalar @array line assumed that it would give you the memory address of the array. WHY you would ever want the address in memory that something is stored at in perl was beyond me, he was an old school C programmer so I guess he thought he was going to do something with it.

lyra (lyra), Thursday, 21 July 2005 03:13 (twenty years ago)

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

m.

msp (mspa), Thursday, 21 July 2005 03:25 (twenty years ago)

i'm halfway thru my online perl class. GTA:SA and Sid Meier's Pirates interrupts my learning.

kingfish (Kingfish), Thursday, 21 July 2005 03:27 (twenty years ago)

HOW DO YOU CAST AN ARRAY TO A NON ARRAY TYPE IN C++. YOU CAN'T.


kingfish -- the new Pirates? I loved the old one to the point where I kept around my Tandy 1000 till like 1999 so I could get better sound and gfx out of it (versus a 386 or P100 or P266).

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

HOW DO YOU CAST AN ARRAY TO A NON ARRAY TYPE IN C++. YOU CAN'T.
I never said the programmers who assumed that was what was happening were SMART. (; Merely that they'd assumed such things were happening in perl.

$#array gives you the index of the last element. That's one less than scalar @array. I love foreach too, but sometimes in drawing applications you need to know, say, how many search results rows you've got in your array to print out 'Found 88 items' or whatever- the scalar @array syntax is perfect for that. Or a quickie test to tell if you have anything in the errors array after an eval:

eval { $results = do_some_sketchy_function_that_might_die(); };

if (scalar $@) {
print "sorry sucker i died on you";
}

lyra (lyra), Thursday, 21 July 2005 03:33 (twenty years ago)

don't you mean:

die "sorry sucker i died on you";

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

"$#array gives you the index of the last element"

sure...

$#array has other strange uses like:

$#array = 20;

hey, but this is perl .... "There's more than one way to do it." i can dig your scalar usage.

seems like foreach is also pretty blahtastic for assignments ...seems like i recall there being scope issues. it's sugar sweet tho.

i can dig perl's unspoken nature... but i tend to code very explicitly. relying on all the hidden variables gets nightmarish later on.

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...

?
m.

msp (mspa), Thursday, 21 July 2005 04:34 (twenty years ago)

msp, perl is compiled at the beginning runtime so static variable references in code (like an implicit $_) are just as fast as explicit $foobar.


I think.

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

yes. that would make sense.
m.

msp (mspa), Thursday, 21 July 2005 04:40 (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.

Casuistry (Chris P), Thursday, 21 July 2005 04:54 (twenty years ago)

HOW DO YOU CAST AN ARRAY TO A NON ARRAY TYPE IN C++. YOU CAN'T.

And lo, the computer expert has spoken!

Casting between arrays and non-array types is one of the most frequent operations when dealing with arrays - at least with all the code I've ever written or looked at. You might want to try learning about array-pointer equivalence sometime. And, of course, the even-more-correct answer is that you can cast any type to anything else - you're just not guaranteed to get any meaningful result.

Should I bother to learn C?

Yes. It's a good language to learn, although I don't know how useful it is for creating Mac applications. You might want to learn the basics of C and then try moving on to Objective C.

Forest Pines (ForestPines), Thursday, 21 July 2005 05:27 (twenty years ago)

I guess what I mean is, is C brilliant?

Casuistry (Chris P), Thursday, 21 July 2005 05:31 (twenty years ago)

You might want to try learning about array-pointer equivalence sometime. etc

Oh come on fuck off, I took computer science 173 also! You can define a cast function for anything, but what MEANING does assigning an array to an int have. (YES I KNOW INT[] IS ACTUALLY INT*)

C is essentially a bunch of crap built up on top of assembly language macros. The Objective C classes for OSX are very powerful and similar to the Java class library in functionality. I have played with it, but haven't had a need to develop a real application ever.

C is used a lot of places but most people developing their own stuff now should steer clear IMHO. I mean --- there are fucking computer science programs that have stopped using it completelt (insane IMHO).

OLD SPICE® CHEMTRAILS!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ex machina), Thursday, 21 July 2005 05:47 (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.