monsterzero has asked for the wisdom of the Perl Monks concerning the following question:
I have a problem assigning a varable when using (?{}) inside of a regex. When I run the code below I receive this error:
Sunrise is:03:12Sunset is:21:08 Use of uninitialized value in print at D:\scripts\reg.pl line 7, <DATA +> line 2. Use of uninitialized value in print at D:\scripts\reg.pl line 7, <DATA +> line 2. Sunrise is:Sunset is:
If I comment out the use strict line of the code and remove the my($sunrise, $sunset) line the code will run. I really don't want to comment out the use strict part of my code. So my question is how can I change my code so the (?{}) part will play nice with use strict?
Thanksuse strict; use warnings; while (<DATA>) { my ( $sunrise, $sunset ) = get_time($_); print "Sunrise is:", ${$sunrise}, "Sunset is:", ${$sunset}, "\n"; } sub get_time { my ($string) = @_; my ($sunrise, $sunset); $string =~ /sunrise:\s+(\d+:\d+)(?{ $sunrise = $^N}) \s+sunset:\s+(\d+:\d+)(?{$sunset = $^N})/x; return ( \$sunrise, \$sunset ); } __DATA__ Aberdeen, Scotland 57 9 N 2 9 W sunrise: 03:12 sunset: 21:08 Adelaide, Australia 34 55 S 138 36 E sunrise: 06:52 sunset: 16:41
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Assigning a varable inside of (?{})
by davido (Cardinal) on May 03, 2006 at 16:11 UTC | |
by ikegami (Patriarch) on May 03, 2006 at 17:52 UTC | |
by Jasper (Chaplain) on May 03, 2006 at 16:43 UTC | |
|
Re: Assigning a varable inside of (?{})
by davidrw (Prior) on May 03, 2006 at 16:09 UTC | |
by davido (Cardinal) on May 03, 2006 at 16:18 UTC | |
by monsterzero (Monk) on May 03, 2006 at 16:32 UTC |