Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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: (5)
As of 2014-12-19 04:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (70 votes), past polls