How to insert a word into a string in Perl

Posted by Nano HE on Stack Overflow See other posts from Stack Overflow or by Nano HE
Published on 2010-04-27T23:06:21Z Indexed on 2010/04/27 23:13 UTC
Read the original article Hit count: 560

Filed under:
|
#!C:\Perl\bin\perl.exe 
use strict; 
use warnings; 
use Data::Dumper;  

my $fh = \*DATA;  

while(my $line = <$fh>)
{

    $line =~ s/ ^/male /x ;
    print $line ;
}

__DATA__  
1 0104 Mike Lee 2:01:48

output

male 1 0104 Mike Lee 2:01:48

Then I tried to insert male after the racenumber(0104), I replaced the code with style.

$line =~ s/ ^\d+\s+\d+\s+ /male /x ; # but failed

Acturally I want the output. thank you.

1 0104 male Mike Lee 2:01:48

© Stack Overflow or respective owner

Related posts about perl

Related posts about string-concatenation