Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • My only question is: why are you using eval "" rather than eval {} ?
    --
      ---ict / Spoon
    • Because I need some vars interpolated and some don't. The $params{'sort'} is dynamic.
      • You still don't need the string eval e.g

        if ($params{sort} eq "date")
        { use Time::Local;
          @messages =
          map  { $_->[0] }
          sort { $a->[1] <=> $b->[1] }
          map  { my ($h,$m,$d,$M,$y) =
            $_->messagedate =~ /^(\d{1,2})\:(\d{1,2})
            (\d{1,2})\/(\d{1,2})\/(\d{4})/;
            [$_,timelocal(0,$m,$h,$d,$M-1,$y) ] }
          @messages; #Schwartzian Magic
        } else
        { @messages =
          sort
          { lc($a->${\$params{sort}}) cmp
            lc($b->${\$

        --

        broquaint out

        • @messages contains a number of objects and I need to call a simple getter. I can't (and shouldn't) access those variables explicitly. So I need the name of that parameter (and yes, I do some checking prior to that eval block). And yes, I am using strict... all of it :P
          • I still don't need the need for strict. The only bits that are interpolated are the string comparison, which doesn't need to be interpolated, and the methods calls, which again, can live outside a string eval. Or am I missing something?
            --

            broquaint out

            • IIRC you can't do method calls based on scalar values within strict. Ofcourse, I still suck at perl ;P
              • You surely can
                shell> perl -Mstrict -

                sub foo { print "i'm in foo\n" }
                my $m = "foo";
                main->$m;

                i'm in foo
                This is because we're not violating strict in anyway (not symbolic, not bareword, declared variable).

                With your hash you can do some slippery scalar dereferencing (to keep it all syntactically correct) or just assign the value to a simple scalar e.g

                shell> perl -Mstrict -

                sub foo { print "i'm in foo\n" }

                my %h = ( method => "foo" );
                my $m = $h{method};

                # slippery syntactic shenanigans
                main->${\ $h{method} };

                # such a simple scalar
                main->$m;

                i'm in foo
                i'm in foo

                --

                broquaint out