Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Eval and $@% ...

by jeroenes (Priest)
on Jun 19, 2001 at 01:44 UTC ( #89471=note: print w/ replies, xml ) Need Help??


in reply to Eval and $@% ...

For starters, you probably would like to read perlref, perlreftut link here, perldsc and perltoot.

The eval solution is nice. But I don't see where you get the $type from.

Well, if you have a CODE (it's actually a sort of ref) and the functions are garanteed to neglect the input, you could use CODE => '&'.

To handle REFs, add:    $type = ref( $_[0] ) if $type eq 'REF';
, the eval part doesn't change!

A GLOB is more problematic. You have to put it into brackets so add an extra if statement:

if( $type eq 'GLOB' ){ return <$_[0]>; elsif( isa.....

Hope this helps,

Jeroen
"We are not alone"(FZ)


Comment on Re: Eval and $@% ...
Select or Download Code
Re: Re: Eval and $@% ...
by bbfu (Curate) on Jun 19, 2001 at 01:57 UTC

    A GLOB is more problematic. You have to put it into brackets so add an extra if statement...

    You're thinking of glob. The GLOB ref type refers to typeglobs, for which you can just use an asterik.

    So you should just be able to add this to your hash:

    my %mapping = ( #... GLOB => '*', #... );

    bbfu
    Seasons don't fear The Reaper.
    Nor do the wind, the sun, and the rain.
    We can be like they are.

      Look at perlref. GLOBs are Handles in general, so read them in array context with brackets like I did.

      I have never tried to derefence general GLOBs with a '*', aren't they just symbolics like perlref tells us?:

      Symbolic references are names of variables or other objects, just as a symbolic link in a Unix filesystem contains merely the name of a file. The *glob notation is a kind of symbolic reference. (Symbolic references are sometimes called "soft references", but please don't call them that; references are confusing enough without useless synonyms.)

      Jeroen

        Look at perlref. GLOBs are Handles in general, so read them in array context with brackets like I did.

        Only when used as a filehandle. For a variable name there is a scalar ($), a list (@), a hash (%), a filehanlde, and a format. Instead of saying:

        $foo=$bar; @foo=@bar; %foo=%bar;
        you can just say:
        *foo = *bar;
        So, when you dereference a type glob, you don't add the <foo> unless you are reading from a file handle.

        The 15 year old, freshman programmer,
        Stephen Rawls

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://89471]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (15)
As of 2014-08-29 13:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (280 votes), past polls