Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Suggestion on rewriting small code

by dave_the_m (Monsignor)
on Aug 21, 2019 at 07:01 UTC ( [id://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 (Canon) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11104768]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-19 03:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found