#!/usr/bin/perl -w use strict; my $x= '1 2 3 4 5 6 7 8 9 10 11 12 13 14 15'; print "$x\n"; $x =~ m/^(?<weight>\d+)\s*$/g; #my $weight = $1; print "$+{weight}\n"; print "Weight:\n" unless $x=~/Gkg\./g;
I am trying to print each number from variable x. but I am getting an error which says-Use of uninitialized value $+{"weight"} in concatenation (.) or string. I am trying to execute the following example from "https://perldoc.perl.org/perlretut.html#Using-regular-expressions-in-Perl"
$metric = 1; # use metric units $x = <FILE>; # read in measurement $x =~ /^([+-]?\d+)\s*/g; # get magnitude $weight = $1; if ($metric) { # error checking print "Units error!" unless $x =~ /\Gkg\./g; } else { print "Units error!" unless $x =~ /\Glbs\./g; }
Can any body highlight the issue with my code?
In reply to Regular expression by pravakta
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |