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

script:
open (LOG, ">> $file"); $_ = $msg; print LOG "$_ :: $ENV{REMOTE_ADDR}\n"; print "\$_ is $_"; close (LOG);
Before setting $_ to hold my $msg the $msg was not getting sent to the log file. All that was sending was the IP address. Someone mentioned in the CB that this was because the variable $msg was not directly from the server (or something like that). The script runs now but I was wondering if anyone could explain why I couldn't just use this instead?
open (LOG, ">> $file"); print LOG "$msg :: $ENV{REMOTE_ADDR}\n"; print "\$msg is $msg"; close (LOG);


"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid

Replies are listed 'Best First'.
(jeffa) Re: Sending variables to a log file
by jeffa (Bishop) on Jun 22, 2003 at 23:50 UTC
    Sounds to me like you are describing the wrong symptom. Perhaps the first time you tested your problem, $msg was never defined. Then you tried your work around and this time $msg was set. Otherwise $_ would also be undefined. Think about it, given this expression:
    $_ = $msg;
    how can $_ not be undefined (or contain the empty string) if $msg is undefined (or contains the empty string)? Change it to the latter snippet, i'll bet that you get the same results as the former (given that you really are setting $msg before hand).

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      That's what I was thinking but $msg was defined.
      $_ = $msg; print LOG "$msg :: $ENV{REMOTE_ADDR}\n"; print "\$msg is $msg"; close (LOG);
      The test print of $msg did print out whatever I expected to be in there, it just never showed up in logs. That's why I posted this, it's too confusing because what should have worked didn't and now it does work and there's no reason for it to be any different. ahhh, time for some Mountain Dew I think :)

      "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

      sulfericacid