Gyro has asked for the wisdom of the Perl Monks concerning the following question:
Out of curiosity why does this work...#!/usr/bin/perl -w use strict; use warnings; my %CpmRC; while (<DATA>) { %CpmRC = /^(\d+)\W\d+\W\d+\W(\d+)\W\w+/; } while (my ($key, $value) = each(%CpmRC)) { print "$key,$value\n"; # Print contents of the hash } __DATA__ 030 003 1234567 4403 comments 031 003 1234567 4404 comments 032 003 1234567 4405 comments OUTPUT: 032,4405
I am using Perl 5.6.1 on both Solaris and NT. Any comments and/or improvements this will be appreciated./^(\d+)\W\d+\W\d+\W(\d+)\W\w+/; $CpmRC{$1}=$2; and this only catches the last two matches %CpmRC = /^(\d+)\W\d+\W\d+\W(\d+)\W\w+/;
Thanks,
Gyro
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Loading a Hash directly from a Regex
by merlyn (Sage) on Feb 14, 2002 at 15:59 UTC | |
|
Re: Loading a Hash directly from a Regex
by japhy (Canon) on Feb 14, 2002 at 15:57 UTC | |
|
Re: Loading a Hash directly from a Regex
by hakkr (Chaplain) on Feb 14, 2002 at 16:09 UTC | |
by merlyn (Sage) on Feb 14, 2002 at 16:25 UTC | |
by hakkr (Chaplain) on Feb 14, 2002 at 17:18 UTC | |
by merlyn (Sage) on Feb 14, 2002 at 17:27 UTC | |
by hakkr (Chaplain) on Feb 15, 2002 at 09:18 UTC |