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

Does it make sense that this code:
### test print "1 @line"; $1=""; print "2 @line"; exit; ### end test
which I stuck in the middle of my script, should produce only this:

1 <a href = "http://polisource.com">12345(2345678901234)nopqrst</a>

The script assigned <a href = "http://polisource.com">12345(2345678901234)nopqrst</a> to $line[0], and the rest of the array is empty. Should assigning a null string to a backreference variable clear an array?

This is just something I discovered in my debugging process. I don't really have to use $1="", but I do have the problem of an array disappearing after a block that uses a back reference, and it might be related.

Replies are listed 'Best First'.
Re: Backreference assignment clears array
by mojotoad (Monsignor) on Jan 24, 2003 at 07:31 UTC
    The assignment to $1, a read-only variable, is a fatal error. Your script will not run past that point. (try putting $1=""; right after your shebang line and see what you get).

    Based on your other post, this is also a cgi script.

    The error "Modification of a read-only value attempted at ..." is no doubt appearing in the error log of your web server -- this is where STDERR is directed for cgi applications. Always check that log when developing web applications!

    Matt

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Backreference assignment clears array
by chromatic (Archbishop) on Jan 24, 2003 at 07:00 UTC

    Nope, doesn't make sense. You should at least receive a warning about assigning to a read-only variable. Can you provide more code? (Ten lines that demonstrate the problem on their own should suffice.)

    Do you possibly have a carriage return (\r) or a backspace (\b) banging about somewhere in your printable line?

      I checked every character of the printable line last night. The only hidden thing is that it ends with a chr(10), but I just ran it without the chr(10), and the same thing happened! Does it happen to anyone else? Here is the complete code that I just tried:
      #!/usr/bin/perl ###################################################################### +######## print "Cache-Control: no-cache, must-revalidate\n"; print "Pragma: no-cache\n"; print "Content-type: text/html\n\n"; @line = '<a href = "http://polisource.com">12345(2345678901234)nopqrst +</a>'; ### test print "1 @line"; $1=""; print "2 @line"; exit; ### end test
Re: Backreference assignment clears array
by jepri (Parson) on Jan 24, 2003 at 13:04 UTC
    "Doctor, doctor, it hurts when I do this!"

    "Well, stop doing that"

    ____________________
    Jeremy
    I didn't believe in evil until I dated it.