Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Suggestion on rewriting small code

by Anonymous Monk
on Aug 21, 2019 at 12:30 UTC ( #11104809=note: print w/replies, xml ) Need Help??


in reply to Re: Suggestion on rewriting small code
in thread Suggestion on rewriting small code

No you're making it too complicated! :-)

The first problem is initializing the string with that quote.

That causes the next, of concat in a loop, leaving crud at the end of the string.

The dominoes continue to fall as ya chop chop chop away the first two mistakes.

Finally, having to add a quote to the end of a sting is a bad sign that something went wrong earlier, which is now being hacked into compliance.

Also you should know that printing from inside subs is a bad habit, but don't ask me how I know. It just quickly leads to layers of confusion. May I suggest:

say run(); sub run { my @arr = (12341,1245125,1525125,125125125); my $str = join '', '"', (join ' || ', map {"job==$_"} @arr), '"'; return $str }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11104809]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2019-09-17 00:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The room is dark, and your next move is ...












    Results (199 votes). Check out past polls.

    Notices?