Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I have updated my code to the following based on suggestions in this thread and chatterbox. With so much wondeful help, I didn't know who to reply to.

my @list = map { chomp($_); $_ } <$fh>; my @uc_list = map { chomp $_; [uc $_] } <$lc_fh>; # used only onc +e my @split_list = map { chomp $_; [ split(/\|/, $_) ] } <$piped_fh>; +# used only once

...has become...

my @list = map { chomp; $_ } <$fh>; my @uc_list = map { chomp; [uc $_] } <$lc_fh>; # used only once my @split_list = map { chomp; [ split(/\|/, $_) ] } <$piped_fh>; # u +sed only once

It appears that explicitely using chomp($_) is what was the problem.

The following code is now a lot simpler once I put the regex into the subroutine instead of munging it in the map.

my @array = map { $_ =~ s/^[\*\+-] (.+)/$1/; some_sub($_, $opt); } @another_array;

...has become...

<code> my @array = map { some_sub($_, $opt); } @another_array;

With the use of /r and a chain of regexen, I was able to change the map.

my @ids = map { $_ =~ s/<.+?>//g; $_ =~ s/^(\d+([stnrdh]{2}|))/NUMWORDS($1)/e; $_ =~ s/(.)\.\w{2,5}?$/$1/; $_ =~ s/&amp/and/g; $_ =~ s/&/and/g; $_ =~ s//Ae/g; $_ =~ s//C/g; $_ =~ s//U/g; $_ =~ s/(||)/e/g; $_ =~ s/#/No/g; $_ =~ s/ /_/g; $_ =~ s/[^\w:.\-]//g; $_; } grep {defined($_)} @base;

...has become...

my @ids = map { s/<.+?>//gr =~ s/^(\d+([stnrdh]{2}|))/NUMWORDS($1)/er =~ s/(.)\.\w{2,5}?$/$1/r =~ s/&amp/and/gr =~ s/&/and/gr =~ s//Ae/gr =~ s//C/gr =~ s//U/gr =~ s/(||)/e/gr =~ s/#/No/gr =~ s/ /_/gr =~ s/[^\w:.\-]//gr } grep { defined } @base;

And Fancy::Map got a complete overhaul with help.

sub fancy_map { my ($opt, $list) = @_; map { if (ref($_)) { fancy_map($opt, $_); } else { my $before = $opt->{'before'} ? $opt->{'before'}.' ' : ''; my $after = $opt->{'after'} ? ' '.$opt->{'after'} : ''; $_ = $before.$_.$after; } } @{$list}; }

...has become...

sub fancy_map { my ($opt, $list) = @_; map { ref $_ ? fancy_map ($opt, $_) : do { my $before = $opt->{'before'} ? $opt->{'before'}.' ' : ''; my $after = $opt->{'after'} ? ' '.$opt->{'after'} : ''; $before.$_.$after; } } @{$list}; }

My only unfinished business with Perl::Critic set on gentle is my two eval(EXPR). I haven't figured out a fix for that at the moment. Does eval BLOCK act differently than eval EXPR?

Also, please note my updated signature! 8)

My OS is Debian 10 (Buster); my perl versions are 5.28.1 local and 5.16.3 or 5.30.0 on my web host depending on the shebang.

No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
Lady Aleena

In reply to Re: Perl::Critic says don't modify $_ in list functions and other things by Lady_Aleena
in thread Perl::Critic says don't modify $_ in list functions and other things 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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (4)
    As of 2021-01-23 08:05 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Notices?