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

Re: Suggestion on rewriting small code

by dave_the_m (Monsignor)
on Aug 21, 2019 at 07:01 UTC ( #11104768=note: print w/replies, xml ) Need Help??


in reply to Suggestion on rewriting small code

A more perlish way of doing it:
my @arr = (12341,1245125,1525125,125125125); my $str = join ' || ', map "job==$_", @arr; $str = qq{"$str"};

Dave.

Replies are listed 'Best First'.
Re^2: Suggestion on rewriting small code
by Tux (Abbot) on Aug 22, 2019 at 08:27 UTC

    Yet one more variation to put it in a single line. But this is getting obfuscated :)

    my $str = do {local$"=" || ";qq{"@{[map{qq{job==$_}}@arr]}"}};

    Enjoy, Have FUN! H.Merijn
Re^2: Suggestion on rewriting small code
by Anonymous Monk on Aug 21, 2019 at 12:12 UTC
    A more perlish way of doing it: 
    
    my $str = join ' || ', map "job==$_", @arr;
    $str = qq{"$str"};
    

    # TIMTOWTDI:
    
    my $str = join '', '"', (join ' || ', map { "job==$_" } @arr), '"';
    
      One more way for those who likes to join:
      my $str = join ~~( join q[ || ], map { "job==$_" } @arr ), ( q["] ) x +2;

Log In?
Username:
Password:

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

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












    Results (280 votes). Check out past polls.

    Notices?