gem555 has asked for the wisdom of the Perl Monks concerning the following question:
How to initialize the $2. I have to check in array, whether the regular expression matches and if it does not match change the $ to dollar. But if the single character $ it gives a warning message as $2 is empty#!/usr/bin/perl -w use strict; my %words = map { $_ => 1 } qw($Word $name); my $line = '$Word $'; $line =~ s/(\$(\w+)?)/exists $words{$1} ? $1 : "dollar$2"/eg; print "$line\n\n";
|
|---|