Re: working example File::Taill
From: Richard Morse (remorse_at_partners.org)
Date: 03/19/04
- Next message: Richard Morse: "Re: working example File::Taill"
- Previous message: Richard Morse: "Re: problem with pack and output to binary files"
- In reply to: Jim roos: "working example File::Taill"
- Next in thread: Paul Lalli: "Re: working example File::Taill"
- Reply: Paul Lalli: "Re: working example File::Taill"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 19 Mar 2004 15:22:14 -0500
In article <2gI6c.41274$HQ6.2880664@phobos.telenet-ops.be>,
"Jim roos" <Jimroos@uunet.be> wrote:
> Hi there,
>
> As a newbie to perl i have problems to get the following script to run
> properly.
> I get the message
> Global symbol "$file" requires explicit package name at test.pl line 09
> Global symbol "$line" requires explicit package name at test.pl line 10
> Can someone help me out please...
>
>
> #!/usr/bin/perl
>
> use MIME::Parser;
> use strict;
> use File::Tail;
>
>
>
> $file=File::Tail->new("/home/noc/procmail");
> while (defined($line=$file->read)) {
> print "$line";
> }
Thank you for using strict!
Try this:
#!/usr/bin/perl
use warnings;
use strict;
use MIME::Parser;
use File::Tail;
my $file = File::Tail->new("/home/noc/procmail");
while(my $line = $file->read) {
print "$line";
}
The error messages are because you need to explicitly tell Perl what the
scoping of your variables is: I've shown you how to create a lexically
scoped variable, using the 'my' in front of the variable declaration.
You could also use 'local', or 'our', although they have different
meanings, which you should look up in your reference.
Also, the 'defined()' test is superfluous (I think?) -- the '=' operator
returns the value assigned, and undef is false...
HTH,
Ricky
- Next message: Richard Morse: "Re: working example File::Taill"
- Previous message: Richard Morse: "Re: problem with pack and output to binary files"
- In reply to: Jim roos: "working example File::Taill"
- Next in thread: Paul Lalli: "Re: working example File::Taill"
- Reply: Paul Lalli: "Re: working example File::Taill"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|