Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't call method "line" 1

Status
Not open for further replies.

PerlDaniel

Programmer
Apr 27, 2005
10
US
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
 
You have an error in your subroutine get_line. I'm assuming the reason for this subroutine is to get the information piped from STDIN, chomp off any new line characters and return the value so you can do something with it. If so, you'd want this:

Code:
sub get_line {
    print $_[0];
    chomp (my $line =<STDIN>);
    [b]return $line;[/b]
}

- Rieekan
 
looks like a case of dyslexia too:

line$;



I can relate!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top