Input_record_separator problem 
Author Message
 Input_record_separator problem

When this one perl script runs, the following message/error is generated

input_record_separator is not supported on a per-handle basis at
/opt/perl-5.6.0/site_lib/QIP.pl line 110 input_record_separator is not
supported on a per-handle basis at /opt/perl-5.6.0/site_lib/QIP.pl line 112
input_record_separator is not supported on a per-handle basis at
/opt/perl-5.6.0/site_lib/QIP.pl line 110 input_record_separator is not
supported on a per-handle basis at /opt/perl-5.6.0/site_lib/QIP.pl line 112
input_record_separator is not supported on a per-handle basis at
/opt/perl-5.6.0/site_lib/QIP.pl line 110 Error Code = 0
input_record_separator is not supported on a per-handle basis at
/opt/perl-5.6.0/site_lib/QIP.pl line 112 "PRIMARY ADMIN" "griffde1"
"SECONDARY ADMIN" "wilkiag1" "VLAN" "" "TERNARY ADMIN" "nguyebt1"
"QUATERNARY ADMIN" "" "QUINARY ADMIN" "" "SENARY ADMIN" ""

This script is run from a cron job and the above message is heavily
repeated.

The output right now looks like:

128.244.1.0/24     CORE         # BIX      BIX     :BIX:BIX:BIX:BIX::APLNIS
FastEthernet Backbone

It should appear similar to:

128.244.1.0/24     CORE         # abc xyz     :cdf:BIX:BIX:BIX::APLNIS
FastEthernet Backbone where abc, etc is a username pulled from the database
the script is running against.

The perl script that the error complains the problem is in is below.  Below
that is the other perl script that references this script.

Any advice on what I need to do in order to fix this error would be
extremely appreciated since right now I have no idea.

Thanks,

Bill

# $Id: QIP.pl,v 1.39 2000/12/14 13:49:36 smithwe1 Exp $

use strict;
use FileHandle;
use IPC::Open3;
use Term::ReadKey;
use Text::CSV_XS;
use String::Random qw(random_string);

my ($person_file) = "/opt/dsman/mdw/person2.dat";

my $CON_Id = "ContactID";
my $CON_Last = "LastName";
my $CON_First = "FirstName";
my $CON_Phone = "PhoneNumber";
my $CON_Pager = "PagerNumber";
my $CON_Email = "EmailAddress";

sub BIXprivs {
 my $fh = $_[0];

 printf $fh "Domain,\"jhuapl.edu\",,True\n";
 printf $fh "AddressRange,,\"128.244.0.0 - 128.244.255.255\",False\n";
 printf $fh "Subnet Organization,\"APL\",,False\n";
 printf $fh "Subnet Organization,\"APL-external\",,False\n";
 printf $fh "Subnet Organization,\"APL-perimeter\",,False\n";

Quote:
}

sub dslookup {
 my $bisd_id = $_[0];

 my ($last, $first, $phone, $pager, $email, $ou);

 my ($pat) =
sprintf("^.{8}(.{25})(.{15}).{113}AA.{163}(.{4}).{145}(.{4}).{4}%-8.8s",
    uc($bisd_id));

 $pager = "";

 if (!defined(open(PERSON,$person_file))) {
  printf STDERR "$!\n";
  return undef;
 }

 while (<PERSON>) {
  if (/$pat/) {
   ($last, $first, $ou, $phone) = ($1, $2, $3, $4);
   $last =~ tr/ //d;
   $first =~ tr/ //d;
   $ou =~ tr/ //d;
   last;
  }
 }

 close (PERSON);

 return ($last,$first,$phone,$pager,$email,$ou) if defined($last);
 return undef;

Quote:
}

sub QIPENV {
 die "QIP environment not set\n" if (!defined($ENV{QIPHOME}));
 autoflush STDOUT 1;
 autoflush STDERR 1;

Quote:
}

sub getpass {
 my $prompt = $_[0];

 my $pass;

 ReadMode "noecho";
 print $prompt;
 chop($pass = <STDIN>);
 print "\n";
 ReadMode "normal";
 return ($pass);

Quote:
}

sub getuserpass {
 my $username;
 my $pass;

 if (defined($ENV{QIPMANPASS})) {
  $username = "qipman";
  $pass = $ENV{QIPMANPASS};
  return ($username, $pass);
 }

 $username = (getpwuid( $< ))[0];

 if (defined($ENV{QIPPASS})) {
  $pass = $ENV{QIPPASS};
 } else {
  $pass = getpass("Password: ");
 }
 return ($username, $pass);

Quote:
}

sub doqip {
 my $fh  = $_[0];
 my $pass = $_[1];
 my $cmd  = $_[2];
 my $args = $_[3];

 my $QIP = new FileHandle;

 my $pid = open3($QIP, $fh, ">&STDERR", "$cmd $args");

 input_record_separator $fh ": ";
 chomp($_ = ReadLine(1, $fh));
 input_record_separator $fh "\n";

 if (/^Enter database password$/) {
  print $QIP "$pass\n";
 } else {
  print "$_: ";
 }
 return $pid;

Quote:
}

sub getqipadmins {
    my $user = $_[0];
    my $pass = $_[1];
    my $ADMINS = $_[2];
    my $CREATE = $_[3];

    my $QIPOUT = new FileHandle;
    doqip(*QIPOUT, $pass, "qip-getadminlst", "-u $user");

    while (<QIPOUT>) {
 my $csv = Text::CSV_XS->new({'sep_char' => ' '});

 $_ =~ tr/ //s;
 die "$0: getadminlst failed: $_\n"
  unless ($csv->parse($_) &&
   ((my ($admin) = $csv->fields()) == 1));
 $ADMINS->{$admin} = undef;
    }
    undef $QIPOUT;

    if (defined($CREATE)) {
 my $SUBNETS = new FileHandle;
 doqip(*SUBNETS, $pass,
  "qip-getsubnetlst", "-u $user -t network -a 128.244.0.0");

 while (<SUBNETS>) {
     my $csv = Text::CSV_XS->new({'sep_char' => ' '});

     $_ =~ tr/ //s;
     die "$0: getsubnetlst failed: $_\n"
  unless ($csv->parse($_) &&
   ((my($sub_name,$sub_addr) = $csv->fields()) == 7));

     my $con1 = my $con2 = my $con3 =undef;

     doqip(*QIPOUT, $pass,
       "qip-getudflst", "-u $user -c subnet -t value -a $sub_addr");

     while (<QIPOUT>) {
  $_ =~ tr/ //s;
  die "$0: getudflst failed: $_\n"
   unless ($csv->parse($_) &&
    ((my($attr,$val) = $csv->fields()) == 2));
  if ($attr eq "PRIMARY ADMIN") {$con1 = $val; next};
  if ($attr eq "SECONDARY ADMIN") {$con2 = $val; next};
  if ($attr eq "TERNARY ADMIN") {$con3 = $val; next};
     }
     undef $QIPOUT;

     if ($con1 eq "") {
  warn
"ignoring secondary admin $con2 without primary for subnet: $sub_addr\n"
    if ($con2 ne "");
  next;
     }

     if ($con1 eq $con2) {
  warn "ignoring duplicated admin $con1 for subnet: $sub_addr\n";
  next;
     }

     if ($con1 eq $con3) {
  warn "ignoring duplicated admin $con1 for subnet: $sub_addr\n";
  next;
     }

     if (defined($ADMINS->{$con1})) {
  $ADMINS->{$con1} .= " $sub_name,$sub_addr";
     } else {
  $CREATE->{$con1} = undef if !exists($ADMINS->{$con1});
  $ADMINS->{$con1} = "$sub_name,$sub_addr";
     }

     next if ($con2 eq "");

     if (defined($ADMINS->{$con2})) {
  $ADMINS->{$con2} .= " $sub_name,$sub_addr";
     } else {
  $CREATE->{$con2} = undef if !exists($ADMINS->{$con2});
  $ADMINS->{$con2} = "$sub_name,$sub_addr";
     }

     next if ($con3 eq "");

     if (defined($ADMINS->{$con3})) {
  $ADMINS->{$con3} .= " $sub_name,$sub_addr";
     } else {
  $CREATE->{$con3} = undef if !exists($ADMINS->{$con3});
  $ADMINS->{$con3} = "$sub_name,$sub_addr";
     }
 }
 undef $SUBNETS;
    }

Quote:
}

sub setqipadmins {
    my $username = $_[0];
    my $pass  = $_[1];
    my $ADMINS  = $_[2];
    my $CREATE  = $_[3];
    my $tmpfilename1 = $_[4];
    my $tmpfilename2 = $_[5];

    foreach my $admin (keys(%{$ADMINS})) {
 my ($last,$first,$phone,$pager,$email,$ou) = dslookup($admin);

 if (!defined($last)) {
  warn "Warning: Admin $admin not found in directory\n"
   if (($admin ne "qipman") && ($admin ne "dfltbixuser") &&($admin ne
"dfltuser") &&
      ($admin ne "guest"));
  next if defined $tmpfilename1;
  $last = $first = $phone = $pager = $email = $ou = "";
 }

 if (exists($CREATE->{$admin})) {
  if ($admin !~ /[a-z]{2,7}[1-9]/) {
      if (!defined $tmpfilename1) {
   die "invalid username $admin\n";
      } else {
   warn "invalid username $admin\n";
   next;
      }
  }

  my $new_pass = random_string("Csssssss");
  my ($new_user) = join(',',
   ($admin, $new_pass, $last, $first, $email));

  print "Creating admin $admin\n";

  my ($QIPOUT) = new FileHandle;
  my ($pid) = doqip(*QIPOUT, $pass, "qip-admin",
   "-u $username -a clone -l dfltuser -n $new_user");

  while (<QIPOUT>) {
   print;
  }
  undef $QIPOUT;

  waitpid($pid,0);
  my $rc = $? >> 8;

  if ($rc != 0) {
   warn "Failed to create admin $admin: error $rc\n";
   exit $rc if !defined $tmpfilename1;
   next;
  }
  print "Password set to $new_pass\n" if !defined $tmpfilename1;
 }

 next if !defined $tmpfilename1;

 my ($tmpfilename,$TMP1,$TMP2);
 if ($tmpfilename1 eq "") {
  $tmpfilename = "./$admin.apf";
 } else {
  $tmpfilename = $tmpfilename1;
 }
 open(TMP1,">$tmpfilename") ||
    die "Couldn't create $tmpfilename : $!";
 open(TMP2,">$tmpfilename2") ||
    die "Couldn't create $tmpfilename2 : $!"
      if defined($tmpfilename2);

 my $QIPOUT = new FileHandle;
 doqip(*QIPOUT, $pass,
   "qip-getadminprof", "-u $username -l $admin");

 while (<QIPOUT>) {
  if (!defined($tmpfilename2)) {
   print TMP1;
   next;
  }

  next if /^Subnet,/;
  next if /^Subnet Organization,/;
  next if /^AddressRange,/;
  next if /^Domain,/;

  if (/^$CON_Last=/) {
   print TMP2;
   print TMP1 ($last eq "") ? $_ :
      "$CON_Last=$last\n";
   next;
  }

  if (/^$CON_First=/) {
   print TMP2;
   print TMP1 ($first eq "") ? $_ :
      "$CON_First=$first\n";
   next;
  }

  if (/^$CON_Phone=/) {
   print TMP2;
   print TMP1 ($phone eq "") ? $_ :
      "$CON_Phone=$phone\n";
   next;
  }

  if (/^$CON_Pager=/) {
   print TMP2;
   print TMP1 ($pager eq "") ? $_ :
      "$CON_Pager=$pager\n";
   next;
  }

  if (/^$CON_Email=/) {
   print TMP2;
   print TMP1 ($email eq "") ? $_ :
      "$CON_Email=$email\n";
   next;
  }

  if (/^BusinessUnit=/) {
   print TMP1 ($ou eq "") ? $_ :
      "BusinessUnit=$ou\n";
   next;
  }

  print TMP1;

  if (/^ManagedList:/) {
   if (defined $ADMINS->{$admin}) {
    foreach (split(' ',$ADMINS->{$admin})) {
        printf TMP1 "Subnet,%s,False\n", $_;
    }
   }
   if ($ou eq "BIX") {
    BIXprivs(*TMP1);
   } else {
    if (!defined($ADMINS->{$admin}) &&
     ($admin ne "dfltuser")) {
      warn "Useless admin $admin\n";
    }
   }
  }
 }
 close QIPOUT;

 close TMP1;

 next if !defined($tmpfilename2);

 close TMP2;

 if ($last ne "") {
  my ($contact_id) = undef;

  doqip(*QIPOUT, $pass,
   "qip-getcontactlst", "-u $username -t $tmpfilename2");

  while (<QIPOUT>) {
          my $csv = Text::CSV_XS->new({'sep_char' => ' '});

   $_ =~ tr/\t/ /;
   $_ =~ tr/ //s;
   die "$0: getcontactlst failed: $_\n"
    unless ($csv->parse($_) &&

   if (!defined($contact_id)) {

     $contact_id = "";
    } else {
     $contact_id = $fields[0];
    }
   }
  }
  close QIPOUT;

  if
...

read more »



Sat, 03 Jul 2004 21:31:21 GMT  
 Input_record_separator problem

Quote:

> input_record_separator?$fh?":?";
> chomp($_?=?ReadLine(1,?$fh));
> input_record_separator?$fh?"\n";

the input record separator is global. You can set it with the $/ variable:

$/ = ": ";
chomp($_ = ReadLine(1,$fh));
$/ = "\n";



Sun, 04 Jul 2004 08:37:45 GMT  
 Input_record_separator problem
Quote:

> When this one perl script runs, the following message/error is
> generated

> input_record_separator is not supported on a per-handle basis at

[snip]

That's because record seperator is only supported as a global variable.

[snip]

Quote:
> Any advice on what I need to do in order to fix this error would be
> extremely appreciated since right now I have no idea.

Yes.  First, break QIP.pl into multiple smaller files, one per function.
Then, only require those smaller files that you need. Second, your
functions are too long.  Any function which takes more than a page and a
half should be split into smaller functions.

Third, your understnading of how FileHandle objects work is wrong. For
example, you have in many places, stuff like:

    my $QIPOUT = new FileHandle;
    doqip(*QIPOUT, $pass, "qip-getadminlst", "-u $user");

$QIPOUT is a lexical variable.  *QIPOUT is a package variable.

Furthermore, even if you ommited the 'my', which would make $QIPOUT a
package variable, it *still* would not be the same thing as the file
that *QIPOUT would be.  When a typeglob, like *FOO, is opened as a file,
the IO data is stored in *FOO{IO}.  But a package scalar is stored in a
different part of the type... *FOO{SCALAR}.  These parts are totally
unrelated to each other.

This should be something like:
   my $QIPOUT = new FileHandle;
   doqip($QIPOUT, $pass, ..... );

See the difference?  After declaring the variable, I *USE* that
variable, instead of declaring one variable and using a different,
completely unrelated variable.

Next item, your actual problem...

 input_record_separator $fh ": ";
 chomp($_ = ReadLine(1, $fh));
 input_record_separator $fh "\n";

This would have to be:
  { local $/ = ": ";
    chomp($_ = ReadLine(1, $fh));
  }

Next... you have lots and lots of things in your script which could be
made better, and are *probably* broken as things are right now.
However, I'm not going to be the one to fix them.  Your code is much too
ugly.

HTH, HAND.

--
DATA COMPRESSION: What you get when you squish an android



Mon, 05 Jul 2004 13:31:00 GMT  
 Input_record_separator problem

Quote:

> Next... you have lots and lots of things in your script which could be
> made better, and are *probably* broken as things are right now.

And I would recommend leaving FileHandle and using IO::File instead.
IO::File is more "modern" in several respects.  And you can set
things like input record separator on a per-handle basis if your
handles are IO::File objects.

--
John Douglas Porter

Home is where you hang your head.



Tue, 06 Jul 2004 06:20:15 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Input_record_separator problem

2. input_record_separator Problem

3. BatchMove and accents

4. Help ! Need driver !

5. BMP files

6. problem with $INPUT_RECORD_SEPARATOR

7. INPUT_RECORD_SEPARATOR - why AWK better than Perl?

8. Aware of Input_Record_Separator?

9. $/ and input_record_separator

10. input_record_separator error

11. $INPUT_RECORD_SEPARATOR

12. Different input_record_separator for different files.

 

 
Powered by phpBB® Forum Software