in reply to slice of ptr-based-output routines?

Sigh...   Copy the string $snap_lvh-> to the clipboard, then paste it each time.   If the set of fields is never going to change during the life of the program, “you only have to type it once.”

If the list of fields is truly variable, then the list of field-names can be put into an array or list and then foreach my $foo (@list) you can use the syntax:   $lv_name->{$foo}.

But in any case your aim should be perfect clarity and maintainability; not a momentary ease of effort for your fingers.   The day may well come when one of those output statements must be slightly different from the rest.   Beware of unwanted “coupling” between one occurrence of a statement and the next.

Replies are listed 'Best First'.
Re^2: slice of ptr-based-output routines?
by perl-diddler (Chaplain) on Aug 01, 2012 at 21:02 UTC
    Are you saying a slice is less clear than spelling out the pointer with each element?

    I don't think I emphasized the point clearly enough -- the above was a transitory debug line put in to look at those values. I didn't want a loop or supporting routines... just wanted to print. Pe is a shortcut routine all in of itself, It' alternate of P, which prints to STDOUT by default (or to a string, in string context). Auto traps/handles undef's in printed args and auto deals with linefeed (adds as final char going to a file handle if needed).

    Each item I am printing is a 'class variable' and all of those subs are 'accessor routines'...writing additional routines just to print the value of accessor routines is way overkill for a debug statement.

    It's all about easy of programming... computers were designed to be the servants of humans -- not the otherway around.

    I just thought a slice like statement where each accessor is called off the same pointer would be more clear than retyping the accessor 5 times. Aren't we supposed to avoid duplication in code?

    Sorry if I was unclear, but I did try to stress it was only debugging code.