in reply to simple regular expression printing
Have a look at perlretut:
What is a regular expression? A regular expression is simply a string that describes a pattern. [...] In Perl, the patterns described by regular expressions are used to search strings, extract desired parts of strings, and to do search and replace operations./($what){3}/;
To have this expression operate on $what, you would need to write it $what =~ /($what){3}/;. But even then, it won't match, because it would try to match the contents of $what 3 times. In this case, you would be better off with the x operator. You probably also want to print a newline at the end:
use 5.012; use warnings; my $what = 'ram' x 3; print $what, "\n";
Or even...
use 5.012; use warnings; say 'what' x 3;
Your code should always use warnings;, and usestrict; or use5.012; (or later), which automatically enables 'strict'. You might usediagnostics as well. All of these will help you understand and avoid many errors.
|
|---|