PerlDaniel
Programmer
This is a newbie question. Please let me know how to fix this error.
tia
sub get_line {
print $_[0];
chomp (my $line =<STDIN>);
line$;
}
my $source = &get_line ("which source file? ");
open IN, $source or die "can't open '$source' for input: $!";
my $dest =&get_line ("what destination file? ");
die "won't overwrite existing file!"
if -e $dest;
open OUT, ">$dest" or die "can't open '$dest' for output: $!";
my $pattern = &get_line ("what search pattern: ");
my $replace = &get_line ("what replacement string: ");
while (<IN>) {
s/$pattern/$replace/g;
print OUT $_;
}
which source file? test.txt
Can't call method "line" without a package or object reference at ex11.pl line
9, <STDIN> line 1 (#1)
(F) You used the syntax of a method call, but the slot filled by the
object reference or package name contains an expression that returns a
defined value which is neither an object reference nor a package name.
Something like this will reproduce the error:
$BADREF = 42;
process $BADREF 1,2,3;
$BADREF->process(1,2,3);
Uncaught exception from user code:
Can't call method "line" without a package or object reference at ex11.p
l line 9, <STDIN> line 1.
main::get_line('which source file? ') called at ex11.pl line 12
tia
sub get_line {
print $_[0];
chomp (my $line =<STDIN>);
line$;
}
my $source = &get_line ("which source file? ");
open IN, $source or die "can't open '$source' for input: $!";
my $dest =&get_line ("what destination file? ");
die "won't overwrite existing file!"
if -e $dest;
open OUT, ">$dest" or die "can't open '$dest' for output: $!";
my $pattern = &get_line ("what search pattern: ");
my $replace = &get_line ("what replacement string: ");
while (<IN>) {
s/$pattern/$replace/g;
print OUT $_;
}
which source file? test.txt
Can't call method "line" without a package or object reference at ex11.pl line
9, <STDIN> line 1 (#1)
(F) You used the syntax of a method call, but the slot filled by the
object reference or package name contains an expression that returns a
defined value which is neither an object reference nor a package name.
Something like this will reproduce the error:
$BADREF = 42;
process $BADREF 1,2,3;
$BADREF->process(1,2,3);
Uncaught exception from user code:
Can't call method "line" without a package or object reference at ex11.p
l line 9, <STDIN> line 1.
main::get_line('which source file? ') called at ex11.pl line 12