Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: regex question

by Bloodnok (Vicar)
on Oct 14, 2009 at 12:16 UTC ( [id://801055]=note: print w/replies, xml ) Need Help??


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?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-26 03:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found