Thank you, that was the clue I needed! This now works for me: ... $f = $opts{f} || "sin"; ... $f = "Math::Complex::$f"; ... print eval ($amplitude) * (&$f (2 * pi * $i/$n) + eval ($dc))."\n";
and so I can use this, my "siggen" pgm with gnuplot: plot "<(./siggen -f cos -p 2 -n66 )" lc 1 to get a nice curve. Unfortunately, though, I was only able to get it to work as symbolic reference. First I tried: $f = \&Math::Complex::$func; Scalar found where operator expected at ./siggen line 194, near "&Math::Complex::$func" (Missing operator before $func?) syntax error at ./siggen line 194, near "&Math::Complex::$func" I also tried: $f = eval (\&Math::Complex::$func) but that didn't help. But that's all unimportant, because my pgm works now, thank you. cts --- On Sat, 6/23/12, Ron Bergin <r...@i.frys.com> wrote: > From: Ron Bergin <r...@i.frys.com> > Subject: Re: how to do a reference to a func in Math::Trig > To: "Charles Smith" <cts.priv...@yahoo.com> > Cc: beginners@perl.org > Date: Saturday, June 23, 2012, 3:28 PM > Charles Smith wrote: > > [snip] > > > > But this pgm fails: > > > > #!/usr/bin/env perl > > use Math::Trig; > > my $a = \&Math::Trig::cos; > > &$a(0); > > > > Undefined subroutine &Math::Trig::cos called at > modfunctor line 7. > > > > The cos sub is defined in Math::Complex, which Math::Trig > loads. > > Try this: > > use strict; > use Math::Trig; > > my $cos = \&Math::Complex::cos; > print $cos->(0); > > > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > > -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/