[24581] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6757 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 1 21:06:43 2004

Date: Thu, 1 Jul 2004 18:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 1 Jul 2004     Volume: 10 Number: 6757

Today's topics:
    Re: Downloading form based web page <do.not.spam.me@work.com>
    Re: Getting to variables contained in a typeglob refere <j.g.karssenberg@student.utwente.nl>
    Re: Looking for a certain regexp (Anno Siegel)
    Re: Matching a part of a string <noreply@gunnar.cc>
    Re: Matching a part of a string <gnari@simnet.is>
    Re: Multiple email recipients using NMS Formail <noreply@gunnar.cc>
    Re: My 1st question about locking (and other related is <bik.mido@tiscalinet.it>
        Q: re the kind of reference to be bless()ed in OO perl <bik.mido@tiscalinet.it>
    Re: Q: re the kind of reference to be bless()ed in OO p <notvalid@email.com>
    Re: split crazy <tore@aursand.no>
    Re: Totally stuck <bik.mido@tiscalinet.it>
    Re: Totally stuck <bik.mido@tiscalinet.it>
    Re: Totally stuck <mritty@gmail.com>
    Re: Why can't I get WWW::Mechanize->find_all_links to w (Peter M. Jagielski)
    Re: Writing installation script with Perl? <ceo@nospam.on.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 2 Jul 2004 00:36:57 +0000 (UTC)
From: Takeshi <do.not.spam.me@work.com>
Subject: Re: Downloading form based web page
Message-Id: <cc2an9$d4k$1@titan.btinternet.com>

May tkx John - very helpful links

John Bokma wrote:
> Takeshi wrote:
> 
>> Hi,
>>
>> I'm a Perl virgin (programmed in many languages though C/C++, Java). I 
>> want to write a little script to download dynamic data generated by a 
>> form based web page. By that, I mean, one has to select options 
>> (actually one combo box item on the page) to have the data generated.
>>
>> Currently, I do this manually, by having a timer app pop up a reminder 
>> to save the data. I thought "there must be a better way to do this". I 
>> googled and came accros wget but I don't think that can handle form 
>> based web pages - it is simply good at sucking URLs. OK, the to get to 
>> the point - anyone knows how I can write a little script that will 
>> allow me to programatically select a combo box displayed on the page - 
>> and then save the page ?
> 
> 
> If you know what is selected, you can call the CGI script directly using 
> a POST or GET, and parse the result. See http://johnbokma.com/perl/
> for some small examples.
> 
> Have a peek at
> <http://search.cpan.org/~petdance/WWW-Mechanize-1.02/lib/WWW/Mechanize.pm>
> too.
> 



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

Date: Fri, 2 Jul 2004 00:41:10 +0200
From: Jaap Karssenberg <j.g.karssenberg@student.utwente.nl>
Subject: Re: Getting to variables contained in a typeglob referenced by a scalar.
Message-Id: <20040702004110.72a475c7@Captain>

On Wed, 30 Jun 2004 21:04:08 +0200 ddtl wrote:
: But if reference to a typeglob is equivalent to a reference to
: whatever type with that name I want, it should be able to say:
: 
: $$fh = 10;
: print "$$fh";

I can't tes tit right now but I think you can assign to it 
like this :

 *$fh = \'10'

you need to force the value to be understood as a scalar reference
instead of a scalar

-- 
   )   (     Jaap Karssenberg || Pardus [Larus]                | |0| |
   :   :     http://pardus-larus.student.utwente.nl/~pardus    | | |0|
 )  \ /  (                                                     |0|0|0|
 ",.*'*.,"   Proud owner of "Perl6 Essentials" 1st edition :)  wannabe


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

Date: 1 Jul 2004 22:34:58 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Looking for a certain regexp
Message-Id: <cc23ii$r06$1@mamenchi.zrz.TU-Berlin.DE>

Dale Henderson  <nilram@hotpop.com> wrote in comp.lang.perl.misc:
> >>>>> "Abigail" == Abigail  <abigail@abigail.nl> writes:
> 
>     Abigail> Checksums *can* be checked with a regexp. Regexes for
>     Abigail> certain credit cards are on my todo list for
>     Abigail> Regexp::Common. Now, if only I could find the URLs with
>     Abigail> the checksum formulas....
> 
>      I'd be very interested in seeing a regex that checked a checksum.
> 
>      I've been playing with this for a while and come up with regex
>      based replacement that works:
>     
>      #!/usr/bin/perl
> 
>      use strict;
>      use warnings;
> 
>      sub luhn{
>          # this routine assumes the length of the card number is even.
>          # it can be easily modified to odd length numbers.
>      
>          my $cc=shift;
>          $cc=~s/(\d)(\d)/($1?1x$1:0).($2?2x$2:0)/ge;
>          $cc=~s/1/11/g;
>          $cc=~s/1{10}/1/g;
>          $cc=~s/0//g;
>          return !(length($cc)%10);
>          
>          #or
>          # return length($cc)=~/0$/;
>          #or
>          #  $cc=~s/2/1/g;
>          #  return $cc=~/^(1{10})+$/;
>      }
>        
>      my $cc;  
>      
>      foreach $cc qw(1234567890123456 1234567890123452){
>          print $cc;
>          if(luhn($cc)){
>              print " -- Good\n";
>          }else{
>              print " -- Bad\n";
>          }
>      }
> 
>      camel$ luhn.pl
>      
>      1234567890123456 -- Bad
>      1234567890123452 -- Good
> 
>      However, I wonder if could be done more along the lines of 
> 
>      if ($cc=~/$re/){
>         print " -- Good\n";"
>      }

Using the (?{ code }) and (??{ code }) constructs, it can.

In particular, we can use (?{ code }) to build up the checksum in
a global variable.  Summing only the first 15 digits, we can predict
the 16th and use (?{{ code }) to insert it as the expected match.

    our ( $sum, $odd);
    my $re = qr/
        (?:               # repeat the following
            (\d)          # match and capture a digit
            (?{           # increment $sum accordingly
                $sum += ( $odd ?  $1 : ( $1 == 9) ? 9 : (2*$1) % 9);
                $odd = not $odd;
            })
        ){15}             # repeat for 15 digits
        (??{              # predict and match 16th digit
            -$sum % 10;
        })
    /x;

    for ( qw( 1234567890123456 1234567890123452) ) {
        my $verdict = /$re/ ? 'Good' : 'Bad';
        print "$_ -- $verdict\n";
    }


Of course, this still isn't a pure regex solution, it uses non-regex
Perl code.

Anno


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

Date: Fri, 02 Jul 2004 00:06:06 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Matching a part of a string
Message-Id: <2kjg5nF35jpeU1@uni-berlin.de>

TonyShirt wrote:
> I have a string "FILEVERSION 1,01,0,21\n"
> I want to match only the numbers "1,01,0,21"
> 
> i'm using /([0-9]+,[0-9]+,[0-9]+,[0-9]+)/
> but I'm still getting the whole string.  Why?

Since we are not mind readers in this group, you need to post a short 
but complete program that illustrates the problem. If you do, somebody 
can point out what it is you are doing wrong.

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


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

Date: Thu, 1 Jul 2004 23:05:47 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: Matching a part of a string
Message-Id: <cc258o$gsp$1@news.simnet.is>

"TonyShirt" <tonyshirt@hotmail.com> wrote in message
news:52d54c07.0407011338.1c42a32e@posting.google.com...
> I have a string "FILEVERSION 1,01,0,21\n"
> I want to match only the numbers "1,01,0,21"
>
> i'm using /([0-9]+,[0-9]+,[0-9]+,[0-9]+)/
> but I'm still getting the whole string.  Why?  I know its easier (At
> this point) to just split the string by \s, but I just cant give it
> up!

there probably is somemthing wrong with how you are 'getting' it

  my $x="FILEVERSION 1,01,0,21\n";
  print "gotit: ($1)\n" if $x=~/([0-9]+,[0-9]+,[0-9]+,[0-9]+)/;

gnari





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

Date: Fri, 02 Jul 2004 02:34:13 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Multiple email recipients using NMS Formail
Message-Id: <2kjos3F36651U1@uni-berlin.de>

Adam wrote:
> I am using Version 3.12c1 of NMS FormMail.
> 
> I am unable to get the script to post to mulitple email accounts.

Doesn't the documentation explain how you do that?

> The mail will only get sent to the first email account
> in the '@allow_mail_to' array.
> 
> How can I have the mail forward on to multiple accounts ?
> 
> The script is standard apart from some formatting changes to the
> generated html.
> 
> [snip]
>   $max_recipients    = 5;
>   $mailprog          = '/usr/lib/sendmail -oi -t';
>   $postmaster        = '';
>   @referers          = qw(mydomain.com);
>   @allow_mail_to     = qw(email1@mydomain.com email2@mydomain.com);
>   @recipients        = ();

What's the purpose of the @recipients array?

Note that this group is not the right place to seek help with 
configuring a script. If the docs isn't sufficient, asking the authors 
is the natural next step.

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


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

Date: Fri, 02 Jul 2004 00:21:32 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: My 1st question about locking (and other related issues)
Message-Id: <jh29e05j6qjpqvv8qvd3cgsm7fna5ddv2r@4ax.com>

On 1 Jul 2004 09:53:22 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno
Siegel) wrote:

>> I've thought of using a lockfile, but then since I can be logged at
>> the same time on different machines, I *think* I should write in it
>> the hostname, possibly along with other info.
>
>I wouldn't write the hostname in the lockfile but name the lockfile
>after the host.  In fact, you don't need explicit file locking,
>the existence of the lockfile can be used.  The usual problem with
>this approach is to reliably remove the lockfile when the program
>terminates.  %SIG handlers and an END block cover most of that.

[snip code]

Thank you so much for the supplied code, I really appreciated that! In
fact I noticed that some other programs do something very similar...
it still seems a bit of an overhead for such a simple script.

I was wondering if there could be the possibility of using the named
pipe itself to determine if there's already a copy of $0 running, i.e.
trying to read from it and if nothing comes out in a certain amount of
time (but then how much time?!?) then decide that it is not. Not
terribly reliable, I guess, but... just curious about this
possibility!

Also, could you be so kind to answer my other question or give a
suggestion just as good as this one wrt it? I mean: how can make my
script exit on logging out of the shell from which it was started?


TIA again,
Michele
-- 
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
  "perl bug File::Basename and Perl's nature"


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

Date: Fri, 02 Jul 2004 00:21:33 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Q: re the kind of reference to be bless()ed in OO perl
Message-Id: <t239e0pkaqb27mm1qsscvovjc4e4l95dh2@4ax.com>

I must say in advance that I know the most basic aspects of OO
programmin in Perl, but I've never been really proficient with it. So
pardon my ignorance...

It is often said that the reference that gets bless()ed to create an
object is one to an anonymous hash, which makes perfectly sense, as
the examples abunding everywhere clearly indicate.

I've also seen bless()ing something like an empty {array,hash}ref to
be used "solely" as an index into a package/class global hash to
enforce some degree of encapsulation.

Now I wonder if there are common/cool/smart/witty cases in which it is
natural to use a reference to some other kind of object, like e.g. a
sub, or filehandle, etc.


Michele
-- 
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
  "perl bug File::Basename and Perl's nature"


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

Date: Thu, 01 Jul 2004 22:46:57 GMT
From: Ala Qumsieh <notvalid@email.com>
Subject: Re: Q: re the kind of reference to be bless()ed in OO perl
Message-Id: <Bv0Fc.7101$hA2.2118@newssvr27.news.prodigy.com>

Michele Dondi wrote:

> I've also seen bless()ing something like an empty {array,hash}ref to
> be used "solely" as an index into a package/class global hash to
> enforce some degree of encapsulation.

I'm not sure what you mean there. Can you show a code snippet please?

Note that bless() returns the blessed reference, so it can be used as 
the last statement of the constructor to return the object (blessed 
reference).

> Now I wonder if there are common/cool/smart/witty cases in which it is
> natural to use a reference to some other kind of object, like e.g. a
> sub, or filehandle, etc.

I believe Damian Conway has a few examples in his Object-Oriented Perl 
book. Personally, I have written many Perl classes, and can only recall 
one that didn't use a hashref for the object representation (I used an 
arrayref, to be precise, since the data structure I was after was easily 
representable as a matrix).

--Ala


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

Date: Fri, 02 Jul 2004 02:08:18 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: split crazy
Message-Id: <pan.2004.07.02.00.08.18.699764@aursand.no>

On Thu, 01 Jul 2004 04:22:22 +0000, Jeff Thies wrote:
> I have this:
> 
> my $s='xxxxxxxx';
> 
> my @split= /x/,$s;
> 
>  I thought I would get: ('','','','','','','')
> 
> But I get: ()
> 
> How do I get what I intended?  I've tried a lot of things that don't work!

Your requirements are a bit vague, but why do you need split for this?

  my $string = 'xxxx';
  my @array  = ('') x length( $string );


-- 
Tore Aursand <tore@aursand.no>
"When you see a good idea look for a better one. You should never play
 the first good move that comes into your head." (Bruce Pandolfine)


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

Date: Fri, 02 Jul 2004 00:21:30 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Totally stuck
Message-Id: <vi19e01of36nhd3isr41c5pf8nbqe06v1h@4ax.com>

On Wed, 30 Jun 2004 22:31:53 -0700, "187"
<bigal187.invalid@adexec.com> wrote:

>> "working version" and I tried it on your sample. Now, if I'm not
>> mistaken, the following should serve your needs and is considerably
>> simpler:
>>
>>   #!/usr/bin/perl -ln
>>
>>   print, next unless /\\backtomargin/;
>
>I dont udnerstand whats going on here. I thought 'next' can only be used
>in loops, but here you're tryign to print something? Very confusing,

In fact we *are* in a loop. But you've already been explained this by
someone else. Here I'll add only that issuing

  perl -MO=Deparse new.pl

(assuming the script was called 'new.pl') you will see what's going on
behind the scenes:

  BEGIN { $/ = "\n"; $\ = "\n"; }
  LINE: while (defined($_ = <ARGV>)) {
      chomp $_;
      print($_), next unless /\\backtomargin/;
      {
          local $/ = '';
          chomp(my $par = <ARGV>);
          print
"\\begin{instructions}\n$par\n\\end{instructions}\n\n";
      }
  }
  __DATA__

>And I don't see how you've opened the file. I thought <> read from a
>file passed though STDIN, but you say below "no need for '<'" but
>withotu that you're just passing "new" to new.pl, and not the file
>contends, or am I missing something here..? Thanks for any explainations
>you can give, aas I'm quite confused :(

Again, you've already been told that. And the answer is in the docs,
as always, but then someone kindly pointed you to the relevant
entries.

Last, I notice only now that the OP's code contained the following
lines

      if ($line=~/^\s*\\backtomargin/) {
  	push (@instructions,$');

suggesting that "\backtomargin" may not come alone on a line, so a
slightly better approximation to what he really wants may be:


  #!/usr/bin/perl -lp
  
  next unless s/.*\\backtomargin//;
  {
      local $/='';
      chomp(my $par=<>);
      $_ .= <<EOT;
  \n\\begin{instructions}
  $par
  \\end{instructions}
  
  EOT
  }
  
  __END__


This is even somewhat simpler than the previous one and... you see?
*Apparently* not even any print() there!!


Michele
-- 
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
  "perl bug File::Basename and Perl's nature"


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

Date: Fri, 02 Jul 2004 00:21:31 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Totally stuck
Message-Id: <5um8e0hjj7bt58tt1p8vl481vurvj84fle@4ax.com>

On Thu, 1 Jul 2004 14:02:46 -0400, Paul Lalli <mritty@gmail.com>
wrote:

>This actually confuses me.  the original code was (effectively):
>perl -ln -e 'print, next unless /\\backtomargin/;'
>
>From what I can tell, it looks like the statement containing the print and
>next is a comma-separated list being evaluated in void context.  In scalar
>context, the comma operator evaluates each of its operands from left to
>right, discarding the return values of all but the last.   Using that
>logic, shouldn't the print be evaluated before the next?

It is, but only if !/\\backtomargin/, i.e. on /\\backtomargin/ it
won't print *and* it won't C<next>.


Michele
-- 
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
  "perl bug File::Basename and Perl's nature"


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

Date: Thu, 01 Jul 2004 23:50:44 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Totally stuck
Message-Id: <or1Fc.204000$j24.118764@twister.nyroc.rr.com>

"Michele Dondi" <bik.mido@tiscalinet.it> wrote in message
news:5um8e0hjj7bt58tt1p8vl481vurvj84fle@4ax.com...
> On Thu, 1 Jul 2004 14:02:46 -0400, Paul Lalli <mritty@gmail.com>
> wrote:
>
> >This actually confuses me.  the original code was (effectively):
> >perl -ln -e 'print, next unless /\\backtomargin/;'
> >
> >From what I can tell, it looks like the statement containing the print
and
> >next is a comma-separated list being evaluated in void context.  In
scalar
> >context, the comma operator evaluates each of its operands from left to
> >right, discarding the return values of all but the last.   Using that
> >logic, shouldn't the print be evaluated before the next?
>
> It is, but only if !/\\backtomargin/, i.e. on /\\backtomargin/ it
> won't print *and* it won't C<next>.

Okay.  I think I understand.  So you're saying
perl -lne 'print, next unless /foo/'
is equivalent to
perl -lne 'do {print; next;} unless /foo/'

Is that correct?  If so, then I guess my question to the original poster of
that code is what's the point of the 'next' at all?  Wouldn't simply   '
print unless /foo/ '  do the same thing?   (that is, it would do the same
thing in the simple example posted where the line  ' print, next unless
/foo/ ' is the only line in a program run with the -ln options).  As 'next'
would be the last thing evaluated in the loop block, it would seem to serve
no purpose.

Am I missing something obvious?

Thank you,
Paul lalli




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

Date: 1 Jul 2004 15:25:48 -0700
From: peterj@insight.rr.com (Peter M. Jagielski)
Subject: Re: Why can't I get WWW::Mechanize->find_all_links to work?
Message-Id: <f5f1d08b.0407011425.1f86eb4c@posting.google.com>

Thanks Andrew, that *was* simple.


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

Date: Thu, 01 Jul 2004 22:35:16 GMT
From: ChrisO <ceo@nospam.on.net>
Subject: Re: Writing installation script with Perl?
Message-Id: <Ek0Fc.73$593.24@newssvr16.news.prodigy.com>

minjie wrote:
> Hello,
> 
> Does anyone have experience in writing installation script with Perl?
> Is it feasible to use Perl to package programs for installation, if I
> do not use a professional installation buidling tool (such as
> InstallShield)? If so, is there any Perl module for this purpose?
> Where can I find examples?
> 
> Note: I need to build installation packages for both Windows and
> Linux.
> 
> Thanks.

It's entirely possible and yea, even recommended.  Have a look at IBM's 
Tivoli product for one commercial example.  Home grown solutions abound.

-ceo


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

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 6757
***************************************


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