Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://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":



  • 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 having an uproarious good time at the Monastery: (4)
As of 2024-04-19 21:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found