• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 162
  • Last Modified:

replace

how to replace all comma's in a variable with an other character ?

tnx in advance
0
oostwijk
Asked:
oostwijk
  • 2
  • 2
1 Solution
 
ahoffmannCommented:
$var=~s/,/x/g;
0
 
interiotCommented:
$var =~ tr/,/x/;


Using tr/// is a little over 4 times as fast as using s///;
0
 
interiotCommented:
You can see that by running the following program:


#!/usr/bin/env perl
$^W=1;

use Benchmark;

my $str = "asdfklj,123ja09d,21349a,asd,f,23,,4,,,123a09sdfjl2345,asdj034,";

timethese(500000,
{       'S' => sub {
                my $s = $str;
                $s =~ s/,/x/g;
        },
        'TR' => sub {
                my $s = $str;
                $s =~ tr/,/x/;
        }
});
0
 
ahoffmannCommented:
nice Benchmark ;-)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now