BaldPenguin has asked for the wisdom of the Perl Monks concerning the following question:
Output:use strict; use warnings; my $current_index = 12; my %columns = ( 'alpha' => 1, 'bravo' => 2, 'charlie' => 3, 'delta' => 4, ); foreach my $k ( keys %columns ) { ( $current_index =~ $columns{$k} ) ? print "$k matches\n" : print "$k does not match\n"; }
I am trying to grasp why this works, why word perl automagically interpret the scalar as a regex?bravo matches charlie does not match delta does not match alpha matches
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex vs. string
by Enlil (Parson) on Jul 08, 2005 at 23:05 UTC | |
|
Re: Regex vs. string
by dave_the_m (Monsignor) on Jul 09, 2005 at 00:34 UTC | |
by TimToady (Parson) on Jul 09, 2005 at 18:33 UTC | |
|
Re: Regex vs. string
by kwaping (Priest) on Jul 09, 2005 at 15:03 UTC | |
|
Re: Regex vs. string
by kp7 (Initiate) on Jul 10, 2005 at 16:28 UTC |