$stuff = "d:/learning/perl/tmp.txt";
open STUFF, $stuff or die "Cannot open $stuff for read :$!";
while (<STUFF>) {
my($line) = $_; # Good practice to always strip the trailing
chomp($line);
my @values = split(' ', $line);
foreach my $val (@values) {
if ($val == 1){
print "1 found";
}
elsif ($val =~ /hello/){
print "hello found";
}
elsif ($val =~ /"/*"/){ # I don't know how to handle here.
print "/* found";
}
print "\n";
}
}
My tmp.txt:
/* CheerStone ColdStunner
1 Cheer Rock
hello Boo Pedigree
How do I handle the /* character sequence in my code?
Both characters have special meaning in Perl regular expression, so you have to escape them with a backslash:
Btw, you should probably add
^in front of all the regexes, because you seem to want to handle only text on the beginning of the line.