Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
There Will Be Penalty
May 18, 2002

Makes a great pet!

Ninjew posted:

Stabby McDamage posted:

- Subroutines can be passed as variables ("closures").
Actually, this isn't what a closure is. *snip*

Nice clarification. Also, whether or not your language supports closures, the concept of passing subroutines (or subroutine references) as variables is properly termed "higher-order programming".

:eng101:

Adbot
ADBOT LOVES YOU

There Will Be Penalty
May 18, 2002

Makes a great pet!

TiMBuS posted:

But then I would have to undef $\ when using print for other needs. =(

code:
print "fred";        # doesn't print a newline
{
    local $\ = "\n"; # can't use my here
    print "barney";  # prints a newline
}
print "wilma";       # doesn't print a newline

There Will Be Penalty
May 18, 2002

Makes a great pet!

satest4 posted:

A subroutine definition can refer to variables that exist in the surrounding scope.

That sort of thing is called a closure. :eng101:

There Will Be Penalty
May 18, 2002

Makes a great pet!

ashgromnies posted:

loving ace. I always forget about queues working in Perl all the time :)

I also didn't know about File::Basename... is there a good core module reference anywhere?

perlmodlib(1)

There Will Be Penalty
May 18, 2002

Makes a great pet!
Not a short question, but Perl was released 21 years ago today.

Yay Perl!

There Will Be Penalty
May 18, 2002

Makes a great pet!

Sartak posted:

Found an interesting bug today at work. It would have slipped under my nose if other parts of the code had looser validation. What's the bug?

code:
my %is_special = map { $_ => 1 } qw/user project transaction/;

sub create_record {
    my $self = shift;
    my $type = shift;

    if ($is_special{$type} || ($type =~ /^(.*)s$/ && $is_special{$1})) {
        $type = $1 || $type;
        return $self->create_special_record($type, @_);
    }
    
    return $self->create_mundane_record($type, @_);
}


if $is_special{$type} is true then $1 was preserved from the most recent regex match instead of being undefined or something, right?

There Will Be Penalty
May 18, 2002

Makes a great pet!

Triple Tech posted:

Does the bitwise-and bind too tightly causing you to regexp bind on a "1"??

=~ binds tighter than &&. See perlop(1). And && is not a bitwise AND. :)

Adbot
ADBOT LOVES YOU

There Will Be Penalty
May 18, 2002

Makes a great pet!

FeloniousDrunk posted:

code:
    $$a{'000', 1} = $lea;

Read the perlvar(1) documentation under $;.

  • Locked thread