[30980] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2225 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 21 00:09:43 2009

Date: Fri, 20 Feb 2009 21:09:08 -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           Fri, 20 Feb 2009     Volume: 11 Number: 2225

Today's topics:
    Re: Chomp <1usa@llenroc.ude.invalid>
    Re: Chomp <ben@morrow.me.uk>
    Re: Chomp <tim@burlyhost.com>
    Re: Chomp <tadmc@seesig.invalid>
    Re: Kill processes after web page closes <stoupa@practisoft.cz>
    Re: Kill processes after web page closes <tim@burlyhost.com>
    Re: Sorting based on existence of keys <whynot@pozharski.name>
    Re: Sorting hash of hashes (Greg Bacon)
    Re: Sorting hash of hashes (Greg Bacon)
    Re: Sorting hash of hashes (Greg Bacon)
        using WWW::Mechanize on activestate <larry@example.invalid>
    Re: using WWW::Mechanize on activestate <placebo@dontbesilly.com>
    Re: using WWW::Mechanize on activestate <tadmc@seesig.invalid>
    Re: using WWW::Mechanize on activestate <ben@morrow.me.uk>
    Re: using WWW::Mechanize on activestate <tim@burlyhost.com>
    Re: weird matching variable behavior sln@netherlands.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 20 Feb 2009 19:52:02 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Chomp
Message-Id: <Xns9BB8973CDFBEasu1cornelledu@127.0.0.1>

"zoomcart.com" <screwmeblome@gmail.com> wrote in news:6e98e552-1d5e-
4b27-8c10-5fc8a1ee84fc@z6g2000pre.googlegroups.com:

> Hello and thanks in advance for you help.
> I have a simple email program that has a bulk add feature where a user
> can add an email list separated by returns. It works fine, except when
> the user tries to edit and remove an email, the script is not
> recognizing the email. If the email was added individually, it
> recognizes it. This may only be caused when the user is using a mac. 

Line endings are different on the Mac CRLF for DOSish systems, LF for 
*nixes and CR for the old Mac OS.

The code you have provided below is simply an undreadable mess. Don't 
code like this but more importantly, don't post like this. Please take a 
look at the Posting Guidelines to learn how to help others help you.

>  while (<USERS>)
>     {
>     $line = $_;

while ( my $line = <USERS> ) {

>     chomp $line if ($line =~ /\n$/);

A line, by definition, ends with a newline.

Assuming whitespace at the end of an email address cannot be significant 
(the assumption makes sense to me but I don't know the RFC), how about:

$line =~ s/\s+$//;

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/


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

Date: Fri, 20 Feb 2009 20:02:16 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Chomp
Message-Id: <8re376-ie7.ln1@osiris.mauzo.dyndns.org>


Quoth "zoomcart.com" <screwmeblome@gmail.com>:
> Hello and thanks in advance for you help.
> I have a simple email program that has a bulk add feature where a user
> can add an email list separated by returns. It works fine, except when
> the user tries to edit and remove an email, the script is not
> recognizing the email. If the email was added individually, it
> recognizes it. This may only be caused when the user is using a mac. I
> have tried several chomp variations.

I have tidied up your indentation. Please make an effort to make code at
least minimally readable before posting it. If nothing else, run it
through 'perltidy'.

> This is the bulk add code..

> sub add_bulk_email {
>     my ( $newemail, $bademail, $email, $newemail, $checkemail );

Declaring a whole lot of variables like this is bad style. Perl is not
Pascal. Declare them as you need them.

>     $checkemail = param('checkemail');
>     @emails = split( /\n+/, $checkemail );

Where is @emails declared? Are you using 'strict'?

>     foreach $email (@emails) {
>         unless ( $email =~ /.*\@.*\..*/ ) {

You do realise this is not a very good regex for detecting valid email
addresses? You would be better off using something like
Regexp::Common::Email::Address. You should also probably have your match
anchored, or just extract the bit that matches.

>             $bademail = $email;

Do you actually do anything with $bademail? Since you appear not to, I
would write this as

    $email =~ /.*\@.*\..*/ or next;

and avoid the unless/else block altogether.

>         }
>         else {

Don't use 'else' with 'unless'. It's very confusing. Reverse the two
halves instead.

>             $emailcnt++;
>             chomp $email;

What are you trying to achieve here? $email is the result of splitting
something on newlines, so it doesn't contain any "\n"s. I suspect it may
contain "\r"s, and that the best way of removing them would be to change
your split pattern above to /\r?\n|\r/ which will catch most flavours of
newline.

>     if ($newemail) {
>         open( USERS, ">>$userpath/lists/$list" ) || &adminerror(
>             "$userpath/
> lists/$list  Update Account", __FILE__, __LINE__,
>         );

Don't call subs with & unless you know what it does.
Use 3-arg open.
Use lexical filehandles.
Don't repeat yourself.
|| and && are meant as boolean operators; 'or' and 'and' are for
flow-control.

    my $listpath = "$userpath/lists/$list";
    open( my $USERS, ">>", $listpath )  
        or adminerror("$listpath  Update Accout", __FILE__, __LINE__);

If adminerror is something you wrote, you may also be interested to read
perldoc -f caller, which will allow you to avoid passing __FILE|LINE__
all over the place.

>         print USERS $newemail;
>         close(USERS);

Since this is presumably important data you are writing, you should
check the return value of 'close' as well. Errors like 'disk full' will
show up here.

<snip>
> ########################## This is the code for the individual add ...
> sub add_new_email {
<snip>
>     if ( -e "$userpath/lists/$list" ) {

Don't do this: the file may be created or destroyed in between the -e
and the open. Try the open, and if it fails check if $! == ENOENT (you
can get a definition of ENOENT from the POSIX module like this:

    use POSIX qw/ENOENT/;

)

>         open( USERS, "$userpath/lists/$list" ) || &adminerror(
>             "$userpath/
> lists/$list  add new email  ", __FILE__, __LINE__,
>         );
>         flock( USERS, LOCK_EX );

Why are you locking LOCK_EX when the file is only open for read? More
importantly, do you realise you are dropping the lock between read and
update, which makes it worthless? You need to seek to the end instead of
re-opening in append mode, and you also need to lock the file everywhere
else you read or write it. add_bulk_email currently doesn't take a lock,
and it needs to.

>         while (<USERS>) {
>             $line = $_;

Yuck!

    while (my $line = <USERS>) {

>             chomp $line if ( $line =~ /\n$/ );

chomp already does that check, and, again, you shouldn't be using chomp.
You want something more like

    $line =~ s/(?:\r?\n|\r)\z//;

>             if ( $checkemail eq $line ) {
>                 $newemail = "";
>             }
>             else {
>                 $newemail = $checkemail;
>             }    #else

If you used proper indentation you would realise comments like this
aren't helpful.

The rest of the code is much the same. Your immediate problem is that
you are using chomp on form fields, when that isn't appropriate.

Ben



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

Date: Fri, 20 Feb 2009 12:42:50 -0800
From: Tim Greer <tim@burlyhost.com>
Subject: Re: Chomp
Message-Id: <fBEnl.8943$FI5.8567@newsfe07.iad>

zoomcart.com wrote:

> Hello and thanks in advance for you help.
> I have a simple email program that has a bulk add feature where a user
> can add an email list separated by returns. It works fine, except when
> the user tries to edit and remove an email, the script is not
> recognizing the email. If the email was added individually, it
> recognizes it. This may only be caused when the user is using a mac. I
> have tried several chomp variations.
> This is the bulk add code..
> sub add_bulk_email{
> my ($newemail, $bademail, $email, $newemail, $checkemail);
> $checkemail = param('checkemail');
>   @emails = split(/\n+/, $checkemail);
> foreach $email(@emails){
> unless ($email =~ /.*\@.*\..*/) {

As a couple of people have already covered a lot of problems with the
code in other replies, I'll be short.  The above check, just so you 
know, will match completely invalid addresses, including seeing "@." as
a valid email address.

> $emailcnt++;
> chomp $email;
> #chomp $email if ($email =~ /\n$/);
> #chomp $email if ($email =~ /\r$/);

Line feeds/new lines are not the same across all systems.  Why not just
strip out any whitespace/new lines altogether from the variable?
-- 
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!


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

Date: Fri, 20 Feb 2009 15:18:55 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Chomp
Message-Id: <slrngpu7hv.dg3.tadmc@tadmc30.sbcglobal.net>

zoomcart.com <screwmeblome@gmail.com> wrote:

>   @emails = split(/\n+/, $checkemail);


That line of code looks familiar...

 ... it appears I posted it verbatim in a followup to you in April 2008.

You're still working on the same program?


> if($checkemail eq ""){
>  &adminerror("Please include an email address");
> }


I would prefer writing that as:

   adminerror("Please include an email address") unless length $checkemail;


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Sat, 21 Feb 2009 01:05:18 +0100
From: "Petr Vileta \"fidokomik\"" <stoupa@practisoft.cz>
Subject: Re: Kill processes after web page closes
Message-Id: <gnngha$23ss$1@ns.felk.cvut.cz>

Petyr David wrote:
> I have a PERL-CGI application. I gather input from user, start PERL
> script and build a new web page based on input. At the top of the
> newly created page is a command button to return the user to the
> previous page. If the user clicks the command button and is returned
> to the previous page before the page has been completely built,  I
> find the PERL script is still running. It eventually dies (20 - 30
> seconds). I'd like to kill the process as soon as the user returns to
> the original page.
>
> How do I determine when that happens?
>
> I'd also like to be able to delete temp files that are  deleted when
> the PERL script normally completes.
>

You can set some $SIG{} perl variables to you own routine. I'm not sure if this 
is exact but possible when user click back button then Appache server (or other 
web server service) send TERM or QUIT signal to your perl proccess. When you 
have $SIG{} variable redirected to your routine then you can do something you 
need.

#!/usr/bin/perl
use strict;
# .....
$SIG{'QUIT'}=sub {errexit("SIG-QUIT")};
$SIG{'TERM'}=sub {errexit("SIG-TERM")};
# .....

sub errexit
{
my $signal = shift;
# you can write $signal to the log file if you need

# you can unlink some files;

exit 0;
}


-- 
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail.
Send me your mail from another non-spammer site please.)
Please reply to <petr AT practisoft DOT cz>



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

Date: Fri, 20 Feb 2009 20:06:31 -0800
From: Tim Greer <tim@burlyhost.com>
Subject: Re: Kill processes after web page closes
Message-Id: <n5Lnl.8801$aZ3.3339@newsfe01.iad>

Petr Vileta "fidokomik" wrote:

> Petyr David wrote:
>> I have a PERL-CGI application. I gather input from user, start PERL
>> script and build a new web page based on input. At the top of the
>> newly created page is a command button to return the user to the
>> previous page. If the user clicks the command button and is returned
>> to the previous page before the page has been completely built,  I
>> find the PERL script is still running. It eventually dies (20 - 30
>> seconds). I'd like to kill the process as soon as the user returns to
>> the original page.
>>
>> How do I determine when that happens?
>>
>> I'd also like to be able to delete temp files that are  deleted when
>> the PERL script normally completes.
>>
> 
> You can set some $SIG{} perl variables to you own routine. I'm not
> sure if this is exact but possible when user click back button then
> Appache server (or other web server service) send TERM or QUIT signal
> to your perl proccess. When you have $SIG{} variable redirected to
> your routine then you can do something you need.
> 
> #!/usr/bin/perl
> use strict;
> # .....
> $SIG{'QUIT'}=sub {errexit("SIG-QUIT")};
> $SIG{'TERM'}=sub {errexit("SIG-TERM")};
> # .....
> 
> sub errexit
> {
> my $signal = shift;
> # you can write $signal to the log file if you need
> 
> # you can unlink some files;
> 
> exit 0;
> }
> 
> 

Those (signals) aren't sent or captured from the browser.  Do you meant
to suggest some alarm for the run time or something?
-- 
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!


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

Date: Sat, 21 Feb 2009 04:00:17 +0200
From: Eric Pozharski <whynot@pozharski.name>
Subject: Re: Sorting based on existence of keys
Message-Id: <slrngpuo34.n5b.whynot@orphan.zombinet>

On 2009-02-20, Uri Guttman <uri@stemsystems.com> wrote:
>>>>>> "EP" == Eric Pozharski <whynot@pozharski.name> writes:

*SKIP* [ since uri skipped attribution anyway ]

>  EP> I beg to differ.  Jurgen is right that OP must get realtional and
>  EP> equality operators and boolean algebra straight first (as if mine is).
>
>  EP>     sort {
>  EP>         (exists $h{$a} xor exists $h{$b}) ?
>  EP>             exists $h{$b} - exists $h{$a} :
>  EP>             0
>  EP>     } @ks
>
> and where does that sort the lengths? even though it isn't a real
> requirement we all seem to have been using it. when you add that back
> you get much more complicated comparisons.

Comparision on lengthes has nothing to do with Jurgen's point.  That
comparision is a patch and nothing more.

> i haven't even brought up
> speed for which the presort key extraction is needed.

Speed?  Great, now we are about speed.  OP has no clue, talking about
speed with him leads to conclusion you teach him that rude thing of 23
letters (space included).

> see my other post
> for an example which should work if i typed it cleanly and is simpler,
> clearer and faster.

That's your B<Sort::Maker>, your golf, and be it good for you.  I'm
afraid that OP didn't get your comments anyway.  But clpm is a
discussion group.


-- 
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom


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

Date: Fri, 20 Feb 2009 15:31:27 -0600
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: Sorting hash of hashes
Message-Id: <cY6dnXjcWv2yvALUnZ2dnUVZ_gyWnZ2d@posted.hiwaay2>

Justin C wrote:

: J. Gleixner wrote:
:
: > Having keys like 1,2,3, etc. is not very descriptive and after a few
: > months, when you look at your code again, you'll wish you used
: > something that made sense.
:
: I have, within the code, described the construction, and the numbers
: are the column numbers within the report, so it's not overly
: confusing.

Using sequence numbers as keys in a hash is often a strong sign
that you should use an array instead. However...

I assume you used comments to describe the construction. Consider
Rob Pike's advice[*]:

    If your code needs a comment to be understood, it
    would be better to rewrite it so it's easier to
    understand.

[*] http://www.lysator.liu.se/c/pikestyle.html

*The Practice of Programming* (a book Pike co-authored with
Brian Kernighan -- the K in K&R) succinctly advises: "Give names
to magic numbers." That is, use meaningful symbolic names instead
of bare numeric literals.

Greg
-- 
The greatest dangers to liberty lurk in insidious encroachment by men
of zeal, well-meaning but without understanding.
    -- Justice Louis D. Brandeis


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

Date: Fri, 20 Feb 2009 16:12:54 -0600
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: Sorting hash of hashes
Message-Id: <Qpmdnd3Ru897twLUnZ2dnUVZ_umWnZ2d@posted.hiwaay2>

Justin C wrote:

: More to think about, thank you. I'm considering an alteration to my
: data structure (%hashes), with each report getting it's own hash,
: named at run-time from the report code. Seems a better way to me.

By "named at run-time," it sounds as though you're thinking about
making a common mistake. Mark Jason Dominus wrote a series of posts
about why you should NOT do this:

    Why it's stupid to `use a variable as a variable name'
    http://perl.plover.com/varvarname.html

    A More Direct Explanation of the Problem
    http://perl.plover.com/varvarname2.html

    What if I'm Really Careful?
    http://perl.plover.com/varvarname3.html

: It'll reduce the 'depth' of the hash for a start.

Why is depth a problem? Because it's unfamiliar?

:                                                   I'm just going
: through the replies I've received to my post before I read perldoc -f
: map, so I'll keep this to re-read after I've read the docs. Thanks for
: you help.

With map, you transform one list into another:

    $ perl -MData::Dumper -le 'print Dumper [map $_*2, 1..5]'
    $VAR1 = [
              2,
              4,
              6,
              8,
              10
            ];

It's roughly equivalent to a for loop:

    $ perl -MData::Dumper -le \
      'for (1..5) { push @a, $_*2 } print Dumper \@a'
    $VAR1 = [
              2,
              4,
              6,
              8,
              10
            ];

Hope this helps,
Greg
-- 
These days it's slightly different.  You give the Web site your privacy
and your spam-vulnerable email address ... it gives you a cookie.  What
is it good for?  Don't worry about it.  Good user, have a cookie.
    -- Internet Oracularities 1308-01


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

Date: Fri, 20 Feb 2009 16:42:50 -0600
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: Sorting hash of hashes
Message-Id: <G6idnUeMqql3rALUnZ2dnUVZ_gyWnZ2d@posted.hiwaay2>

Justin C wrote

: Greg Bacon wrote
:
: > It looks like you must have called Dumper(%hashes). What you really
: > want is Dumper(\%hashes) -- note the backslash -- so you can later
: > evaluate the dump to create an equivalent hash.
:
: I copied that output from a web-browser, it doesn't appear much
: different using what you suggest, only the $VAR2,  $VAR3 etc are
: missing.

Several in this thread have mentioned it, so it's not a mere point
of taste or aesthetics. Compare the difference with the following
program:

    #! /usr/bin/perl

    use Data::Dumper;

    my %h = (
      a => 1,
      b => 2,
    );

    my $plain = Dumper  %h;
    my $ref   = Dumper \%h;

    foreach my $dump ($plain, $ref) {
      my $result = eval $dump;
      die if $@;

      print Dumper($result), "\n";
    }

Its output is

    $VAR1 = 2;

    $VAR1 = {
              'a' => 1,
              'b' => 2
            };

By dumping a reference, you get back out what you put in. Dumping
a flattened hash gives surprising results.

: [...]
: It's given me stuff to think about, and some help, yes. Thank you.

Help us help you: describe at a high level what you're trying to do.

Greg
-- 
The logic is flawless: when a private business *accidentally* kills 146
people, we need to increase the power of the government, an entity that
*deliberately* kills millions.
    -- Gene Callahan


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

Date: Fri, 20 Feb 2009 18:31:06 -0700
From: Larry Gates <larry@example.invalid>
Subject: using WWW::Mechanize on activestate
Message-Id: <7wzzzvvr59bk$.1xe1s9cowbbsn$.dlg@40tude.net>


I've been trying to get scrape the web page that is given in the faqs as a
searching resource and then automate the page.  WWW::Mechanize is not one
of the modules that activestate bundles, so I needed it off the web.

I think activestate made a less-than-effective install, as when I was done
with it, it didn't have a Mechanize.pm in it anywhere.  So I download
Mechanize.pm from cpan and put it in the WWW folder.

Now my error is:

C:\MinGW\source> perl goog2.pl
Can't locate HTTP/Response/Encoding.pm in @INC (@INC contains:
C:/Perl/site/lib
C:/Perl/lib .) at C:/Perl/site/lib/WWW/Mechanize.pm line 109.
BEGIN failed--compilation aborted at C:/Perl/site/lib/WWW/Mechanize.pm line
109.

Compilation failed in require at goog2.pl line 9.
BEGIN failed--compilation aborted at goog2.pl line 9.

C:\MinGW\source>

What is this telling me?

This is the script so far:

#!/usr/bin/perl
# url http://groups.google.com/advanced_search

use warnings;
use strict;
use HTML::TreeBuilder;
use LWP::Simple;
use LWP::UserAgent;
use WWW::Mechanize;

my $site_url = 'http://groups.google.com';
my $url_args = 'advanced_search';
my $t = get "$site_url/$url_args" || "Problem";

my $tree = HTML::TreeBuilder->new_from_content($t);

$tree->dump;

my $g = 'comp.lang.perl.misc';
my $s = 'mechanize website';

# perl goog2.pl

Out of this dump, I have the data that I want to mechanize

<input name="as_ugroup" size="40" type="text" value="" />

<input name="as_usubject" size="40" 

I want to put $g into the group and $s in the subject.

I'm hoping the output informs the autodidact.  Thanks for your comment.
-- 
larry gates

Clear conceptual splits often hide false dichotomies.
    -- Larry Wall in <20050330195322.GB22184@wall.org>


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

Date: Sat, 21 Feb 2009 02:01:46 GMT
From: "Peter Wyzl" <placebo@dontbesilly.com>
Subject: Re: using WWW::Mechanize on activestate
Message-Id: <egJnl.22368$cu.17971@news-server.bigpond.net.au>

"Larry Gates" <larry@example.invalid> wrote in message 
news:7wzzzvvr59bk$.1xe1s9cowbbsn$.dlg@40tude.net...
>
> I've been trying to get scrape the web page that is given in the faqs as a
> searching resource and then automate the page.  WWW::Mechanize is not one
> of the modules that activestate bundles, so I needed it off the web.
>
> I think activestate made a less-than-effective install, as when I was done
> with it, it didn't have a Mechanize.pm in it anywhere.  So I download
> Mechanize.pm from cpan and put it in the WWW folder.
>
> Now my error is:
>
> C:\MinGW\source> perl goog2.pl
> Can't locate HTTP/Response/Encoding.pm in @INC (@INC contains:
> C:/Perl/site/lib
> C:/Perl/lib .) at C:/Perl/site/lib/WWW/Mechanize.pm line 109.
> BEGIN failed--compilation aborted at C:/Perl/site/lib/WWW/Mechanize.pm 
> line
> 109.

Looks like you need to install Encoding.pm which is something WWW::Mechanize 
uses.

P 




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

Date: Fri, 20 Feb 2009 19:54:34 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: using WWW::Mechanize on activestate
Message-Id: <slrngpunmq.g3c.tadmc@tadmc30.sbcglobal.net>

Larry Gates <larry@example.invalid> wrote:
>
> I've been trying to get scrape the web page that is given in the faqs as a
> searching resource and then automate the page.  WWW::Mechanize is not one
> of the modules that activestate bundles, so I needed it off the web.
>
> I think activestate made a less-than-effective install, as when I was done
> with it, it didn't have a Mechanize.pm in it anywhere.  So I download
> Mechanize.pm from cpan and put it in the WWW folder.


What does "the WWW folder" mean when you say it?


> Now my error is:
>
> C:\MinGW\source> perl goog2.pl
> Can't locate HTTP/Response/Encoding.pm in @INC (@INC contains:
> C:/Perl/site/lib
> C:/Perl/lib .) at C:/Perl/site/lib/WWW/Mechanize.pm line 109.
> BEGIN failed--compilation aborted at C:/Perl/site/lib/WWW/Mechanize.pm line
> 109.
>
> Compilation failed in require at goog2.pl line 9.
> BEGIN failed--compilation aborted at goog2.pl line 9.
>
> C:\MinGW\source>
>
> What is this telling me?


All of the messages that perl might issue are documented in:

   perldoc perldiag

Did you look up the message there?

If you put

    use diagnostics;

near the beginning of your program and run it again, 
then perl will look up the message and display its docs for you...


It is telling you that WWW::Mechanize depends on ("use"s) HTTP::Response.

When you install a module, you also need to install all of its
dependencies, and all of the dependencies of the dependencies, and ...


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Sat, 21 Feb 2009 03:12:57 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: using WWW::Mechanize on activestate
Message-Id: <p28476-0m9.ln1@osiris.mauzo.dyndns.org>


Quoth larry@example.invalid:
> 
> I've been trying to get scrape the web page that is given in the faqs as a
> searching resource and then automate the page.  WWW::Mechanize is not one
> of the modules that activestate bundles, so I needed it off the web.
> 
> I think activestate made a less-than-effective install, as when I was done
> with it, it didn't have a Mechanize.pm in it anywhere.  So I download
> Mechanize.pm from cpan and put it in the WWW folder.
> 
> Now my error is:
> 
> C:\MinGW\source> perl goog2.pl
> Can't locate HTTP/Response/Encoding.pm in @INC (@INC contains:

Either install WWW::Mechanize using ppm, or ditch AS Perl, install
Strawberry Perl from strawberryperl.com, and install WWW::Mechanize
using CPAN. It's never worth trying to install CPAN modules by hand,
especially as you don't really know what you're doing.

Ben



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

Date: Fri, 20 Feb 2009 20:08:58 -0800
From: Tim Greer <tim@burlyhost.com>
Subject: Re: using WWW::Mechanize on activestate
Message-Id: <v7Lnl.8802$aZ3.8635@newsfe01.iad>

Larry Gates wrote:

> 
> I've been trying to get scrape the web page that is given in the faqs
> as a
> searching resource and then automate the page.  WWW::Mechanize is not
> one of the modules that activestate bundles, so I needed it off the
> web.
> 
> I think activestate made a less-than-effective install, as when I was
> done
> with it, it didn't have a Mechanize.pm in it anywhere.  So I download
> Mechanize.pm from cpan and put it in the WWW folder.
> 
> Now my error is:
> 
> C:\MinGW\source> perl goog2.pl
> Can't locate HTTP/Response/Encoding.pm in @INC (@INC contains:
> C:/Perl/site/lib
> C:/Perl/lib .) at C:/Perl/site/lib/WWW/Mechanize.pm line 109.
> BEGIN failed--compilation aborted at C:/Perl/site/lib/WWW/Mechanize.pm
> line 109.
> 
> Compilation failed in require at goog2.pl line 9.
> BEGIN failed--compilation aborted at goog2.pl line 9.

Seems to indicate it can't locate the Encoding module.  Instead of just
dropping a module file into a directory, try installing the module
normally via CPAN or with the module's source/build steps (and ensure
you install any requirements for that module). This way you don't risk
having partial installs.  The error you saw seems to specifically
outline the problem.


-- 
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!


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

Date: Sat, 21 Feb 2009 05:04:10 GMT
From: sln@netherlands.com
Subject: Re: weird matching variable behavior
Message-Id: <rb2vp4pgk5d0dh161srhpf601iaatsmlvc@4ax.com>

On Fri, 20 Feb 2009 09:23:31 -0800 (PST), "juliani.moon@gmail.com" <juliani.moon@gmail.com> wrote:

>I am using perl v5.8.5.
>
>I made a simple construct to make email addresses hyper-linkable:
> if ($_ =~ / ([a-zA-Z\.]+\@[a-zA-Z\.]+) /g) {
>      s!$1!<a href="mailto:$1">$1</a>!g;
> }
>However it only effectively takes out the email address, as if only
>the first "$1" matched and the "$1" at the 2nd and 3rd places becomes
>empty because it replaces an email address only with:
>  <a href="mailto:"></a>
>
>Then I tried to use "$&" in places of "$1", as in:
> if ($_ =~ / ([a-zA-Z\.]+\@[a-zA-Z\.]+) /g) {
>      s!$&!<a href="mailto:$&">$&</a>!g;
> }
>This time the email addresses are found and replaced with html codes
>like:
><a href="mailto: username@somedomain.com "> username@somedomain.com </
>a>
>-- but "$&" carries a space on both sides of the email address.
>
>It seems trivial and unnecessary although I can work around by this:
>  if ($_ =~ / ([a-zA-Z\.]+\@[a-zA-Z\.]+) /g) {
>      $emem = $1;
>      s!$emem!<a href="mailto:$emem">$emem</a>!g;
>  }
>My wonders are (1) I saw examples where "$1" was used as in my first
>example. Why it fails to work as in my first example? (2) Is it by
>default that "$&" carries spaces on both sides of its content?
>(To"clean" it, I would have to introduce a new variable as "$&" is a
>"read-only value"). Things shouldn't be that complicated, are they?
>
>Joe

Joe,

Understand some regulare expression basics first.
Don't depend on the documentation for complete knowledge.
Test and retest samples that are redundant with minor variations.
After a while, regulare expression behaviour will become ingrained
into your sub-concious.

-sln

------------------------------------------
## jjj.pl
use strict;
use warnings;

$_ = join '', <DATA>;

# Non - Global /g
# ---------------------
print "\nNon - global, position reset even with match (/g):\n";
print "-"x30,"\n";
/ ([a-zA-Z\.]+\@[a-zA-Z\.]+) /;    print $1,"\n" if defined $1;
/ ([a-zA-Z\.]+\@[a-zA-Z\.]+) /;    print $1,"\n" if defined $1;
/ ([a-zA-Z\.]+\@[a-zA-Z\.]+) /;    print $1,"\n" if defined $1;
print "\n";

# Global /g
# ---------------------
print "\nGlobal, position reset on non-match only (/g):\n";
print "-"x30,"\n";
/ ([a-zA-Z\.]+\@[a-zA-Z\.]+) /g;    print $1,"\n" if defined $1;
/ ([a-zA-Z\.]+\@[a-zA-Z\.]+) /g;    print $1,"\n" if defined $1;
/ ([a-zA-Z\.]+\@[a-zA-Z\.]+) /g;    print $1,"\n" if defined $1;
/ ([a-zA-Z\.]+\@[a-zA-Z\.]+) /g;    print $1,"\n" if defined $1;
/ ([a-zA-Z\.]+\@[a-zA-Z\.]+) /g;    print $1,"\n" if defined $1;
print " ^^^ did not match, position was reset, but \$1 retained its value\n";
/ ([a-zA-Z\.]+\@[a-zA-Z\.]+) /g;    print $1,"\n" if defined $1;


# If, with Global /g, Capture $1, use $1 in substitution
# ----------------------------------------------------
print "\nIf, with Global /g, Capture \$1, use $1 in substitution:\n";
print "-"x30,"\n";
if (/ ([a-zA-Z\.]+\@[a-zA-Z\.]+) /g)
{
	print "$1\n";
	s!($1)!<a href="mailto:$1">$1</a>!g;
	print $1,"\n";
	print $_,"\n";
}

# If, with Global /g, Non Capture $1, use $1 in substitution
# ----------------------------------------------------
print "\nIf, with Global /g, NON Capture \$1, use $1 in substitution:\n";
print "-"x30,"\n";
if (/ ([a-zA-Z\.]+\@[a-zA-Z\.]+) /g)
{
	print "$1\n";
	s!$1!<a href="mailto:$1">$1</a>!g;
	print $1,"\n";
	print $_,"\n";
}

__DATA__
 SmithA@Biz.net    SmithB@Biz.net    SmithC@Biz.net    SmithD@Biz.net 

=========================================
Output:

c:\temp>perl jjj.pl

Non - global, position reset even with match (/g):
 ------------------------------
SmithA@Biz.net
SmithA@Biz.net
SmithA@Biz.net


Global, position reset on non-match only (/g):
 ------------------------------
SmithA@Biz.net
SmithB@Biz.net
SmithC@Biz.net
SmithD@Biz.net
SmithD@Biz.net
 ^^^ did not match, position was reset, but $1 retained its value
SmithA@Biz.net

If, with Global /g, Capture $1, use SmithA@Biz.net in substitution:
 ------------------------------
SmithB@Biz.net
SmithB@Biz.net
 SmithA@Biz.net    <a href="mailto:SmithB@Biz.net">SmithB@Biz.net</a>    SmithC@
Biz.net    SmithD@Biz.net


If, with Global /g, NON Capture $1, use SmithB@Biz.net in substitution:
 ------------------------------
SmithA@Biz.net
Use of uninitialized value in concatenation (.) or string at jjj.pl line 48, <DA
TA> line 1.
Use of uninitialized value in concatenation (.) or string at jjj.pl line 48, <DA
TA> line 1.
Use of uninitialized value in print at jjj.pl line 49, <DATA> line 1.

 <a href="mailto:"></a>    <a href="mailto:SmithB@Biz.net">SmithB@Biz.net</a>
 SmithC@Biz.net    SmithD@Biz.net


c:\temp>


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

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 V11 Issue 2225
***************************************


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