A bug in get_iplayer-3.01?

Ralph Corderoy ralph at inputplus.co.uk
Wed Jun 7 05:03:26 PDT 2017


Hi Richard,

> The function/procedure/subroutine parameters I have difficulty with
> are ones of the form
> my $string = shift;
> I am inclined to agree with MrBrightside's comment in stackoverflow.
> https://stackoverflow.com/questions/7082811/what-does-assigning-shift-to-a-variable-mean
> "Forgive me but this seems like the worst convention ever for code
> readability."

No, it's fine if you know the Unix programming environment.  Perl's
author, Larry Wall, was an expert in it and Perl borrows from tr, sed,
awk, sh, etc., so it's familiar to programmers like him and
straightforward to transfer one's existing knowledge.  Without that,
it's a weird hodge-podge of styles and conventions and Python and Go are
available.  :-)

`my $foo = shift' is handy to shift the first argument off the array of
arguments, assigning it to local variable $foo, and leaving all the
other arguments still in their array, perhaps because they are to be
passed on to another function without being inspected by this one.
sh(1) handles its arguments in a similar manner.

    $ set foo bar xyzzy
    $ while test $# -ne 0; do
    >     echo $# "$@"
    >     shift
    > done
    3 foo bar xyzzy
    2 bar xyzzy
    1 xyzzy
    $

-- 
Cheers, Ralph.
https://plus.google.com/+RalphCorderoy



More information about the get_iplayer mailing list