I am very confused about perl’s matching behavior.
I have an input file temp.txt that contains:
,0.85Vnom,,,0.75Vnom,,,0.65Vnom,,,
My perl script contains:
#!/usr/bin/perl -w
use strict;
( 0 == @ARGV ) || die( 'Usage: ', __FILE__ );
my $input_file_name = 'temp.txt';
open( my $fh_in, '<', $input_file_name ) || die( "ERROR: cannot read from $input_file_name" );
my $header_line = <$fh_in>;
chomp( $header_line);
print $header_line, "n";
$header_line =~ s/a*/FOOBAR/;
print $header_line, "n";
my @header = split( /s*[,]+s*/, $header_line );
print $header[0], "n";
print $header[1], "n";
print $header[2], "n";
I get the following output to stdout:
,0.85Vnom,,,0.75Vnom,,,0.65Vnom,,,
FOOBAR,0.85Vnom,,,0.75Vnom,,,0.65Vnom,,,
FOOBAR
0.85Vnom
0.75Vnom
why is a* matching before the first comma char? My understanding is that * should match the preceding element (a) 0 or more times. I have no “a” at the start, so what is being matched?
I have tried different matching strings, but it seems that the asterisk is the key regex symbol that is performing as un-expected.