in reply to Re^2: Hash of Arrays and File Operations
in thread Hash of Arrays and File Operations

@cols[1 .. $#cols] = map(tr /[1,2]/[0,1]/, @cols)
I'm no tr expert, but isn't tr /[1,2]/[0,1]/ more simply written as tr/12/01/?

The following will replace all 1's with 0's, and all 2's with 1's, in all elements of the @cols array. It modifies the array in-place.

map { tr/12/01/ } @cols;

Update: I concur with AnonyMonk's hint that it is better written as:

tr/12/01/ for @cols;

Replies are listed 'Best First'.
Re^4: Hash of Arrays and File Operations
by Anonymous Monk on Jan 28, 2010 at 20:24 UTC
    tr/12/91/ for @cols[1.. $#cols];

      I have tried the above syntax and it doesn't seem to be working.

        You may think you have, but you made a mistake :) Show your code and I'll tell you where
        #!/usr/bin/perl -- use strict; use warnings; use Data::Dumper; my @cols = ( 12, 12, 12 ); print Dumper( \@cols ),"\n"; tr/12/91/ for @cols[1.. $#cols]; print Dumper( \@cols ),"\n"; __END__ $VAR1 = [ 12, 12, 12 ]; $VAR1 = [ 12, '91', '91' ];