in reply to matching characters in filename
my $file = /(1M01)(\_)(F)(\0+)(121)/;
In the above line, you matching against the default "thing", i.e. $_ and assigning the result to tha variable $file - not what you want, probably. The parens in the regular expression mean captures which are to be found in $1, $2, $3, ... and so on.
Furthermore, the char '_' needs no escape, and \0 does match a NULL byte, not the number 0.
That corrected, the following prints those captures mentioned above, if there is a match:
my $file = '1M01_F00121.npt.gro'; if ( $file =~ /(1M01)(_)(F)(0+)(121)/ ) { print join( "\n", "\$1 = '$1'", "\$2 = '$2'", "\$3 = '$3'", "\$4 = '$4'", "\$5 = '$5'", ),"\n"; } else { print "'$file': no match\n"; } __END__ $1 = '1M01' $2 = '_' $3 = 'F' $4 = '00' $5 = '121'
|
|---|