Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: modify the contents of an array

by dannoura (Pilgrim)
on Sep 29, 2005 at 14:45 UTC ( #496121=note: print w/ replies, xml ) Need Help??


in reply to modify the contents of an array

How about:

my @arr = qw/092205 092305 092605/; foreach (@arr) {$_ = sprintf "%d%d/%d%d/%d%d", split //} print "@arr";


Comment on Re: modify the contents of an array
Download Code
Re^2: modify the contents of an array
by Anonymous Monk on Sep 29, 2005 at 15:13 UTC
    Even slower than the s/// suggestion.
    #!/usr/bin/perl use strict; use warnings; use Benchmark qw 'cmpthese'; our @dates = (qw [092205 092305 092605]) x 100; our (@sub, @pck, @mth, @spf,); cmpthese(-10, { sub => '@sub = @dates; for (@sub) {s{(\d{2})(\d{2})(\d{2})}{$1/$2/ +$3}}', pck => '@pck = @dates; for (@pck) {$_ = join "/", unpack "A2 A2 A2 +", $_}', mth => '@mth = @dates; for (@mth) {$_ = join "/", /../g}', spf => '@spf = @dates; for (@spf) {$_ = sprintf "%d%d/%d%d/%d%d", +split //}', }); __END__ Rate spf sub mth pck spf 368/s -- -33% -60% -69% sub 548/s 49% -- -40% -53% mth 909/s 147% 66% -- -22% pck 1171/s 218% 114% 29% --

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2015-07-04 14:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls