in reply to Getopt::Long - why \$ ?

How would you define an interface where you specify a string and a place where to store the value if that string is matched somewhere?

You pass a list of pairs to GetOptions(...), and that list of pairs is 1) the specification of the switch ("name|alias=value type") and 2) the place where the value should be written to. The way to pass a place around in Perl is usually to pass a reference to the target around, which is what happens with the \$foo thing.

An alternative approach is to make GetOptions(...) store all things it finds in a hash. This will give you a plain hash without weird syntax, but on the downside, you lose the typo checking that strict.pm provides.

Replies are listed 'Best First'.
Re^2: Getopt::Long - why \$ ?
by Melly (Chaplain) on Oct 29, 2018 at 14:39 UTC

    Ah, got it. I think my conceptual problem was that I don't think I ever use (or think of) references as a way to set the referenced variable's value. A reference to me tends to mean that either I need a complex data-structure, or I've got a fussy return from a subroutine (e.g. two separate variable-length lists that I need to keep separate).

    Anyway, many thanks your holiness.

    map{$a=1-$_/10;map{$d=$a;$e=$b=$_/20-2;map{($d,$e)=(2*$d*$e+$a,$e**2 -$d**2+$b);$c=$d**2+$e**2>4?$d=8:_}1..50;print$c}0..59;print$/}0..20
    Tom Melly, pm (at) cursingmaggot (stop) co (stop) uk