[24576] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6752 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 30 18:05:38 2004

Date: Wed, 30 Jun 2004 15:05:08 -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           Wed, 30 Jun 2004     Volume: 10 Number: 6752

Today's topics:
        ANNOUNCE: Text::Iconv 1.3 <mxp@dynalabs.de>
    Re: Authenticating to a web form that posts to a jsp. <spamtrap@dot-app.org>
    Re: Getting to variables contained in a typeglob refere (Anno Siegel)
    Re: Getting to variables contained in a typeglob refere <this.is@invalid>
    Re: Getting to variables contained in a typeglob refere <skuo@mtwhitney.nsc.com>
    Re: Getting to variables contained in a typeglob refere <skuo@mtwhitney.nsc.com>
        Help Using Expect (Jim)
    Re: HTTP::Request, trailing slash <sebastian.baua@t-online.de>
    Re: HTTP::Request, trailing slash <gnari@simnet.is>
        My 1st question about locking (and other related issues <bik.mido@tiscalinet.it>
        syntax? <raven_at@home.domonet.ru>
    Re: syntax? <notvalid@email.com>
    Re: syntax? <bmb@ginger.libs.uga.edu>
    Re: syntax? <mritty@gmail.com>
    Re: Why can't I get WWW::Mechanize->find_all_links to w (Walter Roberson)
        Writing installation script with Perl? (minjie)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 30 Jun 2004 18:56:06 GMT
From: Michael Piotrowski <mxp@dynalabs.de>
Subject: ANNOUNCE: Text::Iconv 1.3
Message-Id: <I04xxI.1GC1@zorch.sf-bay.org>

I've just uploaded a new version of the Text::Iconv module to CPAN.
The main changes are:

- The Makefile.PL now tries to automatically detect whether -liconv is
  needed.  It will also give you a much more helpful error message
  when it can't find an iconv implementation.

- It is now possible to access the return value of the underlying
  iconv() function.

When it has migrated to its final destination, you should be able to
find it via
  
   <http://search.cpan.org/search?dist=Text-Iconv-1.3>
  
It's also immediately available from
  
   <http://www.dynalabs.de/mxp/perl/Text-Iconv-1.3.tar.gz>  

Here's an excerpt from the README:
  
   This module provides a Perl interface to the iconv() codeset
   conversion function, as defined by the Single UNIX Specification.
   For more details see the POD documentation embedded in the file
   Iconv.pm.

In other words (and if you aren't into terminology), this module lets
you convert text from one character set into another character set
using the iconv library, which is very likely to be already installed
on your system (if it's a UNIX or UNIX-like system).  You can also use
this module with a separate iconv implementation, such as GNU libiconv.

-- 
Michael Piotrowski, M.A.                               <mxp@dynalabs.de>
Public key at <http://www.dynalabs.de/mxp/pubkey.txt>




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

Date: Wed, 30 Jun 2004 17:42:18 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Authenticating to a web form that posts to a jsp.
Message-Id: <5I2dnepVpr8hrn7dRVn-gg@adelphia.com>

Jeremy wrote:

>  However, the site posts username/password information to a jsp, not a
> cgi.

That doesn't matter - a form is a form is a form. The client just formats
and sends the form data according to HTTP rules; it doesn't know or care
how the server deals with its end.

> I have read the LWP::UserAgent and LWP::Simple documentation, 
> and had no problem writing a script to authenticate to another site,
> but I haven't had any success here.  Any suggestions?

The site you point to isn't using HTTP Authentication. There is a form in
the page you point to; you need to mimic what that form does by assigning
the user name and password to form inputs and submitting a get or post
request to the action URL.

If the site maintains state using cookies, you'll need to handle that as
well.

sherm--

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


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

Date: 30 Jun 2004 20:44:10 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Getting to variables contained in a typeglob referenced by a scalar.
Message-Id: <cbv8mq$2ua$1@mamenchi.zrz.TU-Berlin.DE>

ddtl  <this.is@invalid> wrote in comp.lang.perl.misc:
> 
> Hello,
> 
> After 'open' is called in the following way:
> 
> open my $fh, $file;
> 
> '$fh' contains a reference to a filehandle, i.e., somewhere in the 'open'
> function there is probably a following assignment:
> 
> $fh = \*SOME_TYPEGLOB;
> 
> (and somehow that typeglob is anonymous (?), so the filehandle is
> also anonymous).

The module Symbol creates anonymous globs.  It is used in the creation
of this kind of file handle.

> If I understand correctly, it actually means that '$fh' contains
> a reference to a typeglob, because wherever there is a filehandle,
> it can be substituted for a typeglob.

I think you mean "...substituted *by* a typeglob".

> Than, if we want to get to the variables inside that typeglob, we
> have to do it in the following way:
> 
> *$fh - access the fileglob
> *$fh->{SCALAR} - access a reference to a scalar (typeglob is also a special
> 		hash)
> ${*$fh->{SCALAR}} - access the scalar itself.
> 
> But "Programming Perl" (14.4.1) mentions another, easier way -
> just use $$$fh (or @$$fh or %$$fh, etc.).
> 
> I don't understand, though, how it works - what do we access when
> $$fh is used - there is no scalar reference inside '$fh'?

It's the glob.  You need older books (Perl 4 level) to find any that talk
about (type-)globs at any length.  Their original purpose has entirely
been superseded by references.

> The book doesn't mention it as some new way of using typeglobs/references,
> which probably means that it should be clear from the previous chapters
> why and how it works, and it seems that I missed the point.
> 
> 
> The question is, then: how and why $$$fh etc. work, and where is an
> explanation for it in the book (or just in the documentation)

The fact that $fh is created as a file handle is irrelevant, it's just
a behavior of globs.  To see how globs work, observe this:

    our ( $var, @var, %var);
    $var = 123;
    %var = ( aaa => 123, bbb => 456 );
    @var = qw( boo hoo woo);

    my $glob = *var;

    print "$$glob\n";
    print "@$glob\n";
    print "$_=>$$glob{ $_} " for keys %$glob; print "\n";

 ...which prints

123
boo hoo woo
bbb=>456 aaa=>123 

So $glob behaves like a universal reference in that can be de-referenced
as a scalar, an array, a hash, and a sub (not shown).

Adding a level of (ordinary) reference works just as it should, and
results in the same output:

    my $fh = \ $glob; # same as $fh = \ *var;

    print $$$fh, "\n";
    print "@$$fh\n";
    print "$_=>$$$fh{ $_} " for keys %$$fh; print "\n";

Anno


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

Date: Thu, 01 Jul 2004 00:03:06 +0200
From: ddtl <this.is@invalid>
Subject: Re: Getting to variables contained in a typeglob referenced by a scalar.
Message-Id: <03d6e09evtlglu2o9pb6jgqsto0es7b2lf@4ax.com>


>$fh is a reference to a GLOB
>$$fh is the GLOB itself
>$$$fh is the SCALAR inside the GLOB
>

But how do you get to the typeglob using a funny character used to
access scalars - glob is not scalar. I could understand why it works if
instead of '$' it had been possible to use other funny characters as
well, like '@$fh' or '%$fh' - then i would infer: because glob contains 
everything, you can get to glob by dereferencing glob reference with
any funny character, but in fact only '$$f' gets you a glob, all the other
constructs generate an error. Then why it works? 




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

Date: Wed, 30 Jun 2004 12:58:24 -0700
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: Getting to variables contained in a typeglob referenced by a scalar.
Message-Id: <Pine.GSO.4.21.0406301251450.14629-100000@mtwhitney.nsc.com>

On Wed, 30 Jun 2004, ddtl wrote:

> 
> Hello,
> 
> After 'open' is called in the following way:
> 
> open my $fh, $file;
> 
> '$fh' contains a reference to a filehandle, i.e., somewhere in the 'open'
> function there is probably a following assignment:
> 
> $fh = \*SOME_TYPEGLOB;
> 
> (and somehow that typeglob is anonymous (?), so the filehandle is
> also anonymous).
> 
> If I understand correctly, it actually means that '$fh' contains
> a reference to a typeglob, because wherever there is a filehandle,
> it can be substituted for a typeglob.
> 
> Than, if we want to get to the variables inside that typeglob, we
> have to do it in the following way:
> 
> *$fh - access the fileglob
> *$fh->{SCALAR} - access a reference to a scalar (typeglob is also a special
> 		hash)
> ${*$fh->{SCALAR}} - access the scalar itself.
> 
> But "Programming Perl" (14.4.1) mentions another, easier way -
> just use $$$fh (or @$$fh or %$$fh, etc.).
> 
> I don't understand, though, how it works - what do we access when
> $$fh is used - there is no scalar reference inside '$fh'?
> The book doesn't mention it as some new way of using typeglobs/references,
> which probably means that it should be clear from the previous chapters
> why and how it works, and it seems that I missed the point.



$fh is a reference to a GLOB
$$fh is the GLOB itself
$$$fh is the SCALAR inside the GLOB



> The question is, then: how and why $$$fh etc. work, and where is an
> explanation for it in the book (or just in the documentation)


Perhaps this makes it clearer:

use strict;
use warnings;
use Scalar::Util;
use Symbol;

$\ = $/;

my $foo = gensym;
$$$foo = 'bar';

open ($foo, '<', '/etc/services')
    or die "Could not open file : $!";

if ( fileno($foo)
    and fileno($foo) == fileno(*$foo{IO}) ) {
    print "SAME FILE DESCRIPTOR\n";
}

print $$$foo;

# equivalently

print ${*$foo{SCALAR}};

print Scalar::Util::reftype($foo), "\n";

-- 
Hope this helps,
Steven



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

Date: Wed, 30 Jun 2004 14:41:54 -0700
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: Getting to variables contained in a typeglob referenced by a scalar.
Message-Id: <Pine.GSO.4.21.0406301437240.16216-100000@mtwhitney.nsc.com>

On Thu, 1 Jul 2004, ddtl wrote:

> 
> >$fh is a reference to a GLOB
> >$$fh is the GLOB itself
> >$$$fh is the SCALAR inside the GLOB
> >
> 
> But how do you get to the typeglob using a funny character used to
> access scalars - glob is not scalar. I could understand why it works if
> instead of '$' it had been possible to use other funny characters as
> well, like '@$fh' or '%$fh' - then i would infer: because glob contains 
> everything, you can get to glob by dereferencing glob reference with
> any funny character, but in fact only '$$f' gets you a glob, all the other
> constructs generate an error. Then why it works? 
> 


If you want the array and hash in the GLOB, then you write:
@$$fh and %$$fh respectively (not @$fh and not %$fh);

It 'works' because the deference syntax is unambiguous.  From

'perldoc perlref'

 ...

       A typeglob may be dereferenced the same way a reference can, because
       the dereference syntax always indicates the type of reference desired.
       So "${*foo}" and "${\$foo}" both indicate the same scalar variable.


-- 
Hope this helps,
Steven



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

Date: 30 Jun 2004 11:46:21 -0700
From: nep777@yahoo.com (Jim)
Subject: Help Using Expect
Message-Id: <d7e52631.0406301046.383d6992@posting.google.com>

Hi
I am using expect to automate sftp file transfers. It works fine for
files under 1MB. However it dies when It tries to grab big files. It
seems to always die at 1.4MB.  If I sftp manually, there is never a
problem. Also, if I run the script to connect to the server, then go
interactive (by using expect's interactive routine) it works. I have
tried everything from the expect.pm documentation.  Here is the
relevant code.
Thanks for any suggestions

---
#!/db/app/perl/bin/perl -w
use Expect;

$cmd = '/appl/uas/ssh/bin/sftp user@host';
$pw = 'mypassword';
$lcd = '/temp/raw_downloads';

# switch to local dir where the xferd files should go
chdir $lcd;

# spawn the sftp program
my $sftp = Expect->spawn($cmd) or die "Can't spawn cmd: $!";
# $sftp->log_stdout(0);

# wait 10 seconds for password prompt:
unless ( $sftp->expect(10, -re , '.*assword:') ) {
        print "timed out or something else went wrong\n";
        exit;
}

print $sftp "$pw\r";

# wait for sftp shell prompt:
unless ( $sftp->expect(10, -re , 'sftp>') ) {
    print "timed out or something else went wrong\n";
    exit;
}

# cd to the remote server dir to grab the files from
$sftp->send("cd /u10/seatab\r");

### IF I GO INTERACTIVE HERE, IT WORKS ######
# $sftp->interact();

# wait for the next shell prompt:
unless ( $sftp->expect(10, -re , 'sftp>') ) {
    print "timed out or something else went wrong\n";
    exit;
}

# grab the files
###### THIS IS WHERE IT DIES. #####
$sftp->send("mget TRANSACT*\r");

$sftp->soft_close();

 ...............


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

Date: Wed, 30 Jun 2004 22:32:32 +0200
From: Sebastian Bauer <sebastian.baua@t-online.de>
Subject: Re: HTTP::Request, trailing slash
Message-Id: <cbv80l$a8e$01$1@news.t-online.com>

i would accept that they dont allow me to download the image via a script,
but what drives me crazy is that i can obviously get the image via mozilla
but NO other way. I tried telnet 5 mins ago -> didnt work. So it seems i
will need to download the images by myself or i get it working any other
way. 
Thx a lot, if you have any ideas please let me know ;-)
Sebastian


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

Date: Wed, 30 Jun 2004 20:59:07 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: HTTP::Request, trailing slash
Message-Id: <cbv9f8$5dq$1@news.simnet.is>

"Sebastian Bauer" <sebastian.baua@t-online.de> wrote in message
news:cbv80l$a8e$01$1@news.t-online.com...
> i would accept that they dont allow me to download the image via a script,
> but what drives me crazy is that i can obviously get the image via mozilla
> but NO other way. I tried telnet 5 mins ago -> didnt work. So it seems i
> will need to download the images by myself or i get it working any other
> way.
> Thx a lot, if you have any ideas please let me know ;-)

sessions, referer, cookies, useragent ...

gnari





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

Date: Wed, 30 Jun 2004 21:49:09 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: My 1st question about locking (and other related issues)
Message-Id: <8466e0d0voveu5imabvircj1k7752elfr0@4ax.com>

I have a *working* .sig rotation script that begins like this:


  #!/usr/bin/perl
  
  use strict;
  use warnings;
  use POSIX;
  
  $|++;
  setsid;
  
  # ...
  # Do some administrative things like 
  # redirecting STDIN STDOUT and STDERR
  # ...
  
  fork and exit;


then it starts an infinite loop and writes to a fifo (creating it if
it doesn't exist).

Now I'd like to use some mechanism to prevent more than one copy of
the program to run at the same time on the same machine. The named
pipe is in my home, mounted on nfs.

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.

Anyway, I've really *no* experience in these matters, so can you give
me any suggestion? Also, I'm not asking you to do the job for me, but
could you please provide some minimal code snippet?

Note: I know I've read that file creation/deletion is not atomic over
nfs, but I don't think this is really a major issue, since I'll call
the script from my .bash_profile and it's hard to imagine how there
could be race conditions...

Last, I have another request: as I said above, I want to launch my
script on login, and even if it wouldn't be a problem to have it
running as a background process when I'm not logged in, I'd rather
prefer to have it exit when I exit the shell.

I know this is not strictly speaking a Perl question, but also in this
case I'd welcome an actual code snippet.


TIA,
Michele
-- 
#!/usr/bin/perl -lp
BEGIN{*ARGV=do{open $_,q,<,,\$/;$_}}s z^z seek DATA,11,$[;($,
=ucfirst<DATA>)=~s x .*x q^~ZEX69l^^q,^2$;][@,xe.$, zex,s e1e
q 1~BEER XX1^q~4761rA67thb ~eex ,s aba m,P..,,substr$&,$.,age
__END__


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

Date: Wed, 30 Jun 2004 22:27:44 +0400
From: "Sergei Shelukhin" <raven_at@home.domonet.ru>
Subject: syntax?
Message-Id: <2kgev6F251mbU1@uni-berlin.de>

Here's a line from a module I dled from CPAN today, on which it generates an
error and thus refuses to work.
The module is XML::Parser::Expat, line 368.
    my $ptr = ('=' my $ret;

What is it supposed to mean? How do I correct this line so that it would
work? It seems to be osme kind of arcane suntax construct i fail to
recognize.





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

Date: Wed, 30 Jun 2004 18:33:40 GMT
From: Ala Qumsieh <notvalid@email.com>
Subject: Re: syntax?
Message-Id: <8IDEc.79615$16.43056@newssvr29.news.prodigy.com>

Sergei Shelukhin wrote:

> Here's a line from a module I dled from CPAN today, on which it generates an
> error and thus refuses to work.
> The module is XML::Parser::Expat, line 368.
>     my $ptr = ('=' my $ret;
> 
> What is it supposed to mean? How do I correct this line so that it would
> work? It seems to be osme kind of arcane suntax construct i fail to
> recognize.

Somehow the text got garbled. Browsing through the source of that module 
on CPAN, I see this:

     my $ptr = ('=' x ($col - 1)) . '^' . "\n";
     my $ret;

--Ala


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

Date: Wed, 30 Jun 2004 14:45:48 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: syntax?
Message-Id: <Pine.A41.4.58.0406301441130.38288@ginger.libs.uga.edu>

On Wed, 30 Jun 2004, Sergei Shelukhin wrote:

> Here's a line from a module I dled from CPAN today, on which it generates an
> error and thus refuses to work.
> The module is XML::Parser::Expat, line 368.
>     my $ptr = ('=' my $ret;
>
> What is it supposed to mean? How do I correct this line so that it would
> work? It seems to be osme kind of arcane suntax construct i fail to
> recognize.

It should look like this:

    my $col = GetCurrentColumnNumber($parser);
==> my $ptr = ('=' x ($col - 1)) . '^' . "\n";
    my $ret;
    my $dosplit = $linepos < length($string);

Corruption perhaps?

Regards,

Brad


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

Date: Wed, 30 Jun 2004 15:06:31 -0400
From: Paul Lalli <mritty@gmail.com>
Subject: Re: syntax?
Message-Id: <20040630150521.H16568@barbara.cs.rpi.edu>

On Wed, 30 Jun 2004, Sergei Shelukhin wrote:

> Here's a line from a module I dled from CPAN today, on which it generates an
> error and thus refuses to work.
> The module is XML::Parser::Expat, line 368.
>     my $ptr = ('=' my $ret;
>
> What is it supposed to mean? How do I correct this line so that it would
> work? It seems to be osme kind of arcane suntax construct i fail to
> recognize.

I'd say your copy of the module is corrupt.  The copy on CPAN (first
result for searching for XML::Parser::Expat) has this as line 368-369:

    my $ptr = ('=' x ($col - 1)) . '^' . "\n";
    my $ret;

Try re-downloading.

Paul Lalli


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

Date: 30 Jun 2004 20:27:09 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: Why can't I get WWW::Mechanize->find_all_links to work?
Message-Id: <cbv7mt$4sp$1@canopus.cc.umanitoba.ca>

In article <f5f1d08b.0406300652.2b5306d2@posting.google.com>,
Peter M. Jagielski <peterj@insight.rr.com> wrote:
:I know, but if I get rid of the space between "smith," and "john", the
:URL (ie. my "query") returns an empty dataset.  Granted, the HTML is
:broken, but it works, so I have to work within those constraints.  I
:contacted the court's web master, and he couldn't care less - he said
:it works just fine if you use the web site, and that my "back-door"
:approach via Perl to getting to the data is not his problem, which is
:true.

If that's the HTML that the site is delivering back, then it would
NOT work via Netscape (at least not Netscape 4). I would suspect
that a quick run through via a WWW validation service would bruise
the webmaster's certainty. http://validator.w3.org/

-- 
   The image data is transmitted back to Earth at the speed of light
   and usually at 12 bits per pixel.


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

Date: 30 Jun 2004 13:57:21 -0700
From: minjie@excite.com (minjie)
Subject: Writing installation script with Perl?
Message-Id: <a06d6e69.0406301257.42513111@posting.google.com>

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.


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

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


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