Scalar-only Perl

Now that Perl's builtin functions can directly operate on hashrefs and arrayrefs (I'm already starting to dread having to write push @{$foo->{bar}} instead of just push $foo->{bar}, but I'll be stuck with 5.10 for at least a couple more years), it chuckles me a bit imagining a future where beginners only use and know about scalars, and not arrays/hashes. Where they just need to memorize $ as the variable prefix. And where % and @ are nowhere to be found in baby Perl.

Among the issues with this would include the many special variables like @_, @INC and %INC, %ENV, %SIG and so on. We can provide some abstraction like self or MooseX::Declare for @_. With Moose et al, we already don't need to muck with @ISA directly.

Another would be list assignment, but I don't think beginners use it much.

Wouldn't it be cute? Albeit a bit pointless maybe. I can do away with context in Perl, but for now I like being able to have $thing, @thing, and %thing at the same time. Or do I?


I've been thinking of something similar. Well, not where beginners don't know about arrays and hashes, but where they only need to know about references to those data structures.

Suddenly a whole level of Perl complexity goes away as complex data structures work as beginners expect them to and accidental list flattening becomes a thing of the past.

my $hash = { one => 1, two => 2 };
my $array = [ 1 .. 10 ];
my $data_structure = {
  hash => $hash,
  array => $array,

Of course, it no doubt opens up whole new areas of doubt and uncertainty :-)

Of course, it no doubt opens up whole new areas of doubt and uncertainty

No kidding - you just assigned the result of flip-flop on lines 1/10 to $array :)

Argh. Oops, yes, fixed. Thanks for pointing it out.

But in this case, the error wasn't a symptom of the complexity of the scalar-only syntax. It was simply a symptom of the pointlessness of posting at ridiculously early times of the day.

(Hmm... I wonder what this site's timezone is set to. It claims I made that post at 2:41pm. It was more like 6:41am.... *wanders off to check config options*)

First person that adds syntax validation to a blogging/commenting system will run away with the money.

Leave a comment

About Steven Haryanto

user-pic A programmer (mostly Perl 5 nowadays).