MacBook, defective by design banner

title:
Put the knife down and take a green herb, dude.


descrip:

One feller's views on the state of everyday computer science & its application (and now, OTHER STUFF) who isn't rich enough to shell out for www.myfreakinfirst-andlast-name.com

Using 89% of the same design the blog had in 2001.

FOR ENTERTAINMENT PURPOSES ONLY!!!
Back-up your data and, when you bike, always wear white.

As an Amazon Associate, I earn from qualifying purchases. Affiliate links in green.

x

MarkUpDown is the best Markdown editor for professionals on Windows 10.

It includes two-pane live preview, in-app uploads to imgur for image hosting, and MultiMarkdown table support.

Features you won't find anywhere else include...

You've wasted more than $15 of your time looking for a great Markdown editor.

Stop looking. MarkUpDown is the app you're looking for.

Learn more or head over to the 'Store now!

Wednesday, February 11, 2015

So let's have fun with Perl variable scoping.

sub spam {
    my $mySpam = "my spam";
    our $ourSpam = "our spam";
    local $localSpam = "local spam";

    print "mySpam: " . $mySpam;
    print "ourSpam: " . $ourSpam;
    print "localSpam: " . $localSpam;

    spam2();
}

sub spam2 {
    print "mySpam: " . $mySpam;
    print "ourSpam: " . $ourSpam;
    print "localSpam: " . $localSpam;
}

spam();
print "mySpam: " . $mySpam;
print "ourSpam: " . $ourSpam;
print "localSpam: " . $localSpam;

Results:

mySpam: my spam
ourSpam: our spam
localSpam: local spam
mySpam: 
ourSpam: our spam
localSpam: local spam
mySpam: 
ourSpam: our spam
localSpam:


----------------
*** WARNINGS ***
----------------
Use of uninitialized value $mySpam in concatenation (.) 
    or string at C:\tmp\temp.pl line 14.
Use of uninitialized value $mySpam in concatenation (.) 
    or string at C:\tmp\temp.pl line 20.
Use of uninitialized value $localSpam in concatenation (.) 
    or string at C:\tmp\temp.pl line 22.

What's not to like about Perl scoping? Weird, weird language.

Pretty good summary at this SO answer that boils down to...

  • my is the most restrictive. Exists only between the nearest containing brackets.
  • local additionally gets shared with anything called within the nearest containing brackets.
  • our gets pushed everywhere within the script or module context (including things that import your module).

Mostly I'm just happy how well, relatively speaking, PerlRunner is working as a Perl !IDE. I really should take the time to integrate the syntax aware textbox from the CodeProject rather than continuing to hack away to get code editing behaviors in this one (like autoindent, faux tab deletion, and block tabbing). Honestly, his text box has everything, it appears: code folding, export to HTML, lazy-loading, column selection, even autocomplete if you set it up.

But sometimes it's fun to teach yourself to fish a little.

Labels: ,


posted by ruffin at 2/11/2015 10:57:00 AM
Tuesday, January 13, 2015

Look Ma! More Perl!

;_; (aka QQ)

Again from Learn Perl in about 2 hours 30 minutes:

Unlike almost every other major programming language, Perl calls by reference. This means that the variables or values available inside the body of a subroutine are not copies of the originals. They are the originals.

You're killing me, Perl.

(Bee tea dub: Nice doc on perl command line options here -- -l is a nice alternative to say)

Padre fails

In the "won't behave" category, add still being unable to install Padre, the at least implicitly recommended IDE for Perl, with cpanm or cpan. And I'm not the only person. What a versioning mess.

Loops are fun!

And finally, this jive on loops is more note-to-self, but isn't especially intuitive either:

Basic C-style for loops are available too. Notice how we put a my inside the for statement, declaring $i only for the scope of the loop:

for(my $i = 0; $i < scalar @array; $i++) {
    print $i, ": ", $array[$i];
}
# $i has ceased to exist here, which is much tidier.

This kind of for loop is considered old-fashioned and should be avoided where possible. Native iteration over a list is much nicer. Note: unlike PHP, the for and foreach keywords are synonyms. Just use whatever looks most readable:

foreach my $string ( @array ) {
    print $string;
}

... and it's intuitive, too!

Remembering that $#array gets you the array's length (argh. Of course)...

If you do need the indices, the range operator .. creates an anonymous list of integers:

foreach my $i ( 0 .. $#array ) {
    print $i, ": ", $array[$i];
}

You can't iterate over a hash. However, you can iterate over its keys. Use the keys built-in function to retrieve an array containing all the keys of a hash. Then use the foreach approach that we used for arrays:

foreach my $key (keys %scientists) {
    print $key, ": ", $scientists{$key};
}

Since a hash has no underlying order, the keys may be returned in any order. Use the sort built-in function to sort the array of keys alphabetically beforehand:

foreach my $key (sort keys %scientists) {
    print $key, ": ", $scientists{$key};
}

If you don't provide an explicit iterator, Perl uses a default iterator, $_. $_ is the first and friendliest of the built-in variables:

foreach ( @array ) {
    print $_;
}

Packages are also fun!!!

Packages and modules are two completely separate and distinct features of the Perl programming language. The fact that they both use the same double colon delimiter is a huge red herring. It is possible to switch packages multiple times over the course of a script or module, and it is possible to use the same package declaration in multiple locations in multiple files.

You can see where this is going, right? I was already loling in my head at how convoluted the two concepts could get by this point. -mfn

Calling require Foo::Bar does not look for and load a file with a package Foo::Bar declaration somewhere inside it, nor does it necessarily load subroutines in the Foo::Bar namespace. Calling require Foo::Bar merely loads a file called Foo/Bar.pm, which need not have any kind of package declaration inside it at all, and in fact might declare package Baz::Qux and other nonsense inside it for all you know.

Likewise, a subroutine call Baz::Qux::processThis() need not necessarily have been declared inside a file named Baz/Qux.pm. It could have been declared literally anywhere. This next bit at the close of the packages/modules section is probably best considered a universally applicable tenet of programming:

However, it is important that you do not take [any convention or best practice] for granted, because one day you will meet code produced by a madman.

I don't think I'd ever recommend Perl for someone's first programming language. Probably not even their second (I think I'd recommend 6502 assembler (because you should know, in at least a simplest case, how the things work) and then C# at this point).

VIm is not the IDE you were looking for

And here's a VIm related issue...

I'm trying to trick to run :!perl % to run what I'm editing in a shell, but right now VIm is opening PowerShell, which is executing my PowerShell profile and dropping me into the directory I have PowerShell navigate to by default. When it's there, it can't find the file in %, of course.

I tried Open Perl IDE, which was rough running, and there's some sentiment that it's not working well with recent versions of Windows.

Seems it would be insanely easy (all things considered) to write a Perl IDE for Windows (and Open Perl IDE had 131 downloads from SourceForge (that we know is evil now) this week) since Perl provides its own debugger for goodness' sake, but it doesn't appear to have been done.

WHAT A PAIN.

Others feel your pain.

from here, and the first quote is from the page's author:

2014-09-08 09:20:04 by Sam:

PHP is a minor evil perpetrated and created by incompetent amateurs, whereas Perl is a great and insidious evil perpetrated by skilled but perverted professionals.

... or, better yet...

2014-09-07 05:37:51 by David Mitchell:

Dear God. Not[e] to self: never use perl.

Labels:


posted by ruffin at 1/13/2015 08:26:00 PM
Monday, January 12, 2015

Again from Learn Perl in about 2 hours 30 minutes:

Perl variables come in three types: scalars, arrays and hashes. Each type has its own sigil: $, @ and % respectively.

I started dropping which was which in my head trying to remember what the character was for grabbing a reference, and decided it was mnemonic time.

Taking a closer look, the mnemonic's already there, and is painfully obvious. For those even thicker than me (ha), they are...

  • $ is for S is for Scalar.
  • @ is for A is for Array
  • % is for, well, I guess H, since it's Hash.

Okay, the "H" isn't quite as obvious as it could be (# would probably be more obvious, and then we could use // for comments, but I digress ;^D), but the first two are as obvious as they can get.

Duh.

And as for grabbing references, that's a backlash. Because why not, I guess.

A reference is created using a backslash.

my $colour = "Indigo";
my $scalarRef = \$colour;

Any time you would use the name of a variable, you can instead just put some braces in, and, within the braces, put a reference to a variable instead.

print $colour; # "Indigo"
print $scalarRef; # e.g. "SCALAR(0x182c180)"
print ${ $scalarRef }; # "Indigo"

As long as the result is not ambiguous, you can omit the braces too:

print $$scalarRef; # "Indigo"

or, for an array...

my @owners = @{ $ownersRef };

In other news, I was trying to install Padre with Strawberry Perl, and was following the apparently years old suggestions to the letter. After trying to cpanm Wx, however, I got this encouraging bit in a failed build log:

Test Summary Report
    t/04_userdata.t (Wstat: 0 Tests: 65 Failed: 0)
    TODO passed: 25, 33, 41, 57
    t/14_eh_die.t (Wstat: 0 Tests: 5 Failed: 0)
    Parse errors: Bad plan. You planned 6 tests but ran 5.
    Files=23, Tests=772, 444 wallclock secs ( 0.27 usr + 0.34 sys = 0.61 CPU)
    Result: FAIL

This sort of thing has apparently happened before and may be some sort of version conflict.

Idk, when I was using fink on OS X (I think brew is the more popular package manager for OS X now), I never hit this sort of issue, which was pretty impressive. You'd think Perl on Windows would be popular enough to be pretty painless. It's not.

Labels: ,


posted by ruffin at 1/12/2015 09:19:00 AM
Friday, January 09, 2015

Having managed to dodge Perl for the first 16 years of his professional life, somehow, in 2014 [sic], it creeps up and takes him down. "Just when I thought I was out..."

From Learn Perl in about 2 hours 30 minutes:

Perl has no boolean data type. A scalar in an if statement evaluates to boolean "false" if and only if it is one of the following:

undef
number 0
string ""
string "0".

The Perl documentation repeatedly claims that functions return "true" or "false" values in certain situations. In practice, when a function is claimed to return "true" it usually returns 1, and when it is claimed to return false it usually returns the empty string, "".

RLY Perl? You return truth and falsity with two different paradigms? `string "0"` is *false*?

We're not getting off on the right foot. And I thought I'd unfairly disliked you for all these years.


Backstory:

Third party to direct client and me (and a few others):

I'd like to engage [mfn author] and have him work the actual deployment there. He can also help us troubleshoot scripting issues that arise when the scripts run and work directly with [Perl guy] here. How is [mfn author's] Perl scripting?

My reply to direct client:

> How is his Perl scripting?

Unfortunately nonexistent.

"Unfortunately" said not wholly without jest, unfortunately.

Direct client says:

Oh, I am sure you will be great at it. :)

;^D And with that, we start installing Strawberry Perl and reading free intro books. YAY.

Labels:


posted by ruffin at 1/09/2015 09:24:00 AM

<< Older | Newer >>


Support freedom
All posts can be accessed here:


Just the last year o' posts:

URLs I want to remember:
* Atari 2600 programming on your Mac
* joel on software (tip pt)
* Professional links: resume, github, paltry StackOverflow * Regular Expression Introduction (copy)
* The hex editor whose name I forget
* JSONLint to pretty-ify JSON
* Using CommonDialog in VB 6 * Free zip utils
* git repo mapped drive setup * Regex Tester
* Read the bits about the zone * Find column in sql server db by name
* Giant ASCII Textifier in Stick Figures (in Ivrit) * Quick intro to Javascript
* Don't [over-]sweat "micro-optimization" * Parsing str's in VB6
* .ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture); (src) * Break on a Lenovo T430: Fn+Alt+B
email if ya gotta, RSS if ya wanna RSS, (?_?), ยข, & ? if you're keypadless


Powered by Blogger etree.org Curmudgeon Gamer badge
The postings on this site are [usually] my own and do not necessarily reflect the views of any employer, past or present, or other entity.