|
Prev: convert Vbscript to Perl code
Next: I/O open()
From: jcharth on 17 Jan 2007 10:40 Hello I am downloading a mime from a web server using lwp my $fullpage = $ua->request($req)->as_string; then i was trying to extract the text body of the mesage using MIME tools but i cant seem get this to work when i do $parser->parse_data($fullpage) i get Can't use string ("MIME::Parser") as a HASH ref while "strict refs" in use at /usr/lib/perl5/site_perl/5.8.0/MIME/Parser.pm line 279. not sure what i am doing wrong thanks.
From: Paul Lalli on 17 Jan 2007 12:30 jcharth(a)hotmail.com wrote: > Hello I am downloading a mime from a web server using lwp > my $fullpage = $ua->request($req)->as_string; > then i was trying to extract the text body of the mesage using MIME > tools but i cant seem get this to work > when i do > $parser->parse_data($fullpage) > i get > Can't use string ("MIME::Parser") as a HASH ref while "strict refs" in > use at /usr/lib/perl5/site_perl/5.8.0/MIME/Parser.pm line 279. > > not sure what i am doing wrong Neither are we, and it's pretty hard to guess without seeing the *actual* code. I refuse to believe that those two simple lines are enough to cause the error. Please post a SHORT but COMPLETE script that demonstrates the error you're having. Also, please read the Posting Guidelines for this group, which would have told you to do that in the first place. Paul Lalli
From: Mark Clements on 17 Jan 2007 16:00 jcharth(a)hotmail.com wrote: > Hello I am downloading a mime from a web server using lwp > my $fullpage = $ua->request($req)->as_string; > then i was trying to extract the text body of the mesage using MIME > tools but i cant seem get this to work > when i do > $parser->parse_data($fullpage) > i get > Can't use string ("MIME::Parser") as a HASH ref while "strict refs" in > use at /usr/lib/perl5/site_perl/5.8.0/MIME/Parser.pm line 279. > > not sure what i am doing wrong > thanks. > How have you created $parser? use strict; use warnings; use MIME::Parser; my $parser = MIME::Parser->new(); would be usual (see perldoc MIME::Parser). Have you done something like: mark(a)owl:~$ cat testmimeparser.pl use strict; use warnings; use MIME::Parser; my $parser = "MIME::Parser"; $parser->parse_data("this is not a test"); mark(a)owl:~$ perl testmimeparser.pl Can't use string ("MIME::Parser") as a HASH ref while "strict refs" in use at /usr/share/perl5/MIME/Parser.pm line 279. As Paul says, you need to check out the posting guidelines - you haven't given us much to go on. Mark
From: jcharth on 18 Jan 2007 22:55 Looks like something is fishy in my perl module #!/usr/bin/perl use MIME::Parser; my $parser = "MIME::Parser"; #$parser->parse_data("$fullpage"); $parser->parse_data("fullpage"); #dump_entity($parser); Content-type:text/plain Can't use string ("MIME::Parser") as a HASH ref while "strict refs" in use at /usr/lib/perl5/site_perl/5.8.0/MIME/Parser.pm line 279.
From: Sherm Pendley on 18 Jan 2007 23:33 jcharth(a)hotmail.com writes: > Looks like something is fishy in my perl module No, it looks like you haven't read *anything* about how to create objects and call their methods in Perl. Neither have you read the example at the top of the module you're using, MIME::Parser. I suggest: perldoc perlboot perldoc perltoot perldoc perltooc perldoc perlbot And, of course: perldoc MIME::Parser > #!/usr/bin/perl > > use MIME::Parser; > my $parser = "MIME::Parser"; Now $parser is a string. Not an object, just a plain old string. > #$parser->parse_data("$fullpage"); > $parser->parse_data("fullpage"); Calling a method using a string, as you're doing here, results in a class method being called, the same as if you had written it like this: MIME::Parser->parse_data('fullpage'); In a class method, $self is a string containing the class name. In an object method, $self is a blessed reference containing instance data. Parse_data() is an object method, so it expects a blessed reference; but since you're calling it as a class method, it's receiving a string instead. Hence the error: > Can't use string ("MIME::Parser") as a HASH ref while "strict refs" in > use at /usr/lib/perl5/site_perl/5.8.0/MIME/Parser.pm line 279. sherm-- -- Web Hosting by West Virginians, for West Virginians: http://wv-www.net Cocoa programming in Perl: http://camelbones.sourceforge.net
|
Pages: 1 Prev: convert Vbscript to Perl code Next: I/O open() |