3 ms·
> Imagine spending your whole afternoon trying to dig what "($fc) = /^(.)/" does The issue with that is that it's a core part of the language's syntax so how a
by dale_glass 4y ago
> Imagine spending your whole afternoon trying to dig what "($fc) = /^(.)/" does
The issue with that is that it's a core part of the language's syntax so how are you going to search for something like that? It's a bit like trying to search what the `Obj foo{3};` means in C++, nothing in the text is a keyword, so it will vary from one program to the next and therefore won't be searchable.
- shubhamjain 4y agoConventional languages follow a pattern and you can get somewhere because the syntax will seem vaguely familiar if the paradigm is the same. I can guess the code you mentioned is some sort of declaration. Perl deviates too much at times and the numbers of choices is seriously high, which makes the job considerably difficult.
- BaseballPhysics 4y ago> Conventional languages follow a pattern and you can get somewhere because the syntax will seem vaguely familiar if the paradigm is the same. Got it, so all languages should look kinda similar so you don't actually have to learn them to grok the code. Let me guess, you also dislike Lisp, Smalltalk, and Haskell?
- kazinator 4y agoI'm guessing that it's a compound assignment. /^(.)/ is a regex match with a capture group. Perhaps this produces a list or tuple like ("a") if the buffer starts with "a", and that becomes the value of $fc. So that is to say, maybe ($x, $y, $z) = /(\d+)-(\d+)-(\d+)/ breaks down a string like 123-334-559 such that $x gets "123", $b gets "334" and $z gets "559". I did a very small amount of Perl 4 programming in the mid-to-late 1990s.
- dale_glass 4y agoNot that, no. ($fc) = /^(.)/ We're doing a regexp match, capturing the first character of a string. This is an usage of the implicit $_ magic variable. The () in the regexp means we want to capture this part, and the "." matches any character. ^ is the start of the string. We're doing ($fc) rather than $fc because regular expression matches work differently depending on context. In array context they return a list of matches. In scalar context they return a match count. So the ($fc) forces an array context to return the actual match. So, TL;DR in a more traditional language this would be: firstChar = left(someString, 1) And actually in Perl you could do: $fc = substr($var, 0, 1); as well, which would be far more understandable to a less Perl-inclined person, but with regexes being such a core part of the language they tend to show up for purposes users of other languages may not expect. This is indeed a pretty good demonstration of some of Perl's quirkiness. If you like it, it's nice and flexible, if you don't, then it's annoying as hell.