Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Concatenate and join

by NetWallah (Canon)
on Mar 31, 2016 at 03:33 UTC ( [id://1159177]=note: print w/replies, xml ) Need Help??


in reply to Concatenate and join

This code produces the answer - you should be able to incorporate the idea into your code.

perl -e '@x=qw| 28 8a 1c 59 cc 85|; my $o=""; for (my $i=0; $i<$#x; $i+=2){ $o.=$x[$i].$x[$i+1]."."} chop $o; print "$o\n"' 288a.1c59.cc85
Update: Fixed typo in code above, to produce right answer.

There are other, slightly more elegant methods (using natatime from List::MoreUtils), but to use those, you will need to use CPAN modules.

Here is another option (Has trailing "."):

perl -e '@x=qw| 28 8a 1c 59 cc 85|; while ($_=shift @x){ print "$_" .shift (@x) . "."}'
Note -: This one destroys the source array.

        This is not an optical illusion, it just looks like one.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-03-28 21:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found