Loading ...
Sorry, an error occurred while loading the content.

Sub problem

Expand Messages
  • sxj0779@afs1.njit.edu
    How i can pass a scalar variable to a subroutine. print Input file name: ; chomp($infilename = ); print Output file name: ; chomp($outfilename =
    Message 1 of 2 , Apr 2, 2001
    • 0 Attachment
      How i can pass a scalar variable to a subroutine.

      print "Input file name:";
      chomp($infilename = <stdin>);
      print "Output file name:";
      chomp($outfilename = <stdin>);
      open (IN, $infilename) || die "cannot open $infilename for reading:
      $!";
      open (OUT, ">$outfilename") || die "cannot create $outfilename: $!";
      ..............
      more code

      &comma(i want to pass $outputfilename to sub comma);

      sub comma{


      }
    • Damien Carbery
      sub comma { my $OutputFileName = shift; print In comma function: $OutputFileName n ; } Call with: comma( $outfilename ); You don t need the & before comma
      Message 2 of 2 , Apr 2, 2001
      • 0 Attachment
        sub comma
        {
        my $OutputFileName = shift;

        print "In comma function: $OutputFileName\n";
        }

        Call with:
        comma( $outfilename );

        You don't need the '&' before 'comma' unless you are using an old
        version of Perl.

        --- In perl-beginner@y..., sxj0779@a... wrote:
        > How i can pass a scalar variable to a subroutine.
        >
        > print "Input file name:";
        > chomp($infilename = <stdin>);
        > print "Output file name:";
        > chomp($outfilename = <stdin>);
        > open (IN, $infilename) || die "cannot open $infilename for reading:
        > $!";
        > open (OUT, ">$outfilename") || die "cannot create $outfilename: $!";
        > ..............
        > more code
        >
        > &comma(i want to pass $outputfilename to sub comma);
        >
        > sub comma{
        >
        >
        > }
      Your message has been successfully submitted and would be delivered to recipients shortly.