in reply to Re^3: System Command Issues
in thread System Command Issues

Hmm. I've tried that code as well. The "strict" and "warnings" commands are very helpful indeed. It's pointing out some mysterious errors on a particular line:

Possible unintended interpolation of @whatever in string at myscript.pl line 158.
Possible unintended interpolation of @whatever in string at myscript.pl line 158.
Global symbol "@whatever" requires explicit package name at myscript.pl line 158.
Global symbol "@whatever" requires explicit package name at myscript.pl line 158.
Execution of myscript.pl aborted due to compilation errors.

The line in question is a simple print command immediately following the last line of the code I am posting. Line 157 is the system() command causing all the trouble...

use strict; use warnings; my $address = 'myemail@whatever.com'; my $subject = 'Comments Version: $version ID: $ID'; # backslash the @ sign in the address $address =~ s/@/\\$1/g; system( "mail $address -s $subject < blah6.txt" ) == 0 or die "mail failed: $?";

By the way, $ID is a 10-character alphanumeric string, and $version is something like "5.3" or "5.4" or "Nightly" (sans quotes, of course).

Any thoughts? I appreciate all the help so far, by the way. I'm a self-professed perl newb, and can use all the suggestions I can get. Thanks!

--blanket

Replies are listed 'Best First'.
Re^5: System Command Issues
by tlm (Prior) on Jun 09, 2005 at 14:27 UTC

    This should work

    use strict; use warnings; my $address = 'myemail@whatever.com'; my $subject = "Comments Version: $version ID: $ID"; system( "mail $address -s '$subject' < blah6.txt" ) == 0 or die "mail failed: $?";
    I made three changes to the code you posted:
    1. Eliminated the s/// line since escaping is required only in a double-quoted context, but above the @ is being given in a single-quoted context, so no variable interpolation occurs.
    2. I put the RHS of the assignment to $subject in double quotes, because in this case we do want interpolation (of $Version and $ID).
    3. In the argument to system I put $subject in single quotes, because otherwise the shell would interpret the various words in $subject as different arguments, as opposed to the single argument for -s
    This is definitely a little quoting workout! You may want to read the docs on quoting, to best make sense of the above.

    the lowliest monk

      Ok. The code seems to have generated further errors.

      use strict; use warnings; my $address = 'myemail@whatever.com'; my $subject = "Comments Version: $version ID: $ID"; system( "mail $address -s '$subject' < blah6.txt" ) == 0 or die "mail failed: $?";

      Generates:
      Variable "$ID" is not imported at myscript.pl line 137. Variable "$version" is not imported at myscript.pl line 137. Possible unintended interpolation of @whatever in string myscript.pl l +ine 154. Possible unintended interpolation of @whatever in string at myscript.p +l line 154. Global symbol "$ID" requires explicit package name at myscript.pl line + 137. Global symbol "$version" requires explicit package name at myscript.pl + line 137. Global symbol "@whatever" requires explicit package name at myscript.p +l line 154. Global symbol "@whatever" requires explicit package name at myscript.p +l line 154. Execution of myscript.pl aborted due to compilation errors.

      Any more thoughts? I'm using Perl 5.8.0, if that makes any difference...

      Thanks again!
        <homer>Woohoo!</homer>

        I figured it out. It had to do with how I declared the version and ID vars, and also with the print statement directly after the system command. Many thanks to all who patiently helped me. Time for a coffee!