Evaluating escape sequences in perl

后端 未结 3 1514
暗喜
暗喜 2020-12-12 03:40

I\'m reading strings from a file. Those strings contain escape sequences which I would like to have evaluated before processing them further. So I do:

$t = e         


        
3条回答
  •  自闭症患者
    2020-12-12 03:49

    oh gah don't use eval for this, thats dangerous if someone provides it with input like "system('sync;reboot');"..

    But, you could do something like this:

    #!/usr/bin/perl
    
    $string = 'foo\"ba\\\'r';
    printf("%s\n", $string);
    $string =~ s/\\([\"\'])/$1/g;
    printf("%s\n", $string);
    

提交回复
热议问题