[24528] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6708 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jun 19 14:05:52 2004

Date: Sat, 19 Jun 2004 11:05:07 -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           Sat, 19 Jun 2004     Volume: 10 Number: 6708

Today's topics:
    Re: Embedding perl in Java <usenet@morrow.me.uk>
    Re: Encoding question <dickey@saltmine.radix.net>
    Re: Encoding question <usenet@morrow.me.uk>
    Re: float storage <usenet@morrow.me.uk>
    Re: float storage (ivo welch)
    Re: Help with a "Post" procedure. <jimsimpson@cox.net>
        Help with a "Post" procedure <jimsimpson@cox.net>
        Problem of "Too many open files" (Yash)
    Re: Problem of "Too many open files" <usenet@morrow.me.uk>
    Re: remove redundant elements in an array (Anno Siegel)
    Re: remove redundant elements in an array (Anno Siegel)
    Re: sorting text <noreply@gunnar.cc>
    Re: while grep filehandle <raisin@delete-this-trash.mts.net>
    Re: while grep filehandle <usenet@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 19 Jun 2004 13:50:33 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Embedding perl in Java
Message-Id: <cb1gb8$81h$1@wisteria.csv.warwick.ac.uk>


Quoth shalinij1@yahoo.com (Shalini Joshi):
> 
> I found out about the JPL module that allows us to write perl code
> within a java program and vice versa.
> 
> The reason I'd be interested in this particular thing is that we dont
> want our clients to actually see the source code(i am guessing there
> is no way to hide a perl script from a user and just give an
> executable kind-of, since it's a script). So to actually produce a
> product we thought of embedding the script in a java program and
> compiling it and then the byte code could be supplied to the client.
> 
> Is this reasoning/line of thought correct? And if so, how do I go
> about using jpl and designing the program?

No. The Perl source would still be visible; the user would still need
Perl installed.

For advice on (the futility of) concealing Perl code in general, see
perldoc -q hide.

Ben

-- 
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/'                                                 # ben@morrow.me.uk


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

Date: Sat, 19 Jun 2004 14:19:43 -0000
From: Thomas Dickey <dickey@saltmine.radix.net>
Subject: Re: Encoding question
Message-Id: <10d8irvopedq0d2@corp.supernews.com>

Michael Krueger <kruger@math.fu-berlin.de> wrote:


> On Fri, 18 Jun 2004, Ben Morrow wrote:
> thx for your fast reply, this really helped me alot.
> I'll try it with Unicode then.

> Just want to draw those darn boxes ; )

He gave poor advice however.  Most of the interesting terminals support
line-drawing, which any termcap interface (such as the one in Perl) can
support.

The current version of ncurses is 5.4 (20040208)
There's an faq at
	http://invisible-island.net/ncurses/ncurses.faq.html

-- 
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net


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

Date: Sat, 19 Jun 2004 14:24:19 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Encoding question
Message-Id: <cb1iaj$8ai$5@wisteria.csv.warwick.ac.uk>


Quoth Thomas Dickey <dickey@saltmine.radix.net>:
> Michael Krueger <kruger@math.fu-berlin.de> wrote:
> 
> 
> > On Fri, 18 Jun 2004, Ben Morrow wrote:
> > thx for your fast reply, this really helped me alot.
> > I'll try it with Unicode then.
> 
> > Just want to draw those darn boxes ; )
> 
> He gave poor advice however.  Most of the interesting terminals support
> line-drawing, which any termcap interface (such as the one in Perl) can
> support.

Ah, I didn't know that... filed for future reference. Thank you.

FWIW, I always do boxes just with '+', '-' and '|'...

Ben

-- 
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/'                                                 # ben@morrow.me.uk


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

Date: Sat, 19 Jun 2004 14:16:22 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: float storage
Message-Id: <cb1hrm$8ai$3@wisteria.csv.warwick.ac.uk>


Quoth tassilo.parseval@post.rwth-aachen.de:
> Also sprach ivo welch:
> 
> > hi perl gurus:  I would like to read about 1GB of floats, not doubles.
> >  Does perl have the facility to designate internal storage of an array
> > to be in float (4-byte), not double (8-byte) representation? 
> > Otherwise, I am running out of memory...
> 
> Other than using Inline/XS as Ben suggested, you can try to go the
> slightly cheaper path by using a packed string.

 ...and of course you could write a (Perl, not XS) class to tie an array
to this packed string. Silly, I should have thought of that :)

Ben

-- 
"If a book is worth reading when you are six,                * ben@morrow.me.uk
it is worth reading when you are sixty." - C.S.Lewis


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

Date: 19 Jun 2004 10:45:27 -0700
From: ivo.welch@anderson.ucla.edu (ivo welch)
Subject: Re: float storage
Message-Id: <5159bba2.0406190945.45413bca@posting.google.com>

(yes, 1GB is 4-byte float data size.  yes, I could change the
algorithm.  what I should do is use an data base---but that would mean
installing one and learning SQL for a 1-time application.)

thank you everyone.  probably back to C++ for me.  it's been a long
time---hope I still remember it.  now that I have used perl for a
while, C++ really seems like a dinosaur.  the string and array
handling is truly awkward.

regards,

/iaw


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

Date: Sat, 19 Jun 2004 10:39:08 -0400
From: "Jim Simpson" <jimsimpson@cox.net>
Subject: Re: Help with a "Post" procedure.
Message-Id: <FeYAc.3415$wD3.1250@lakeread03>

In a Google search for other postings on the same subject I happened across
my posting along with a response as follows:
Message 2 in thread
From: Matt Garrish (matthew.garrish@sympatico.ca)
Subject: Re: Help with a "Post" procedure.

View this article only
Newsgroups: comp.lang.perl.misc
Date: 2004-06-18 14:51:24 PST

"Jim Simpson" <jimsimpson@cox.net> wrote in message
news:wgFAc.791$HN5.60@lakeread06...
> I am trying to automate logging in  to an HTTPS site which requires a
"user
> name" and "password". It appears to me that the following code should do
the
> job - but it does not do it. Can someone help me out on this.
>
> I'm especially concerned about the "post" line. I do not understand what
> should be in the places where I have used 'text', 'password' and 'submit'.
>

You need to take a step back and learn some basic html. When you submit a
form, each field has (should have!) a name (i.e., <input name="somthing">)
which is used to identify the variable(s) being sent to the server. Username
and password are often used for fields on login pages, but no one says they
have to be. You need to read the source of the page you're trying to log on
to and see what variables actually need to be sent. You can then modify the
post line to send the correct name/value pairs (i.e., fieldname => 'value').

Matt

I don't understand why Matt's response doesn't appear in this listing.

However - thanks Matt for your comment. I should have explained that I did
try to determine what variables should be sent.

 The source code includes the following:
"<input type=text name="username" size="15"  maxlength="35"
AUTOCOMPLETE="off">"
That's why I used "text" in my script.

 . It also contains the following:
 "<input type="password" name="password" size="15" ONKEYDOWN="return
handleEnterSubmission( this.form , event)"  maxlength="35"
AUTOCOMPLETE="off">"
 That's why I used "password".

For the button it includes the following:
 "<input type="image" name="submit" value="Submit"
SRC="/images/login/log_on.gif" border="0">"
I'm not at all sure that the button variable is correct or how the "post"
line of script should indicate that the button is "on".

I need some more help please.

Jim

"Jim Simpson" <jimsimpson@cox.net> wrote in message
news:wgFAc.791$HN5.60@lakeread06...
> I am trying to automate logging in  to an HTTPS site which requires a
"user
> name" and "password". It appears to me that the following code should do
the
> job - but it does not do it. Can someone help me out on this.
>
> I'm especially concerned about the "post" line. I do not understand what
> should be in the places where I have used 'text', 'password' and 'submit'.
>
> All help will be greatly appreciated.
>
> Jim
>
> #########################
> #A program to login to a secure site which requires a "user name" and
> password".
> #Load the source code of the site into a Microsoft Word document.
> #Using Windows 98 and ActivePerl v5.8
> #########################
>
> use strict;
> use Data::Dumper;
> use LWP::UserAgent;
> use HTTP::Cookies;
> use Win32::OLE::Const 'Microsoft Word';
>
> my $https_login = 'url of login sheet sought';
> my $https_user = 'my user name';
> my $https_pass = 'my password';
>
> #get already active Word application or open new
>   my $Word = Win32::OLE->GetActiveObject('Word.Application')
>       ||Win32::OLE->new('Word.Application', 'Quit');
>
>   my $book = $Word->Documents("PrintOut.doc");
>
> #  secure login
>   my $ua = LWP::UserAgent->new();
>   $ua->protocols_allowed( [ 'https'] );
>   $ua->cookie_jar(HTTP::Cookies->new(file => ".cookies.txt", autosave =>
> 1));
>   my $response = $ua->post($https_login, [ 'text' => "$https_user",
> 'password' => "$https_pass", 'submit' => "Log On" ] );
>
>   $book->words(1)->{'text'} = Dumper($response);
>
>




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

Date: Sat, 19 Jun 2004 11:48:23 -0400
From: "Jim Simpson" <jimsimpson@cox.net>
Subject: Help with a "Post" procedure
Message-Id: <AfZAc.3420$wD3.659@lakeread03>

Some of these postings got lost and I have tried to reassemble them.
Jim

I am trying to automate loging in  to an HTTPS site which requires a "user
name" and "password". It appears to me that the following code should do the
job - but it does not do it. Can someone help me out on this.

I'm especially concerned about the "post" line. I do not understand what
should be in the places where I have used 'text', 'password' and 'submit'.

All help will be greatly appreciated.

Jim

#########################
#A program to login to a secure site which requires a "user name" and
password".
#Load the source code of the site into a Microsoft Word document.
#Using Windows 98 and ActivePerl v5.8
#########################

use strict;
use Data::Dumper;
use LWP::UserAgent;
use HTTP::Cookies;
use Win32::OLE::Const 'Microsoft Word';

my $https_login = 'url of login sheet sought';
my $https_user = 'my user name';
my $https_pass = 'my password';

#get already active Word application or open new
  my $Word = Win32::OLE->GetActiveObject('Word.Application')
      ||Win32::OLE->new('Word.Application', 'Quit');

  my $book = $Word->Documents("PrintOut.doc");

#  secure login
  my $ua = LWP::UserAgent->new();
  $ua->protocols_allowed( [ 'https'] );
  $ua->cookie_jar(HTTP::Cookies->new(file => ".cookies.txt", autosave =>
1));
  my $response = $ua->post($https_login, [ 'text' => "$https_user",
'password' => "$https_pass", 'submit' => "Log On" ] );

  $book->words(1)->{'text'} = Dumper($response);


From: Matt Garrish (matthew.garrish@sympatico.ca)
Subject: Re: Help with a "Post" procedure.


Newsgroups: comp.lang.perl.misc
Date: 2004-06-18 14:51:24 PST


"Jim Simpson" <jimsimpson@cox.net> wrote in message
news:wgFAc.791$HN5.60@lakeread06...
> I am trying to automate logging in  to an HTTPS site which requires a
"user
> name" and "password". It appears to me that the following code should do
the
> job - but it does not do it. Can someone help me out on this.
>
> I'm especially concerned about the "post" line. I do not understand what
> should be in the places where I have used 'text', 'password' and 'submit'.
>

You need to take a step back and learn some basic html. When you submit a
form, each field has (should have!) a name (i.e., <input name="somthing">)
which is used to identify the variable(s) being sent to the server. Username
and password are often used for fields on login pages, but no one says they
have to be. You need to read the source of the page you're trying to log on
to and see what variables actually need to be sent. You can then modify the
post line to send the correct name/value pairs (i.e., fieldname => 'value').

<<<<<<<<<<<<<<,

Matt

Matt thanks for responding to my posting.

I should have explained that I did try to determine the correct variables to
use. I found the following in the source code for the login sheet that I
thought applied to "username" and that is why I used "text" in my code.
<input type=text name="username" size="15"  maxlength="35"
AUTOCOMPLETE="off">

And the following that is why I used "password"
<input type="password" name="password" size="15" ONKEYDOWN="return
handleEnterSubmission( this.form , event)"  maxlength="35"
AUTOCOMPLETE="off">

And the following that I assume applies to the "button" confused me - but I
made a stab at it. I'm not sure how I show that the button has been pushed.
<input type="image" name="submit" value="Submit"
SRC="/images/login/log_on.gif" border="0">

Also i understand that some secure sites may encript the data going in. How
can I determine if that is required for this site?

I need more help please.

Jim




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

Date: 19 Jun 2004 07:03:26 -0700
From: yashgt@gmail.com (Yash)
Subject: Problem of "Too many open files"
Message-Id: <4f428e7b.0406190603.74a0bd6b@posting.google.com>

Hi,
I am facing a problem with a Perl 5.6.1 program on HP-Ux 11i.
My program reads lines from a set of hundreds of files and based on a
particular field in every line, redistributes the lines to a new set
of files.
A new file is created using:
$fh{$timePartition} = IO::File->new("> $ENDIR/$timePartition.new") or
print LOGFILE "$!\n";


While running the program, I get an error at the above line saying
"Too many open files"

This is because I close the file descriptors after I am done with all
the input files.

Is there a way I can get around the problem from within Perl, by
increasing the value of some special variable?
If that is not possible, what system parameter should I increase to
avoid the problem?

Thanks


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

Date: Sat, 19 Jun 2004 14:11:08 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Problem of "Too many open files"
Message-Id: <cb1hhs$8ai$2@wisteria.csv.warwick.ac.uk>


Quoth yashgt@gmail.com (Yash):
> Hi,
> I am facing a problem with a Perl 5.6.1 program on HP-Ux 11i.
> My program reads lines from a set of hundreds of files and based on a
> particular field in every line, redistributes the lines to a new set
> of files.
> A new file is created using:
> $fh{$timePartition} = IO::File->new("> $ENDIR/$timePartition.new") or
> print LOGFILE "$!\n";

I wouldn't use IO::File... nowadays it has been superseded by lexical FHs:

open $fh{$timePartition}, '>', "$ENDIR/$timePartition.new"
    or print LOGFILE "can't create '$ENDIR/$timePartition.new': $!\n";

I would also consider overriding CORE::GLOBAL::die to write to the logfile and
using that instead.

> While running the program, I get an error at the above line saying
> "Too many open files"
> 
> This is because I close the file descriptors after I am done with all
> the input files.
> 
> Is there a way I can get around the problem from within Perl, by
> increasing the value of some special variable?

No.

> If that is not possible, what system parameter should I increase to
> avoid the problem?

man ulimit

Ben

-- 
  Joy and Woe are woven fine,
  A Clothing for the Soul divine       William Blake
  Under every grief and pine          'Auguries of Innocence'
  Runs a joy with silken twine.                                ben@morrow.me.uk


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

Date: 19 Jun 2004 13:10:44 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: remove redundant elements in an array
Message-Id: <cb1e0k$3er$2@mamenchi.zrz.TU-Berlin.DE>

Bob Walton  <see@sig.invalid> wrote in comp.lang.perl.misc:
> Yiping Zhan wrote:
> 
> > Say, @a = qw(1 2 3 1 4 5);
> > 
> > What is a good way to get (1 2 3 4 5)?
> ...
> > -- Newbie
> > 
> 
> @b{@a}=1;@b=sort keys %b;

Assigning 1 to the hash slice is a little misleading, don't you think?
It assigns 1 to what happens to be first in @a, and undef to the rest.
The reader would have to wonder about the special treatment and find
out that it doesn't matter.  "@b{ @a} = ()" is clearer.

Anno



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

Date: 19 Jun 2004 13:12:20 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: remove redundant elements in an array
Message-Id: <cb1e3k$3er$3@mamenchi.zrz.TU-Berlin.DE>

Yiping Zhan  <yzhan@andrew.cmu.edu> wrote in comp.lang.perl.misc:
> Say, @a = qw(1 2 3 1 4 5);
> 
> What is a good way to get (1 2 3 4 5)?

    my %h;
    my @a = grep ! $h{ $_} ++, qw( 1 2 3 1 4 5);

Anno


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

Date: Sat, 19 Jun 2004 18:36:32 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: sorting text
Message-Id: <2jj8ddF129e7pU1@uni-berlin.de>

jamasd@hotmail.com wrote:
> Gunnar Hjalmarsson wrote:
>> jamasd@hotmail.com wrote:
>>> Right now it is printing out the entire file in one line.
>> 
>> ??
>> 
>> Please show us the *whole* program that gives that result.
> 
> Here is my fully program:

<program snipped>

> Now it is just printing a blank screen, which is not what i wanted.

Hmm.. In your previous post you said it was "printing out the entire
file in one line". Maybe you simply need to be more careful, and take
the time to really understand what you are doing...

Anno suggested that the file (giving the *latest* result) is not tab
delimited, after all. I'm not able to find any other explanation.

Also, do consider Anno's style related advices.

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



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

Date: Sat, 19 Jun 2004 09:18:42 -0500
From: Web Surfer <raisin@delete-this-trash.mts.net>
Subject: Re: while grep filehandle
Message-Id: <MPG.1b3e073cb452405d989834@news.mts.net>

[This followup was posted to comp.lang.perl.misc]

In article <b5d78542.0406180835.bf830e3@posting.google.com>, 
jgilber@yahoo.com says...
> Unix command line:
> 
> grep Results File.txt
> 
> Returns lots of lines:
> 
> Results = 1
> Results = 11
> Results = 2
> 
> etc, etc, etc.
> 
> Perl script:
> 
> #!/usr/bin/perl
> 
> open (IN, "< File.txt");
> 
>   while ( grep /Results/, <IN> ) {
>     print "$_\n";
>   }
> 
> close (IN);
> 
> Returns nothing.  Why?
> 

You are not using grep correctly. The result returned by grep is not a 
TRUE/FALSE value intended to be used as a logical test in a conditional 
statement, but rather is an array containing the matched entries.


#!/usr/bin/perl

use warnings;
use strict;

my ( $filename , @matches );

$filename = "File.txt";
open(IN,"<$filename") or
		die("Can't open $filename : $!\n");

@matches = grep(/Results/,<IN>);
close IN;
print @matches;

exit 0;


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

Date: Sat, 19 Jun 2004 14:25:51 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: while grep filehandle
Message-Id: <cb1idf$8ai$6@wisteria.csv.warwick.ac.uk>


Quoth Web Surfer <raisin@delete-this-trash.mts.net>:
> [This followup was posted to comp.lang.perl.misc]

I know, that's where I read it.

> You are not using grep correctly. The result returned by grep is not a 
> TRUE/FALSE value intended to be used as a logical test in a conditional 
> statement, but rather is an array containing the matched entries.

In list context, yes; in scalar context, grep returns the number of
matches, which when treated as a boolean gives if there were any at all.

Ben

-- 
  Joy and Woe are woven fine,
  A Clothing for the Soul divine       William Blake
  Under every grief and pine          'Auguries of Innocence'
  Runs a joy with silken twine.                                ben@morrow.me.uk


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

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


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