×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Another regexp problem

Another regexp problem

Another regexp problem

(OP)
I'm just full of these today   I get the error: Use of uninitilized value at ... line ..., pointing to these lines:

$line =~ s/<!--#include(.*?)=["']\/(.*?)["'](.*?)-->/
grab("$global_inc\/$2",$path,$inc_path,$global_inc)/eg;

$line =~ s/<!--#include(.*?)=["'](.*?)["'](.*?)-->/
grab("$path\/$inc_path\/$2",$path,$inc_path,$global_inc)/eg;

The variable $line is defined, as is the subroutine grab().  In fact, these lines are *in* the subroutine grab().  $path, $inc_path, and $global_inc are also defined.  Any ideas?


Sincerely,
 
Tom Anderson
CEO, Order amid Chaos, Inc.
http://www.oac-design.com

RE: Another regexp problem

first best guess,

Are you defining variables that you are passing to grab before you get to these two replace statements?  If they are not being set until you get into grab, then they are null when each of these replace statements is evaluted.  If those values are static, there is no need to pass them to the sub, just set them in the sub or set them globally and then, do the concatenation in the sub....

maybe?

'hope this helps....


 
 
 keep the rudder amid ship and beware the odd typo

RE: Another regexp problem

(OP)
Here's the entire subroutine (changed a little since I last posted but still giving the error):

sub grab
{
    my ($include_file,$path,$inc_path,$global_inc,$script) = @_;
    my $line = "";
    if (($include_file =~ /\.inc/)||($include_file =~ /\.asp/))
    {
        # print "getting $include_file...<br>\n";
        $line = get($include_file);
    }
    else
    {
        # print "including $include_file...<br>\n";
        open (HTML,$include_file) || &CgiDie("Could not open $include_file: $!");
        my (@DATA)=<HTML>;
        close(HTML);
        $line = join("\n",@DATA);
    }

    # insert a script in the HTML head if provided
    $line =~ s/(<head(.*?)>)(.*?)(<\/head\s*>)/$1$3$script$4/gis;

    $line =~ s/<!--#include(.*?)=["']\/(.*?)["'](.*?)-->/grab("$global_inc\/$2",$path,$inc_path,$global_inc,$script)/eg;
    $line =~ s/<!--#include(.*?)=["'](.*?)["'](.*?)-->/grab("$path\/$inc_path\/$2",$path,$inc_path,$global_inc,$script)/eg;

    return ($line);
}

All of the parameters passed into the subroutine are strings that have been defined.  I am passing them because I am using strict even though they could otherwise be global.


Sincerely,
 
Tom Anderson
CEO, Order amid Chaos, Inc.
http://www.oac-design.com

RE: Another regexp problem

(OP)
I'm also getting that error on the new substitution directly above the other two.  And the really weird part is that now I'm getting it on the regexp in this sub:

sub html_encode
{
    my ($str) = @_;
    $str =~ s/([^0-9A-Za-z])/sprintf("&#%d;",ord($1))/eg;

    return $str;
}


Sincerely,
 
Tom Anderson
CEO, Order amid Chaos, Inc.
http://www.oac-design.com

RE: Another regexp problem

(OP)
Ok, this makes no sense.  I write this:

if ($line&&$global_inc&&$path&&$inc_path)
{
  $line =~ s/<!--#include\s.*?=\s?["']\/(.*?)["'].*?-->/grab("$global_inc\/$1",$path,$inc_path,$global_inc)/egi;
  $line =~ s/<!--#include\s.*?=\s?["'](.*?)["'].*?-->/grab("$path\/$inc_path\/$1",$path,$inc_path,$global_inc)/egi;
}

And it still tells me there is an uninitialized value.  Won't the "if" statement evaluate to false if one of the values is uninitialized?  Could it be misinterpreting something in the regexp "<!--#include" as a variable or function?  Could it think the # is a comment?


Sincerely,
 
Tom Anderson
CEO, Order amid Chaos, Inc.
http://www.oac-design.com

RE: Another regexp problem

I can't point to your error, but i can say that i often get the same error from regular expressions when they are improperly matching the string.  It may be that the (.*?) part isn't actually catching anything.  Try making a simpler version just to print out the $1.  I don't know for sure, but whenever this happens to me, i start building the regex from scratch with a copy of the string to be matched and the text to extract it from open right next to the script window.
 Good luck,
  Martin


"If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."

RE: Another regexp problem

Tom,
can you post a little of the HTML that you are working on?  I can make the error go away, but I am having to alter the code so much that I am probably getting away from what you are trying to do.  With a copy of one of the HTML lines you are trying to match, we could troubleshoot the matching easily.  Then, if the matching/replacing is working, we can look at the larger picture.

Another thought..... do you mean to be calling grab from within itself? <...ponder...ponder... think......scratch head a little>

Another thought.....  are you sure $file is getting set?


 
 
 keep the rudder amid ship and beware the odd typo

RE: Another regexp problem

(OP)
Sorry I haven't gotten back to you guys lately, I've been incapacitated with a bad case of strep.  I guess that's what happens when you have the stress of needing two major redesigns done in two weeks, a Perl proxy app done in two days, three clients asking for meetings in as many days, a broken furnace, defending against a speeding ticket, a dentist appointment, errors in my credit report, errors in my driving record, being overcharged by insurance and utilities, ... and the list goes on.  I guess it was just a matter of time.

I think I've fixed my regex problem now.

if (length($line)) {$line =~ s/.../.../egi;}
if (length($line)) {$line =~ s/.../.../egi;}

$line doesn't only have to exist, it also appears to require a non-zero length to be used in a regular expression.  In the second line, I can see how that might happen -- the first regexp might remove everything from $line.  I still don't see how that could ever happen at the first line, but it doesn't matter... as long as it works.  And it appears to be working now.

Thanks for all of your help.

BTW, $include_file should always exist.  The first time it is named explicitly by hard-coded variables.  Each additional time, it is the result of a match from these two lines.  And, yes, grab() is recursive.  It reads a server-side include and pastes the contents into the output.  If the include contains includes, then those are also translated.  Unfortunately, I couldn't get that first case to work where it executes inc and asp files.  I was hoping to be able to have asp parsed, but that doesn't seem possible unless it is a whole, independent file.  Does anyone know if IIS can send Perl output through the asp parser?


Sincerely,
 
Tom Anderson
CEO, Order amid Chaos, Inc.
http://www.oac-design.com

RE: Another regexp problem

Sorry to hear about the stress, Tom.  We are not superstitious people, but, my wife says that she suspects that trouble events come in 3's.  You've corrupted that theory.  Sounds like you are getting them by the dozens!  Hang in there and don't forget to enjoy life sometime..... go Boating or something ;^)

I don't play with IIS, so I am sorry, I can't help you over there in MicroSoft land.


 
 
 keep the rudder amid ship and beware the odd typo

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close