Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

G'day SamCG,

A small, representative example of data, together with a short, self-contained script that reproduces what you're attempting to achieve, would go a long way to getting a better answer. If terms such as "parties", "transactional roles", "production values", and so on, are important in understanding your problem domain, please provide appropriate descriptions.

"... but I still think it could be improved"

Here's some suggestions for improvement (particularly with respect to readability and maintainability).

Using statements, as opposed to simple values, for the ternary operators's 2nd and 3rd operands, leads to all sorts of problems (often related to precedence), reduces readability, and increases the difficulty of maintenance: all of this leads to error-prone code. See the documentation (link provided) for examples.

This

exists $uat_tid{$key}?print "$uat_tid{$key}\t":print "No UAT trans id\ +t";

would probably be better as

print exists $uat_tid{$key} ? $uat_tid{$key} : 'No UAT trans id', "\t" +;

And this

exists $uat->{$key}{$inrole}?print "$uat->{$key}{$inrole}":for my $rol +e_key ( keys %{$uat->{$key} } ) { print $role_key if $uat->{$key}{$role_key} eq $value};

would definitely be better as

if (exists $uat->{$key}{$inrole}) { print $uat->{$key}{$inrole}; } else { for my $role_key (keys %{$uat->{$key}}) { print $role_key if $uat->{$key}{$role_key} eq $value; } }
"Does the code below work?"

I don't really know what you're asking. Short answer: run it and find out for yourself. Longer answer: explain what it's supposed to do and why the "Short answer" is inadequate.

"And if so, can I really insert it the way I did into the trinary operator above?"

As already explained, even attempting to do so is not a good idea.

-- Ken


In reply to Re: Iterating over second key in HoH defined by reference by kcott
in thread Iterating over second key in HoH defined by reference by SamCG

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-24 23:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found