Perl regex pattern match with saved variable -


I need to match pattern with two variables, one of which has a string and the second has a regex pattern which I have Have tried with the program

  #! / Usr / bin / perl my $ name = "sathish.java"; My $ other = '* .java'; If ($ name = ~ m / $ other /) {print "coefficient"; }  

Please help

thanks Sathishkumar

@ Samuel's answer is tailored to your needs, but if you want a common way of extracting a filename from a full path name, you can use it:

  Strict Use; Use warnings; File :: Use the basinum; My ($ name, $ path, $ suffix) = fileparse ("/ example / path / test.java", qw / .java /); Print "name: $ name \ n"; Print "path: $ path \ n"; Print "suffix: $ suffix \ n";  

It prints:

  name: test path: / example / path / suffix: .java  

Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -