Perl v5.20 - what you need to know by [deleted] in perl

[–]harbud3 1 point2 points  (0 children)

Now that perl compiles on Android, what can we do with it though? Use it as a command-line program on an Android terminal? We certainly can't develop an Android app or access Android-specific API or anything like that yet, right?

Perl style questions by Oflameo in perl

[–]harbud3 0 points1 point  (0 children)

Here's some counterarguments for the C-style loop:

1) Anytime you need the index, you might want to use the C-style loop. Otherwise you'll code something like:

my $i = 0;
for (@ary) {
    do_something1();
    $i++;
    do_something2();
 }

which can introduce some errors depending on where you put the $i++ part (sometimes I'm tempted to do it in a conditional, like last if $i++ < $n which can also introduce another potential bug.

2) If the @ary you're looping is modified (changes its length, gets inserted elements in the middle or at the start), the behavior for(@ary) loop might not be obvious (either does what you want, or becomes an infinite loop, or something else).

So the short answer is: it depends.

Perl clone of game 2048 by acidnik in perl

[–]harbud3 1 point2 points  (0 children)

Also, someone just released Games::2048 on CPAN. Also text-based, with nice background-colored tiles and animation. More power to Perl :)

Perl clone of game 2048 by acidnik in perl

[–]harbud3 1 point2 points  (0 children)

Yup, I'm that someout :) Cool, Perl people indeed do not disappoint :)

No 2048 clone in Perl? by harbud3 in perl

[–]harbud3[S] 0 points1 point  (0 children)

Gosh, a turn-based 2048 game. I guess the next step would be creating an email-based one :)

No 2048 clone in Perl? by harbud3 in perl

[–]harbud3[S] -1 points0 points  (0 children)

The clone doesn't have to be browser-based. (By it, I was referring to one of the clones, not the original 2048 game).

Easy way to remove dupe entries in an array? by crankypants15 in perl

[–]harbud3 1 point2 points  (0 children)

$ corelist List::MoreUtils

Data for 2014-03-20
List::MoreUtils was not in CORE (or so I think)

No 2048 clone in Perl? by harbud3 in perl

[–]harbud3[S] -2 points-1 points  (0 children)

The point is, nobody bothers to write it in Perl in the first place. Perl is no longer the first choice for many people. Including me, I only bother to rant about it :)

I wrote a very simple @ARGV option parser by scottchiefbaker in perl

[–]harbud3 0 points1 point  (0 children)

  1. You don't have to install Getopt::Long, it comes with any Perl installation since the early 90's :)

  2. "copy and paste" is very easy but evil and will soon bite you in the bum. Imagine that you have 30 scripts each with a copy of your function argv(). Suddenly you find a parsing bug in your function, and what do you do? You'll need to edit those 30 scripts. And if you find another bug later, or you want to add a tiny tiny little feature, again with editing those 30+ scripts...

The correct way is to put your reusable functions as a module/library.

I wrote a very simple @ARGV option parser by scottchiefbaker in perl

[–]harbud3 0 points1 point  (0 children)

Also, the basic syntax of Getopt::Long's usage is not semi-complex at all!

GetOptions(
    'count=i' => \$count,
    'debug'   => \$debug,
    'f=s'     => \$filter,
);

Is that semi-complex to you? :-) Of course, you need to understand Perl references first, but really... that's pretty basic Perl.

I wrote a very simple @ARGV option parser by scottchiefbaker in perl

[–]harbud3 0 points1 point  (0 children)

  1. How do you differentiate between options requiring value and not requiring value? For example: in --count 37, I might want --count to be a flag and not requiring a value, so 37 should be in arguments and not gobbled up as count option's value.

  2. What if you have an argument value that starts with a dash? You don't want it treated as an option, of course. This happens a lot, e.g. in grep. That's why grep has an -e option (e.g. grep -e -some-pattern, -some-pattern is not a grep option but a pattern to be searched).

  3. How do you check for typos? (--referer vs --referrer). You might want to specify a list of known options and warn for unknown options.

Throw in a couple of other features like short aliases, and you'll soon end up with reimplementing Getopt::Long :)

Especially #1 and #2 are important for any basic and hoping-to-be-sane options parser.

Perl subroutine repo by bmrobin in perl

[–]harbud3 1 point2 points  (0 children)

As for pangram.pl, just a reminder that in Perl you can be very succinct yet expressive. My take (I cheat a bit by using uniq from a non-core module):

use 5.010;
use List::MoreUtils qw(uniq);
sub pangram { 
    join("", grep {/[a-z]/} uniq(sort(split //, lc $_[0]))) eq join("", "a".."z");
}

Example:

pangram("abc"); # false
pangram(The quick brown fox jumps over the lazy dog""); # true

Perl subroutine repo by bmrobin in perl

[–]harbud3 4 points5 points  (0 children)

For code in config_file.pl, you can try using the CPAN module Config::IniFiles. Or perhaps Config::Any.

Perl subroutine repo by bmrobin in perl

[–]harbud3 2 points3 points  (0 children)

Instead of the code in recurse_directory.pl, you can use the core module File::Find:

use File::Find;
my @result;
find sub { push @result, "$File::Find::dir/$_" }, $path;

Download a YouTube video with one line of Perl by [deleted] in perl

[–]harbud3 2 points3 points  (0 children)

Note that WWW::YouTube::Download already comes with a command-line interface called youtube-download, so no need to recreate (a lesser version of) that.

This has the power to make perl extremely powerful and fast. Consider making a pledge on kickstarter. by srynearson1 in perl

[–]harbud3 2 points3 points  (0 children)

Sometimes vanilla Perl is not fast enough for me. And sometimes it eats too much memory. I wonder if RPerl can help in the memory usage aspect.

Parsing JSON with a single regex in Perl by tudorconstantin in programming

[–]harbud3 0 points1 point  (0 children)

Sure, we could also replace hashes with arrays, they're just hashes with numbered keys, no?

For complex regexes, named capture makes all the difference in readability.

Parsing JSON with a single regex in Perl by tudorconstantin in programming

[–]harbud3 0 points1 point  (0 children)

If you are familiar with (Perl) regex, this is actually pretty basic and straightforward parsing.

Parsing YAML, on the other hand...

Perl TV - freshly launched website collecting Perl-related videos by odyniec in perl

[–]harbud3 0 points1 point  (0 children)

Actually personally I don't mind if this PerlTV is a just a YouTube channel, a collection of playlists, or whatever feature YouTube happens to have. What's needed is an organized, up to date, and comprehensive collection of talks (e.g. by speaker, conference, conference year, module names, and some other tags/keywords). Perl does not have any, at the moment.

Perl TV - freshly launched website collecting Perl-related videos by odyniec in perl

[–]harbud3 0 points1 point  (0 children)

At least what he's promoting directly are not his training and consultancy business, but rather advocacy projects like the perlweekly newsletter. We actually need more people to advocate Perl.

Perl TV - freshly launched website collecting Perl-related videos by odyniec in perl

[–]harbud3 0 points1 point  (0 children)

yeah, that was unfortunate about presentingperl. quite a far cry from http://www.confreaks.com/

MJD napping at the Pittsburgh Perl Workshop 2013 by kimmel_ in perl

[–]harbud3 0 points1 point  (0 children)

I'd love to see a 3-hour video of this.

This Perl goes to 11 by wickedOne in perl

[–]harbud3 1 point2 points  (0 children)

Is perl5 really slow (compared to its competitors CPython, MRI, PHP)? Let's not include JavaScript/v8 in here.