Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Printing values from references

by gryphon (Abbot)
on Sep 13, 2003 at 23:17 UTC ( #291312=note: print w/replies, xml ) Need Help??

in reply to Printing values from references

Greetings fuzzyping,

Pardon the rough nature of this code, but take a look at this:

#!/usr/bin/perl use strict; use warnings; package Thing; sub stuff { return 'word'; } sub new { return bless {}, shift; } package main; my $thing = new Thing; print $thing->stuff, "\n"; print "$thing->stuff\n"; print $thing, "\n";

When you put $thing->stuff into quotes, Perl interprets only the $thing instead of the whole line. One solution is to do exactly what you've done which is to not put the $thing->stuff inside quotes. I remember seeing a way to get Perl to interpret the whole $thing->stuff inside a double-quote, but I never use it, so I can't remember the exact syntax right now.

code('Perl') || die;

Replies are listed 'Best First'.
Re: Re: Printing values from references
by fuzzyping (Chaplain) on Sep 13, 2003 at 23:57 UTC
    That sounds about right. The only problem is that I can't leave it outside the quotes**, since it's going to be in a system() call for the real script. If anyone can remember how to escape a full reference string like that, I'd be very grateful.

    ** Of course, I can simply read the value into a scalar variable and put that into the system() call, but it seems so inefficient. :)


      Perhaps you're thinking of something along the lines of:

      system "frobnitz --oik @{[ $something->method ]}"

      Of course some would consider that uglier than a temporary. Also remember that system() will take a list just fine (presuming you're not dependent on it being passed to a shell for redirection or what not).

        Good call, on both points. That works, but you're right... it's ugly and very unintuitive. I think I'll just use the temp as you've suggested. Thanks!


      Greetings fuzzyping,

      So why not just do the following?

      system('cmd_line stuff ' . $part->bodyhandle->path . ' and_stuff');

      code('Perl') || die;

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2020-11-26 02:03 GMT
Find Nodes?
    Voting Booth?

    No recent polls found