Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

regex question

by grashoper (Monk)
on Oct 14, 2009 at 11:53 UTC ( [id://801050]=perlquestion: print w/replies, xml ) Need Help??

grashoper has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to check usrLevel which would be the access level a user has to the site, in order to provide additional functionality to users with a certain access level. my app is supposed to switch which xml file is used for the user depending on this code which is stored in a session variable. the usersystem would be a prefix for the xml file to be used. This is not working as expected and I am not sure why. is the ! a modifier?
f ($Session->{'usrSystem'} eq "MFR" && $Session->{'usrLevel'}=="!M") { $str .= "<leftIndex>"; $str .= xmlFileData("Content/SSResources", $Session->{'usrSystem +'}.ad.".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; }

Replies are listed 'Best First'.
Re: regex question
by Bloodnok (Vicar) on Oct 14, 2009 at 12:16 UTC
    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 :-))
      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?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://801050]
Approved by BioLion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-03-28 19:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found