Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

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

G'day Lady Aleena,

Without knowing the exact contents of @big_images and @cross_files, or what transformation occurs when textify() is run, it's not possible to give a direct answer.

As a first step, I recommend you print those values inside delimiters to identify parts of the string that may not be immediately obvious. For example, these may appear the same when printed directly:

$ perl -E 'say for "qwe", "qwe\n"' qwe qwe

With delimiters, the difference is obvious:

$ perl -E 'say "|$_|" for "qwe", "qwe\n"' |qwe| |qwe |

Doing this may highlight the problem and allow you to solve it yourself. If not, post the results and we can have another look at it.

You're reading the entirety of @big_images in every iteration of the for loop. A slightly more efficient way would be to only read as much as you need: see the List::Util function first. Not reading that array at all inside the for loop would be much better; something like:

my %big_image = map +(fc($_) => 1), $opt{big} ? @{$opt{big}} : (); for my $cross_file (@cross_files) { my $text = textify($cross_file); my $class = 'svg_group'; $class .= ' right' unless exists $big_image{fc $text}; }

Note: Testing $opt{big} for truth may be an issue. If --big (I'm guessing at the option) isn't supplied, will the key, big, be absent or will it have an empty arrayref ([]) as its value? If it's an empty arrayref, the value (something like ARRAY(0xhhhhhhhh)) will always be true and a better test would be 0+@{$opt{big}}.

$ perl -E 'my %opt = ( big => [] ); say $opt{big}' ARRAY(0x600003a90) $ perl -E 'my %opt = ( big => [] ); say 0+@{$opt{big}}' 0

However, if the key is absent, a better test would be exists($opt{big}).

Depending on other code not shown, a combination of both of those (exists($opt{big}) && 0+@{$opt{big}}) may be even better.

— Ken


In reply to Re: How do I get an exclusion with grep? by kcott
in thread How do I get an exclusion with grep? by Lady_Aleena

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 perusing the Monastery: (7)
As of 2024-04-25 15:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found