• Posted I'm not positive about this... to Bob

    I'm not positive about this, but I'm not sure that things are behaving as I would expect. What would you expect the following lines to output?

    perl -E 'say "x"; say -"x"; say -"-x"; say -"+x";'

    For me, lines 1 and 2 make sense. Lines 3 and 4 …

  • Commented on What's going on here?
    Ah, thank you Aristotle! You have cleared up some subtleties in the language that I knew were there, but were quite hard to pin down. Thank you for taking the time to clearly explain those subtleties, and give an example...
  • Commented on What's going on here?
    Tom: If it were taking `@_[0,1]` as a scalar parameter, it would be printing out `2`. That's what happens with `sprintf(@_)`. It's clearly taking in two parameters, but for some reason the second parameter is being coerced from a number...
  • Posted What's going on here? to Bob

    What do you think the following lines print?

    use feature 'say';
    sub fmt { sprintf( @_[0, 1] ) }
    my $num = 1_234_567_890.12_345_678_9;
    say sprintf( '%.6f', $num );
    say fmt( '%.6f', $num );

    I think the two say lin…

  • Commented on Hacktoberfest: Thank You
    As one of the many distributions that got your attention (more than once, I might add), I thank you. It feels good to have somebody else notice your imperfections, and offer up a solution, rather than simply being a critic...
  • Commented on Managing my shell setup
    I do a similar thing with my home directory. I have a .profile.d and a .bash.d, and I have my own lib/sh and bin directories, where I have some startup files. The .profile.d directory is for systems (like Ubuntu) that...
Subscribe to feed Recent Actions from $Bob

  • Olaf Alders commented on Hacktoberfest: Thank You

    You kept me really busy in October. ;) Congratulations on this. One thing you could consider is fixing up the .travis.yml config files for various distributions. For example, many won't have added the latest version of Perl or may not have caching enabled, might not have sudo set to false etc. You could probably automate some of that and send hundreds of PRs! Just blasting the PRs might annoy a few people along the way, but if you check with authors first, I'm sure many would welcome it.

  • Aristotle commented on What's going on here?
    If it were taking `@_[0,1]` as a scalar parameter, it would be printing out `2`.


    Replace sprintf with scalar and you will see that the result is exactly the same as you see here.

    That’s because @_[0,1] is a list expression, not an array, and list expressions in scalar context yield the last value from that list, for symmetry with the comma operator in scalar context (which does not create a list!).

    Next, replace sprintf @_[0,1] with sprintf @_ and you will …

  • Luca Ferrari commented on What's going on here?

    Just for the record: Perl6 catches the error.

    sub fmt { sprintf @_[0,1] }
    # Your printf-style directives specify 1 argument, but no argument was supplied

    sub fmt { sprintf $^a, $^b } # OK!

  • ysth commented on What's going on here?

    While you are correct about how it works, conceptually the issue is simply that an array slice in scalar context produces the last element of the slice.

    That it actually produces a list and then the last element of the list is produced is an implementation detail.

  • ysth commented on What's going on here?

    This is a fine example of why prototypes should not be used on user-created subroutines; just memorizing what they are for the built-ins and expecting the syntactic effects they have is hard enough.

Subscribe to feed Responses to Comments from $Bob

About is a common blogging platform for the Perl community. Written in Perl and offering the modern features you’ve come to expect in blog platforms, the site is hosted by Dave Cross and Aaron Crane, with a design donated by Six Apart, Ltd.