On Tuesday 13 Apr 2010 11:40:44 Akhthar Parvez K wrote:
> Hi all,
> 
> I've a hash that contains some regex strings as keys and some numbers as
> their values. The value for each keys will primarily be used to identify
> which part to print for that particular rx. eg:- for the first rx string,
> ${$rx{$string1}} (eg: $2) and for the second, $1 etc. And I want to store
> the matched string to a variable like:
> 
> my $c = ${$rx{$string1}}; #$c should store the value of $2
> 
> I can get the desired result if I don't use strict refs. However, with
> strict refs, I'm getting the following error:
> 
> Can't use string ("3") as a SCALAR ref while "strict refs" in use at
> test.pl
> 
> I tried to overcome this issue using scalar(), but didn't help. Could
> someone please let me know what is the workaround here. Thank you!
> 

There are several ways to overcome this problem. I suggest that instead of 
referencing $1, $2 and $3 directly you place them in an array:

{{{
my @matches = ($string =~ m{....}ms);
}}}

And then access the captures in @matches using their indices - 
$matches[$idx-1]. Just note that $matches[0] would be $1, $matches[1] would be 
$2. If that doesn't work for you due to some reason, I may be able to come up 
with other suggestions.

Regards,

        Shlomi Fish

> Regards,
> Akhthar Parvez K
> http://Tips.SysAdminGUIDE.COM
> UNIX is basically a simple operating system, but you have to be a genius to
> understand the simplicity - Dennie Richie

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Original Riddles - http://www.shlomifish.org/puzzles/

Deletionists delete Wikipedia articles that they consider lame.
Chuck Norris deletes deletionists whom he considers lame.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to