How do I not store matched patterns in the $1.. strings?

From: Jonathan (none_at_spam.com)
Date: 12/24/03


Date: Wed, 24 Dec 2003 19:40:16 +0100

Ok, I have this script:

#!perl
print "Content-type: text/html\n\n";
$test[0]="Text0<\$UserA|UserB|UserC|5|>Text1";
$test[1]="Text2";
$test[2]="Text3</\$>";
my $User="UserD";
my $Rights="6";
my $Text=join "ARRAYJOINER",@test;
$Text=~s{<\$(([A-Za-z0-9-_
']+\|)+)>(.*?)</\$>}{(index("\$$1","\$$User\|")!=-1 ||
index($1,"\|$User\|")!=-1 || "\$$1"=~/(\$|\|)[0-$Rights]\|/)?$3:""}egs;
@test=split(/ARRAYJOINER/, $Text);
print $Text;
exit;

What I want is for the script to not display the text in between
<$UserA|UserB|UserC|5|> and </$> unless a person is UserA, -B, -C or has
level 5 (or higher) rights. This means that when I use this on my system,
only Admins, who are level 6 and Moderators, who are level 5, will be able
to see "Text1Text2Text3"

I thought about this and came to the conclusion this should be possible in
one line. At least the =~ part of it...when I have an idea in my head, Im
not gonna be able to get it out :D, so I really wanna give it a try...

The index(..) part of the code works, if the user matches it will paste the
text ($3), but the other part of it doesn't. I had to use m// for it to
allow not only the users with the same rights as needed but also with more
rights than needed. ([0-$Rights])...I think the problem is that the m//
operator clears the $3 string and gives it a different value (""). So, how
do I make perl not store the matched pattern in $1..?



Relevant Pages

  • Re: "Selling" Perl (i.e. getting the boss to let me install it)
    ... You have limited access rights, and Perl will run with your rights. ... Whatever you can do, any perl script ... if an admin lets a user download and run exe files, ...
    (comp.lang.perl.misc)
  • 2005-11-20 [de.comp.lang.perl.cgi] FAQ
    ... Programmiersprache Perl in CGI-Scripten. ... Wo gibt es Dokumentation über Perl und CGI? ... Hilfe zum Programm perldoc kann man mit 'perldoc perldoc' ... Mein Script läuft nicht bei meinem Provider. ...
    (de.comp.lang.perl.cgi)
  • 2005-11-20 [de.comp.lang.perl.cgi] FAQ
    ... Programmiersprache Perl in CGI-Scripten. ... Wo gibt es Dokumentation über Perl und CGI? ... Hilfe zum Programm perldoc kann man mit 'perldoc perldoc' ... Mein Script läuft nicht bei meinem Provider. ...
    (de.comp.lang.perl.cgi)
  • 2005-11-20 [de.comp.lang.perl.cgi] FAQ
    ... Programmiersprache Perl in CGI-Scripten. ... Wo gibt es Dokumentation über Perl und CGI? ... Hilfe zum Programm perldoc kann man mit 'perldoc perldoc' ... Mein Script läuft nicht bei meinem Provider. ...
    (de.comp.lang.perl.cgi)
  • 2005-11-20 [de.comp.lang.perl.cgi] FAQ
    ... Programmiersprache Perl in CGI-Scripten. ... Wo gibt es Dokumentation über Perl und CGI? ... Hilfe zum Programm perldoc kann man mit 'perldoc perldoc' ... Mein Script läuft nicht bei meinem Provider. ...
    (de.comp.lang.perl.cgi)