[25505] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 7749 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 7 18:05:51 2005

Date: Mon, 7 Feb 2005 15:05:17 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 7 Feb 2005     Volume: 10 Number: 7749

Today's topics:
        'Subroutine redefined' annoyance <please_post@nomail.edu>
    Re: 'Subroutine redefined' annoyance <mritty@gmail.com>
    Re: 'Subroutine redefined' annoyance (Anno Siegel)
    Re: 'Subroutine redefined' annoyance <please_post@nomail.edu>
    Re: 'Subroutine redefined' annoyance <please_post@nomail.edu>
    Re: 'Subroutine redefined' annoyance xhoster@gmail.com
        [OT] Re: Perl - permute? <1usa@llenroc.ude.invalid>
    Re: [OT] Re: Perl - permute? <postmaster@castleamber.com>
    Re: [OT] Re: Perl - permute? <1usa@llenroc.ude.invalid>
        [perl-python] text pattern matching, and expressiveness <xah@xahlee.org>
    Re: [perl-python] text pattern matching, and expressive <postmaster@castleamber.com>
        bizarre index() function behavior <ebabin@yahoo.com>
    Re: bizarre index() function behavior <toreau@gmail.com>
    Re: bizarre index() function behavior <1usa@llenroc.ude.invalid>
        CGI - web content into variable <asa@aaelectron.co.uk>
    Re: CGI - web content into variable ioneabu@yahoo.com
    Re: CGI - web content into variable <noreply@gunnar.cc>
    Re: CGI - web content into variable <spamtrap@dot-app.org>
    Re: CGI - web content into variable <1usa@llenroc.ude.invalid>
    Re: CGI - web content into variable <andy@aaelectron.co.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 7 Feb 2005 20:29:06 +0000 (UTC)
From: bill <please_post@nomail.edu>
Subject: 'Subroutine redefined' annoyance
Message-Id: <cu8j2i$ltl$1@reader2.panix.com>


If I uncomment the 'use SlicesDices ...' line below, running the
script/module from the command line results in a 'Subroutine quux
redefined' warning.

  #!/usr/bin/perl -w use strict;
  # SlicesDices.pm

  package SlicesDices;
  use base 'Exporter';

  BEGIN { push @SlicesDices::EXPORT, 'quux' }
  sub quux {
    local $| = 1;
    print "hello from quux\n";
    return;
  }

  return 1 if (caller(0))[7];

  package main;

  # use SlicesDices;  # results in a 'redefined' warning
  # quux();

  __END__


The problem seems to be that the 'use SlicesDices' statement is
causing the file to be read again.  Is there any reasonably scalable
way to import the subs in @SlicesDices::EXPORT to the main namespace
without using "use", and not causing the redefinition to take place?

Thanks!

bill



------------------------------

Date: Mon, 07 Feb 2005 20:51:38 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: 'Subroutine redefined' annoyance
Message-Id: <uxQNd.8338$sR5.143@trndny05>

"bill" <please_post@nomail.edu> wrote in message
news:cu8j2i$ltl$1@reader2.panix.com...
>
> If I uncomment the 'use SlicesDices ...' line below, running the
> script/module from the command line results in a 'Subroutine quux
> redefined' warning.
>
>   #!/usr/bin/perl -w use strict;
>   # SlicesDices.pm
>
>   package SlicesDices;
>   use base 'Exporter';
>
>   BEGIN { push @SlicesDices::EXPORT, 'quux' }
>   sub quux {
>     local $| = 1;
>     print "hello from quux\n";
>     return;
>   }
>
>   return 1 if (caller(0))[7];
>
>   package main;
>
>   # use SlicesDices;  # results in a 'redefined' warning
>   # quux();
>
>   __END__
>
 > The problem seems to be that the 'use SlicesDices' statement is
> causing the file to be read again.  Is there any reasonably scalable
> way to import the subs in @SlicesDices::EXPORT to the main namespace
> without using "use", and not causing the redefinition to take place?

use does a require before the import.  You have no reason to do a
require, because the code for both packages is in the same file.
Replace 'use SlicesDices;' with 'import SlicesDices;'

Paul Lalli



------------------------------

Date: 7 Feb 2005 21:01:04 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: 'Subroutine redefined' annoyance
Message-Id: <cu8kug$ljr$3@mamenchi.zrz.TU-Berlin.DE>

bill  <please_post@nomail.edu> wrote in comp.lang.perl.misc:
> 
> If I uncomment the 'use SlicesDices ...' line below, running the
> script/module from the command line results in a 'Subroutine quux
> redefined' warning.
> 
>   #!/usr/bin/perl -w use strict;
>   # SlicesDices.pm
> 
>   package SlicesDices;
>   use base 'Exporter';
> 
>   BEGIN { push @SlicesDices::EXPORT, 'quux' }
>   sub quux {
>     local $| = 1;
>     print "hello from quux\n";
>     return;
>   }
> 
>   return 1 if (caller(0))[7];
> 
>   package main;
> 
>   # use SlicesDices;  # results in a 'redefined' warning
>   # quux();
> 
>   __END__

> The problem seems to be that the 'use SlicesDices' statement is
> causing the file to be read again.  Is there any reasonably scalable
> way to import the subs in @SlicesDices::EXPORT to the main namespace
> without using "use", and not causing the redefinition to take place?

You're mixing two techniques.  Either you have the module code in an
extra *.pm file, then you "use" it.  Or you make the module code part
of the client code.  Then you don't use it.  In the simplest case,
when they are meant to stay together, you can just informally import
things:

    *quux = \ &SlicesDices::quux;

That's exactly what Exporter does, the rest is bells and whistles you
don't really need in a single source file.

If you want to simulate "use SlicesDices arg1 arg2" exactly, replace
the use statement with two BEGIN blocks.  The first one contains the
module code exactly as it would appear in an external file.  The second
one calls the modules ->import method with the intended arguments:

    BEGIN {
        SlicesDices->import( arg1, arg2);
    }

That's the basic recipe.

Anno



------------------------------

Date: Mon, 7 Feb 2005 21:28:02 +0000 (UTC)
From: bill <please_post@nomail.edu>
Subject: Re: 'Subroutine redefined' annoyance
Message-Id: <cu8mh2$3p6$1@reader2.panix.com>

In <cu8kug$ljr$3@mamenchi.zrz.TU-Berlin.DE> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:

>bill  <please_post@nomail.edu> wrote in comp.lang.perl.misc:
>> 
>> If I uncomment the 'use SlicesDices ...' line below, running the
>> script/module from the command line results in a 'Subroutine quux
>> redefined' warning.
>> 
>>   #!/usr/bin/perl -w use strict;
>>   # SlicesDices.pm
>> 
>>   package SlicesDices;
>>   use base 'Exporter';
>> 
>>   BEGIN { push @SlicesDices::EXPORT, 'quux' }
>>   sub quux {
>>     local $| = 1;
>>     print "hello from quux\n";
>>     return;
>>   }
>> 
>>   return 1 if (caller(0))[7];
>> 
>>   package main;
>> 
>>   # use SlicesDices;  # results in a 'redefined' warning
>>   # quux();
>> 
>>   __END__

>> The problem seems to be that the 'use SlicesDices' statement is
>> causing the file to be read again.  Is there any reasonably scalable
>> way to import the subs in @SlicesDices::EXPORT to the main namespace
>> without using "use", and not causing the redefinition to take place?

>You're mixing two techniques.  Either you have the module code in an
>extra *.pm file, then you "use" it.  Or you make the module code part
>of the client code.  Then you don't use it.

Yes, I realize that I'm mixing techniques here.  I'm trying to find
a satisfactory solution to a recurrent situation:  I write a Perl
script to be used from the command line, but soon enough I discover
that I want the script's functionality from within another script.
I don't want to rely on system calls to do this.  I also don't like
the fuss of splitting the original script into a "module file" and
a "wrapper file".

Hence I thought I'd write the original script as a subclass of
Exporter in the first place, and stick it in a a file foo.pm along
with extra code in main to take care of the command-line functionality
(including options parsing and checking, help screens, and whatever
else the command-line script would need to do that the module
wouldn't have to worry about).  I put this foo.pm file in a directory
in @INC, make it executable, and put a suitable symbolic link foo
to it in a directory in my $PATH.  In this way I can call the script
from the command line, or "use" it from another script.

If there's a better way that meet all my neurotic criteria, I'd
love to hear it.

bill



------------------------------

Date: Mon, 7 Feb 2005 21:36:59 +0000 (UTC)
From: bill <please_post@nomail.edu>
Subject: Re: 'Subroutine redefined' annoyance
Message-Id: <cu8n1r$3p6$2@reader2.panix.com>

In <uxQNd.8338$sR5.143@trndny05> "Paul Lalli" <mritty@gmail.com> writes:

>"bill" <please_post@nomail.edu> wrote in message
>news:cu8j2i$ltl$1@reader2.panix.com...
>>
>> If I uncomment the 'use SlicesDices ...' line below, running the
>> script/module from the command line results in a 'Subroutine quux
>> redefined' warning.
>>
>>   #!/usr/bin/perl -w use strict;
>>   # SlicesDices.pm
>>
>>   package SlicesDices;
>>   use base 'Exporter';
>>
>>   BEGIN { push @SlicesDices::EXPORT, 'quux' }
>>   sub quux {
>>     local $| = 1;
>>     print "hello from quux\n";
>>     return;
>>   }
>>
>>   return 1 if (caller(0))[7];
>>
>>   package main;
>>
>>   # use SlicesDices;  # results in a 'redefined' warning
>>   # quux();
>>
>>   __END__
>>
> > The problem seems to be that the 'use SlicesDices' statement is
>> causing the file to be read again.  Is there any reasonably scalable
>> way to import the subs in @SlicesDices::EXPORT to the main namespace
>> without using "use", and not causing the redefinition to take place?

>use does a require before the import.  You have no reason to do a
>require, because the code for both packages is in the same file.
>Replace 'use SlicesDices;' with 'import SlicesDices;'

Worked like a charm.  Thanks!

bill



------------------------------

Date: 07 Feb 2005 21:46:20 GMT
From: xhoster@gmail.com
Subject: Re: 'Subroutine redefined' annoyance
Message-Id: <20050207164620.318$sS@newsreader.com>

bill <please_post@nomail.edu> wrote:

> The problem seems to be that the 'use SlicesDices' statement is
> causing the file to be read again.  Is there any reasonably scalable
> way to import the subs in @SlicesDices::EXPORT to the main namespace
> without using "use", and not causing the redefinition to take place?

Out of curiousity, what do mean by scalable in this context?

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


------------------------------

Date: 7 Feb 2005 17:47:40 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: [OT] Re: Perl - permute?
Message-Id: <Xns95F68226E5F45asu1cornelledu@132.236.56.8>

John Bokma <postmaster@castleamber.com> wrote in
news:Xns95F67572360F4castleamber@130.133.1.4: 

> Arndt Jonasson wrote:
>> 
>> Besides, showing the existence of CPAN _is_ helping, even if you
>> point at the wrong module.
> 
> Sure, pointing at the hammer in a toolbox and then telling it's wrong
> is always a sound way of educating someone.

I don't care about educating anyone on this forum. That's my day job.
You have already conceded that the OP was confused about whether he
wanted a permutation or a combination. I pointed him to a module that
produced permuations. It is not like I pointed him to Text::CVS or
something! 

Second:

John Bokma <postmaster@castleamber.com> wrote in
news:Xns95F5E96902CCBcastleamber@130.133.1.4: 

> A. Sinan Unur wrote:
> 
>> how much effort does it take to write three nested for loops? 
>> After all, that's how we figured it out in 6th grade to get those 
>> combinations.
> 
> Yup, in the 6th grade I understood things quite a lot of people don't
> understand at my current age. Now what? Should I talk to them like
> they are stupid? 

Just for clarification, please note that I did not "_I_ knew how to do
this when I was in sixth grade". _We_, that is, everyone around me knew
how to count when I was in sixth grade. In fact, people world over can
count this way without the need for any sort of education. It is an
amazing thing. I did not claim I was a genius kid for being able to
count by the time I was 11. It seems, on the other hand, that you wanted
to interpret my statement the other way. 

> Or just look at them as being able to do things I can't do
> and show some respect. 

Those who want respect first give respect. I believe in the value of
reciprocating in kind. That way, those who actually go through the
effort of composing a consistent well-thought out question are also able
to get what they deserve. 

Now, coming back to this message:

John Bokma <postmaster@castleamber.com> wrote in
news:Xns95F67572360F4castleamber@130.133.1.4: 

> Imagine everyone posting smart ass replies to every newbie. 

Imagine every newbie posting dumb ass questions at a rate of 100 a
second. 

Sinan.

PS: I am going to seriously try to shut up from this point on. I
promise. 


------------------------------

Date: 7 Feb 2005 20:09:33 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: [OT] Re: Perl - permute?
Message-Id: <Xns95F6900749C76castleamber@130.133.1.4>

A. Sinan Unur wrote:

> John Bokma <postmaster@castleamber.com> wrote in
> news:Xns95F67572360F4castleamber@130.133.1.4: 
> 
>> Arndt Jonasson wrote:
>>> 
>>> Besides, showing the existence of CPAN _is_ helping, even if you
>>> point at the wrong module.
>> 
>> Sure, pointing at the hammer in a toolbox and then telling it's wrong
>> is always a sound way of educating someone.
> 
> I don't care about educating anyone on this forum.

No need to repeat the obvious. By the way, Usenet is not a forum.

> That's my day job.
> You have already conceded that the OP was confused about whether he
> wanted a permutation or a combination. I pointed him to a module that
> produced permuations. It is not like I pointed him to Text::CVS or
> something!

Since you discovered half way in your wrong posting you picked the wrong
module in the first place, there wouldn't have been any difference if
you pointed the OP to Text::CVS. 
 
>> Yup, in the 6th grade I understood things quite a lot of people don't
>> understand at my current age. Now what? Should I talk to them like
>> they are stupid? 
> 
> Just for clarification, please note that I did not "_I_ knew how to do
> this when I was in sixth grade". _We_, that is, everyone around me
> knew how to count when I was in sixth grade. In fact, people world
> over can count this way without the need for any sort of education.

You are mistaken. There are as far as I know even languages in which you
can't even count. They have only words like "some", "few", "a lot". 

> It is an
> amazing thing. I did not claim I was a genius kid for being able to
> count by the time I was 11. It seems, on the other hand, that you
> wanted to interpret my statement the other way. 

So you just wanted to state that the OP was plain stupid, and me too?

>> Or just look at them as being able to do things I can't do
>> and show some respect. 
> 
> Those who want respect first give respect. I believe in the value of
> reciprocating in kind. That way, those who actually go through the
> effort of composing a consistent well-thought out question are also
> able to get what they deserve.

Everybody has some kind of limitations. For the OP it seems that the OP
was not able to express himself (herself) quite well. Should he/she be
punished because you are able to express youself better? Also, English
is not for everybody his/her first language. 

So the OP wrote "permute" in the subject, but asked for combinations.
The example clearly showed that it was allowed to pick an item more then
once. 

From your reply it looked like you reread the posting after you started
on the wrong foot, admitted it and then hit the send button with "do it
yourself". 

>> Imagine everyone posting smart ass replies to every newbie. 
> 
> Imagine every newbie posting dumb ass questions at a rate of 100 a
> second. 

Note I don't consider nor the OP nor you a dumb ass. But if you consider
someone a dumb ass, don't give them a reply like you are one too. 

> PS: I am going to seriously try to shut up from this point on. I
> promise. 

Yeah, saying sorry is difficult. Most people first defend themselve at
great length, and then act like their nose bleeds. Saying sorry takes
less energy, believe me. 

-- 
John                   Small Perl scripts: http://johnbokma.com/perl/
               Perl programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html
                        


------------------------------

Date: 7 Feb 2005 20:30:53 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: [OT] Re: Perl - permute?
Message-Id: <Xns95F69DD37529Casu1cornelledu@132.236.56.8>

John Bokma <postmaster@castleamber.com> wrote in 
news:Xns95F6900749C76castleamber@130.133.1.4:

> A. Sinan Unur wrote:

[ I just don't seem to be able to shut up ]

> 
>> John Bokma <postmaster@castleamber.com> wrote in
>> news:Xns95F67572360F4castleamber@130.133.1.4: 
>> 
>>> Arndt Jonasson wrote:
>>>> 
>>>> Besides, showing the existence of CPAN _is_ helping, even if you
>>>> point at the wrong module.
>>> 
>>> Sure, pointing at the hammer in a toolbox and then telling it's wrong
>>> is always a sound way of educating someone.
>> 
>> I don't care about educating anyone on this forum.
> 
> No need to repeat the obvious. By the way, Usenet is not a forum.

http://www.cogsci.princeton.edu/cgi-bin/webwn?stage=1&word=forum

UseNet is ISA forum.

> Yeah, saying sorry is difficult. 

Dear John,

I am sorry.

Bye,

Sinan



------------------------------

Date: 7 Feb 2005 11:00:51 -0800
From: "Xah Lee" <xah@xahlee.org>
Subject: [perl-python] text pattern matching, and expressiveness
Message-Id: <1107802850.999843.260520@c13g2000cwb.googlegroups.com>

20050207 text pattern matching

# -*- coding: utf-8 -*-
# Python

# suppose you want to replace all strings of the form
# <img src="some.gif" width="30" height="20">
# to
# <img src="some.png" width="30" height="20">
# in your html files.

# you can use the "re" module.

import re

text = r'''<html>
blab blab
<P> look at this <img src="./some.gif" width="30" height="20"> pict
and this one <img class="float-right" src="../that.gif">, both are
beautiful, but also look: <img src ="my.gif">, and sequel
 <img src=
"girl.gif"> yeah! </p>
'''

new = re.sub(r'''src\s*=\s*"([^"]+)\.gif"''', r'''src="\1.png"''',
text)

print new

# the first argument to re.sub is a regex pattern.
# the second argument is the replacement string,
# which can contain captured pattern (the \1)
# the third argument is the text to be checked.
# an optional 4th argument is number of replacement
# to make. If ommitted, it replace all occurances of matches.

# see
# http://python.org/doc/lib/module-re.html

--------------------
# similar code in perl is s///. For example,
$text = "123";
$text =~ s/2/9/;
print $text;

----------------------
In languages human or computer, there's a notion of expressiveness.

English for example, is very expressive in manifestation, witness all
the poetry and implications and allusions and connotations and
dictions. There are a myriad ways to say one thing, fuzzy and warm and
all. But when we look at what things it can say, its power of
expression with respect to meaning, or its efficiency or precision, we
find natural languages incapable.

These can be felt thru several means. A sure way is thru logic,
linguistics, and or what's called Philosophy of Languages. One can also
glean directly the incapacity and inadequacy of natural languages by
studying the artificial language lojban, where one realizes, not only
are natural languages incapable in precision and lacking in efficiency,
but simply a huge number of things are near impossible to express thru
them.

One thing commonly misunderstood in computing industry is the notion of
expressiveness. If a language has a vocabulary of (smile, laugh, grin,
giggle, chuckle, guffaw, cackle), then that language will not be as
expressive, as a language with just (severe, slight, laugh, cry). The
former is "expressive" in terms of fluff, where the latter is
expressive with respect to meaning.

Similarly, in computer languages, expressiveness is significant with
respect to semantics, not syntactical variation.

These two contrasting ideas can be easily seen thru Perl vs Python
languages, and as one specific example of their text pattern matching
abilities.

Perl is a language of syntactical variegations. Python on the other
hand, does not even allow changes in code's indentation, but its
efficiency and power in expression, with respect to semantics (i.e.
algorithms), showcases Perl's poverty in specification.

 Xah
 xah@xahlee.org
 http://xahlee.org/PageTwo_dir/more.html



------------------------------

Date: 7 Feb 2005 20:18:06 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: [perl-python] text pattern matching, and expressiveness
Message-Id: <Xns95F6917BFEEF4castleamber@130.133.1.4>

Xah Lee wrote:

> Perl is a language of syntactical variegations. Python on the other
> hand, does not even allow changes in code's indentation, but its
> efficiency and power in expression, with respect to semantics (i.e.
> algorithms), showcases Perl's poverty in specification.

Clarify :-D.

-- 
John                   Small Perl scripts: http://johnbokma.com/perl/
               Perl programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html
                        


------------------------------

Date: 7 Feb 2005 12:23:50 -0800
From: "me" <ebabin@yahoo.com>
Subject: bizarre index() function behavior
Message-Id: <1107807830.584228.288420@f14g2000cwb.googlegroups.com>

First I thought I was crazy, then I tested this, seems to work
differently:

$teststr = "            <P>A J SERVICES LIMITED</FONT></P></TD>";
$ret_val = index($teststr, "<P>");
print "position is ".$ret_val."\n\n";

>position is 12


But when I read this in from a file:

sysopen(FH, $default_input_file, O_RDONLY) or
     die "sysopen failed: $!\n";

while ($read_buf = readline(FH)) {
    # parse the field value out of the entire string
    $ret_val = index($read_buf, "<P>");

THEN:
$ret_val = 1


What causes this to be different??  I thought it was because of leading
spaces but I also tried to use "\<P\>" and "A J SERVICES" but the index
value is always 1.


thanks for your thoughts



------------------------------

Date: Mon, 07 Feb 2005 21:35:40 +0100
From: Tore Aursand <toreau@gmail.com>
Subject: Re: bizarre index() function behavior
Message-Id: <qiQNd.7780$IW4.170253@news2.e.nsc.no>

me wrote:
> First I thought I was crazy, then I tested this, seems to work
> differently:
> [...]

Not here. Show us the whole code, and/or try printing out each line each 
time.


-- 
Tore Aursand <tore@aursand.no>
"Daring ideas are like chessmen moved forward; they may be beaten, but
  they may start a winning game." (Johann Wolfgang von Goethe)


------------------------------

Date: 7 Feb 2005 20:42:04 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: bizarre index() function behavior
Message-Id: <Xns95F69FB8E3A5Basu1cornelledu@132.236.56.8>

"me" <ebabin@yahoo.com> wrote in news:1107807830.584228.288420
@f14g2000cwb.googlegroups.com:

> First I thought I was crazy, then I tested this, seems to work
> differently:
> 
> $teststr = "            <P>A J SERVICES LIMITED</FONT></P></TD>";
> $ret_val = index($teststr, "<P>");
> print "position is ".$ret_val."\n\n";
> 
>>position is 12
> 
> 
> But when I read this in from a file:
> 
> sysopen(FH, $default_input_file, O_RDONLY) or
>      die "sysopen failed: $!\n";
> 
> while ($read_buf = readline(FH)) {
>     # parse the field value out of the entire string
>     $ret_val = index($read_buf, "<P>");
> 
> THEN:
> $ret_val = 1
> 
> 
> What causes this to be different??  I thought it was because of leading
> spaces but I also tried to use "\<P\>" and "A J SERVICES" but the index
> value is always 1.

C:\Documents and Settings\asu1\My Documents> cat a.pl
use strict;
use warnings;

my $teststr = q{            <P>A J SERVICES LIMITED</FONT></P></TD>};
print index($teststr, '<P>'), "\n";

while($teststr = <DATA>) {
    print index($teststr, '<P>'), "\n";
}
__DATA__
            <P>A J SERVICES LIMITED</FONT></P></TD>

C:\Documents and Settings\asu1\My Documents> perl a.pl
12
12
-1

Please take a look at the posting guidelines for this group and try to 
put together the shortest script that still exhibits the problem. We 
cannot help you with a problem we cannot observe.

Sinan.


------------------------------

Date: Mon, 7 Feb 2005 16:13:53 -0000
From: "Andrew Armstrong" <asa@aaelectron.co.uk>
Subject: CGI - web content into variable
Message-Id: <420793d3$0$47263$ed2e19e4@ptn-nntp-reader04.plus.net>

I am new to PERL, and finding the documentation difficult to understand.

What I want to do is to retrieve information from a web page. I can view the
page in a browser, but what I want to do is get the content into a variable
so I can get the item of information for further use.

The latter may take a little effort, but it is only internal program logic
so I can make it work eventually. However, I have been unable to find any
reference to the means to get the content of a web page into a
variable.

Can anyone advise me?

Andrew Armstrong





------------------------------

Date: 7 Feb 2005 08:43:34 -0800
From: ioneabu@yahoo.com
Subject: Re: CGI - web content into variable
Message-Id: <1107794614.724076.39750@l41g2000cwc.googlegroups.com>


Andrew Armstrong wrote:
> I am new to PERL, and finding the documentation difficult to
understand.
>
> What I want to do is to retrieve information from a web page. I can
view the
> page in a browser, but what I want to do is get the content into a
variable
> so I can get the item of information for further use.
>
> The latter may take a little effort, but it is only internal program
logic
> so I can make it work eventually. However, I have been unable to find
any
> reference to the means to get the content of a web page into a
> variable.
>
> Can anyone advise me?
>
> Andrew Armstrong

#!/usr/bin/perl
use LWP::UserAgent;
$ua = LWP::UserAgent->new();
$q = $ARGV[0];
$q =~ s/\s/+/g;
$h =
"http://www.google.com/search?hl=en&ie=ISO-8859-1&q=$q&btnG=Google+Search";

$ua->agent("Mozilla/5.0 (compatible; Konqueror/3.1; Linux 2.4.20)");
$resp = $ua->get($h);
$content = $resp->content;
print "$content\n";

I found this that I wrote a while ago in a post.  It does a Google
search.  Good Luck!

wana



------------------------------

Date: Mon, 07 Feb 2005 18:02:12 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: CGI - web content into variable
Message-Id: <36pl7jF4joeptU1@individual.net>

Andrew Armstrong wrote:
> I am new to PERL, and finding the documentation difficult to understand.
> 
> What I want to do is to retrieve information from a web page.

     http://search.cpan.org/~gaas/libwww-perl-5.803/lib/LWP/Simple.pm

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


------------------------------

Date: Mon, 07 Feb 2005 12:02:24 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: CGI - web content into variable
Message-Id: <lL6dnQ_uF8S9AprfRVn-1A@adelphia.com>

Andrew Armstrong wrote:

> I am new to PERL, and finding the documentation difficult to understand.

Have you seen the posting guidelines that appear here frequently? They have
pointers to a number of tips and helpful suggestions.

> What I want to do is to retrieve information from a web page.

Have a look at the LWP module on CPAN:

    <http://www.cpan.org>

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


------------------------------

Date: 7 Feb 2005 17:25:26 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: CGI - web content into variable
Message-Id: <Xns95F67E6219B2Aasu1cornelledu@132.236.56.8>

"Andrew Armstrong" <asa@aaelectron.co.uk> wrote in
news:420793d3$0$47263$ed2e19e4@ptn-nntp-reader04.plus.net: 

> What I want to do is to retrieve information from a web page. I can
> view the page in a browser, but what I want to do is get the content
> into a variable so I can get the item of information for further use.
> 

perldoc -q fetch

I will suggest that you at least browse the FAQ once before posting here. 
If you have ActiveState Perl, it is installed automatically on your 
computer and available from the WIndows start menu.

Sinan. 


------------------------------

Date: Mon, 07 Feb 2005 22:53:02 +0000
From: Andrew Armstrong <andy@aaelectron.co.uk>
Subject: Re: CGI - web content into variable
Message-Id: <80lf01tcf55953uq967p02o683qkvj41h8@4ax.com>




On 7 Feb 2005 08:43:34 -0800, ioneabu@yahoo.com wrote:

>
>Andrew Armstrong wrote:
>> I am new to PERL, and finding the documentation difficult to
>understand.
>>
>> What I want to do is to retrieve information from a web page. I can
>view the
>> page in a browser, but what I want to do is get the content into a
>variable
>> so I can get the item of information for further use.
>>
>> The latter may take a little effort, but it is only internal program
>logic
>> so I can make it work eventually. However, I have been unable to find
>any
>> reference to the means to get the content of a web page into a
>> variable.
>>
>> Can anyone advise me?
>>
>> Andrew Armstrong
>
>#!/usr/bin/perl
>use LWP::UserAgent;
>$ua = LWP::UserAgent->new();
>$q = $ARGV[0];
>$q =~ s/\s/+/g;
>$h =
>"http://www.google.com/search?hl=en&ie=ISO-8859-1&q=$q&btnG=Google+Search";
>
>$ua->agent("Mozilla/5.0 (compatible; Konqueror/3.1; Linux 2.4.20)");
>$resp = $ua->get($h);
>$content = $resp->content;
>print "$content\n";
>
>I found this that I wrote a while ago in a post.  It does a Google
>search.  Good Luck!
>
>wana

Thanks for this comprehensive answer. It still doesn't actually work, though it
looks as if it should. (The documentation at 
http://search.cpan.org/~gaas/libwww-perl-5.803/lib/LWP/Simple.pm
on the other hand is almost but not quite understandable enough at my present
knowledge level.)


The error log tells me:

Can't locate object method "get" via package "LWP::UserAgent" at [PATH
REMOVED]test6.cgi line 9.

Does this mean that the LWP package on the server is non-standard and lacks the
get method, which seems to be what it says, or can you think of anything else
that might be the cause?

Ought I to be using LWP::Simple with appropriate code instead?

I am not clear about the &q lines either. As far as I can understand, the \
characters are replaced by / characters, but I can't find where the
 
$ARGV[0]

comes from. I would *guess* it comes from  the LWP module, but so far haven't
found anything about this in the documentation on CPAN.

Probably the main problem I face is that the documentationI have found assumes
more knowledge than it is easy to get as a beginner when most of the
documentation makes little sense. The text book I have that I understand un
fortunately doesn't go far enough for all the things I have to make work.

Andrew



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 7749
***************************************


home help back first fref pref prev next nref lref last post