Perl Scripting Tips

Now if you are writing scripts with Perl and come from a C or C++ programming background, one of the first things you would want to know is Multiline comment. Well its simple, as shown below.

=begin comment

<your script>

=end comment

=cut

The next thing I wanted to work on was to read a file or paragraph line by line and search for the presence of a string in any line. Here’s how to go about it.

#$obj has the set of lines to be parsed

foreach my $resultline (split /^/m, $obj) {

#$resultline has a line currently being read, $str has to be searched in this line

if (index ($resultline, $str) != 1) {

<Your action>

}

}

 

Reference: