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

I know I have redefined the default record separator before in my code and had it work but not in this little script I am working on:
use strict; use warnings; my $prefix = shift @ARGV; my $cpu = shift @ARGV; my $sched_name = shift @ARGV; my $job_name = shift @ARGV; open (CFG, "/home/mt71124/scripts/maestro_inst.txt") or die ("Error op +ening config file: $1"); $/ = &; while (<CFG>) { next if /^\#/; next unless ($_ =~ /^$prefix\s+$cpu\s+$sched_name\s+$job_name\s+(\ +w+)/); print; exit; } print "Contact the application oncall for this prefix to remediate./n +The workstation is $cpu the schedule is $sched_name the job is $job_n +ame\n";
Here is what I am getting:
syntax error at ./maestro_inst.pl line 16, near ") {" syntax error at ./maestro_inst.pl line 21, near "}" Execution of ./maestro_inst.pl aborted due to compilation errors.
Thanks for any help.

Replies are listed 'Best First'.
Re: Help with default record separator
by almut (Canon) on Feb 20, 2008 at 18:56 UTC

    $/ = "&";

Re: Help with default record separator
by jwkrahn (Abbot) on Feb 20, 2008 at 19:50 UTC
    To elaborate on what is causing your problem, the line  $/ = &; is trying to run the subroutine  ';' with the argument  'while' and assign its return value to  $/ and you don't have a semicolon at the end of that statement.    See perlsub on why you should not use the ampersand to call subroutines in Perl.