Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
$str = "5+2-1"; 以下のように 1 つの文字列を表現するとします。その文字列から計算結果を取得したいと思います。これを計算するためにスカラーに変換するにはどうすればよいですか? ありがとう。
文字列に悪意のあるコードが含まれていないことが確実な場合は、eval を使用してその内容を perl コードとして扱うことができます。
#!/usr/bin/perl use strict; use warnings; my $string = "5+2-1"; print eval($string); #print 6