in reply to regex question

I'm intrigued by the post title - there's not a regex in sight.

$hash->{key}=="string" is performing a numerical comparison between a hash value (presumably a string) and a string - did you mean $hash->{key} eq "string" thus performing a string comparison ??

Using strictures would have helped - consider the tidied up code (so that it compiles!):

use warnings; use strict; my ($str, $logoutLink); my $Session = { usrSystem => 'MFR', usrLevel => 'some_val', }; sub foo { if ($Session->{'usrSystem'} eq "MFR" && $Session->{'usrLevel'}=="!M") { $str .= "<leftIndex>"; $str .= xmlFileData("Content/SSResources", $Session->{'usrSystem +'}.".xml", "mLeftIndex()"); $str .= xmlFileData("Content/SSResources", $Session->{'usrSystem +'}.$Session->{'usrAccount'}.".xml", "mLeftIndex()"); $str .= $logoutLink; $str .= "</leftIndex>"; return $str; } ###Shows regular for everyone except this access level... ? if ($Session->{'usrSystem'} eq "MFR" && !$Session->{'usrLevel'}==" +!A") { $str .= "<leftIndex>"; $str .= xmlFileData("Content/SSResources", $Session->{'usrSystem +'}.".xml", "mLeftIndex()"); $str .= xmlFileData("Content/SSResources", $Session->{'usrSystem +'}.$Session->{'usrAccount'}.".xml", "mLeftIndex()"); $str .= $logoutLink; $str .= "</leftIndex>"; } return $str; } foo();
$ perl $_ Argument "!M" isn't numeric in numeric eq (==) at tst.pl line 11. Argument "some_val" isn't numeric in numeric eq (==) at tst.pl line 11 +. Undefined subroutine &main::xmlFileData called at tst.pl line 14.
Ignoring the undefined sub error, you can see that the compiler would have told (or at least given a clear indication to) you what was wrong.

A user level that continues to overstate my experience :-))

Replies are listed 'Best First'.
Re^2: regex question
by grashoper (Monk) on Oct 14, 2009 at 13:42 UTC
    too early in the morning for me I guess. Thanks, I found my problem i meant to do =~/M/) etc. I had forgotten the ! is a not operator so it wouldn't match unless usrLevel was something other than M right?