Hi all,

On Sat, 9 Nov 2013 08:45:42 -0500
Shawn H Corey <shawnhco...@gmail.com> wrote:

> On Sat, 9 Nov 2013 19:03:00 +0530
> Unknown User <knowsuperunkn...@gmail.com> wrote:
> 
> > Hi,
> > 
> > I have a variable that has a function in it, eg: my $newtime =
> > "time() + 30";
> > How can i use it in code so that it always returns  time() + 30 when
> > it is called?
> 
> See `perldoc -f eval`
> 
> Note that using strings with eval could leave your code open to code
> injection, a big security risk. Use with caution. Or better yet, don't
> use it at all.
> 
> 

an alternative that is often better would be to use subroutine references:

[SHELL]

shlomif@lap:~$ cat sub_ref.pl 
#!/usr/bin/perl

use strict;
use warnings;

my $sub_ref = sub { return time() + 30 };

print "Sub-ref call is: ", scalar( $sub_ref->() ), "\n";
shlomif@lap:~$ perl sub_ref.pl 
Sub-ref call is: 1384007216

[/SHELL]

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Understand what Open Source is - http://shlom.in/oss-fs

Chuck Norris helps the gods that help themselves.
    — http://www.shlomifish.org/humour/bits/facts/Chuck-Norris/

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to