[18411] in Perl-Users-Digest
Perl-Users Digest, Issue: 579 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 28 14:11:40 2001
Date: Wed, 28 Mar 2001 11:11:20 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <985806679-v10-i579@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 28 Mar 2001 Volume: 10 Number: 579
Today's topics:
Extracting data from a file <bag_end@clark.net>
Re: Extracting data from a file (Tad McClellan)
Re: Extracting data from a file (Jay Tilton)
Re: Extracting data from a file <thomastk@prodigy.net>
flock with file dup fails <johnlin@chttl.com.tw>
Re: flock with file dup fails (Mark Jason Dominus)
Re: flock with file dup fails (Mark Jason Dominus)
Re: flock with file dup fails <johnlin@chttl.com.tw>
Re: flock with file dup fails <johnlin@chttl.com.tw>
Re: flock with file dup fails nobull@mail.com
Re: form post parameter looks like directory but is a s d.lebbing@*no*spam*.iquip.nl
GD library newbie question <llarmengol@iro.es>
Re: GD library newbie question (Martien Verbruggen)
Re: Good Perl Code Syntax Highlighting Editor for Linux <goldbb2@earthlink.net>
Re: Good Perl Code Syntax Highlighting Editor for Linux (Carsten Saathoff)
Re: grep(EXPR,LIST) behaves strangely <ronald.fischer.gp@icn.siemens.de>
Re: grep(EXPR,LIST) behaves strangely <bart.lateur@skynet.be>
Help, looking for a learning perl video <jimts@prodigy.net>
how to access HTML pages with username and password <BOBOC@eltcv.epfl.ch>
How to use Net::Telnet? <jackkon@pchome.com.tw>
Re: HTTP Headers <djmarcus@ex-pressnet.com>
Is there an easier way of doing this? (Multiple file ha (e)
Re: LWP help <gisle@ActiveState.com>
Re: More Help please :-) <comdog@panix.com>
Re: More Help please :-) <uri@sysarch.com>
Re: More Help please :-) (Damian James)
Re: Most efficient way to extract unique array elements (H. Merijn Brand)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 28 Mar 2001 03:37:43 GMT
From: adventure <bag_end@clark.net>
Subject: Extracting data from a file
Message-Id: <b0dw6.17579$FS3.217472@sjc-read.news.verio.net>
Hi there,
I am in over my head on this - I am trying to extract the data on two
lines (the second and the fourth) from the following (output of the free
-m command).
total used free shared buffers cached
Mem: 250 67 182 39 26 20
-/+ buffers/cache: 20 230
Swap: 517 0 517
My solution thus far is:
while (<FREE>) {
chomp;
if ($. = 2) {
($mem, $total, $used, $free, $shared, $buf, $cache) = split
/\b[0-9]\b/;
} elsif ($. = 4) {
($swap, $stotal, $sused, $sfree) = split
/\b[0-9]\b/;
}
};
The problem is that nothing seems to be being split out. When I simply
loop through the file, the contents of each line are dumped into $mem and
the rest are empty. I figure I am:
1) Doing the split wrong
2) Doing the if/elsif incorrectly at least
3) Doing it the hard way.
At the end of the day, the $mem and $swap variables will be tossed, and
the values pushed into an Oracle database through DBI (which I haven't
written yet).
Thanks for any advice,
DAVID
--
---------------------------------------------------
David A. Lane, CNE
ERP Technical Lead
ManTech International Corp.
+1.703.218.8241 VOICE
+1.703.218.8391 FAX
PGP ID: 679DF4EE
------------------------------
Date: Tue, 27 Mar 2001 22:43:03 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Extracting data from a file
Message-Id: <slrn9c2ne7.f6j.tadmc@tadmc26.august.net>
adventure <bag_end@clark.net> wrote:
>
>I am in over my head on this -
Looks to me like you are not asking for all the help you can get.
Enable warnings.
Turn on strictures.
#!/usr/bin/perl -w
use strict;
>I am trying to extract the data on two
>lines (the second and the fourth) from the following (output of the free
>-m command).
>
> total used free shared buffers cached
>Mem: 250 67 182 39 26 20
>-/+ buffers/cache: 20 230
>Swap: 517 0 517
>
>My solution thus far is:
>
>while (<FREE>) {
> chomp;
> if ($. = 2) {
^
^
Turn on warnings. It will point out a mistake there.
> ($mem, $total, $used, $free, $shared, $buf, $cache) = split
>/\b[0-9]\b/;
> } elsif ($. = 4) {
^
^
Enable warnings. It will point out a mistake there too.
> ($swap, $stotal, $sused, $sfree) = split
>/\b[0-9]\b/;
> }
> };
>
>The problem is that nothing seems to be being split out.
^^^^^^^
I doubt that that is correct.
Looks to me like you should be getting chunks of spaces. Chunks
of spaces are not "nothing". Empty strings would be "nothing".
>When I simply
>loop through the file, the contents of each line are dumped into $mem and
>the rest are empty. I figure I am:
>
>1) Doing the split wrong
Yes. So type "perldoc -f split" and see what you're doing wrong.
Pay particular attention to what the pattern is supposed to match,
it should match the _delimiter_, not the data of interest.
>2) Doing the if/elsif incorrectly at least
Yes, but only a fool develops with warnings off, don't be foolish.
>3) Doing it the hard way.
split() with both defaults will split on whitespaces.
>At the end of the day, the $mem and $swap variables will be tossed, and
>the values pushed into an Oracle database through DBI (which I haven't
>written yet).
my(undef, $total, $used, $free, $shared, $buf, $cache) = split;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 28 Mar 2001 05:37:47 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Extracting data from a file
Message-Id: <3ac16c59.19137488@news.erols.com>
On Wed, 28 Mar 2001 03:37:43 GMT, adventure <bag_end@clark.net> wrote:
> if ($. = 2) {
^
> } elsif ($. = 4) {
^
Developing/debugging without enabling warnings, eh?
Naughty naughty.
>1) Doing the split wrong
Yup. That's it.
>2) Doing the if/elsif incorrectly at least
Besides the mistake of using '=' when you mean '==', no.
>3) Doing it the hard way.
Besides crippling warnings and stricture, not really.
>split /\b[0-9]\b/;
It looks like you may be confused on what split does.
That would (almost) work if the /pattern/ is what split is supposed to
capture and return, but it really returns what is found in between
occurrences of /pattern/.
You want to split on whitespace.
split /\s+/, $_ ;
Since you're working on the $_ scalar, and splitting on whitespace is
the default action when /pattern/ is not specified, you can omit both
arguments and reduce it to a terse...
split;
------------------------------
Date: Tue, 27 Mar 2001 22:03:57 -0800
From: "Thomas Theakanath" <thomastk@prodigy.net>
Subject: Re: Extracting data from a file
Message-Id: <99ru6j$1bq4$1@newssvr06-en0.news.prodigy.com>
First of all you have to use == instead of = in the if conditions. and try
\s+ for splitting. the resulting code would look something like this-
while (<FREE>) {
chomp;
if ($. == 2) {
($mem, $total, $used, $free, $shared, $buf, $cache) =
split /\s+/;
}
elsif ($. == 4) {
($swap, $stotal, $sused, $sfree) = split /\s+/;
}
};
"adventure" <bag_end@clark.net> wrote in message
news:b0dw6.17579$FS3.217472@sjc-read.news.verio.net...
> Hi there,
>
> I am in over my head on this - I am trying to extract the data on two
> lines (the second and the fourth) from the following (output of the free
> -m command).
>
> total used free shared buffers cached
> Mem: 250 67 182 39 26 20
> -/+ buffers/cache: 20 230
> Swap: 517 0 517
>
> My solution thus far is:
>
> while (<FREE>) {
> chomp;
> if ($. = 2) {
> ($mem, $total, $used, $free, $shared, $buf, $cache) = split
> /\b[0-9]\b/;
> } elsif ($. = 4) {
> ($swap, $stotal, $sused, $sfree) = split
> /\b[0-9]\b/;
> }
> };
>
> The problem is that nothing seems to be being split out. When I simply
> loop through the file, the contents of each line are dumped into $mem and
> the rest are empty. I figure I am:
>
> 1) Doing the split wrong
> 2) Doing the if/elsif incorrectly at least
> 3) Doing it the hard way.
>
> At the end of the day, the $mem and $swap variables will be tossed, and
> the values pushed into an Oracle database through DBI (which I haven't
> written yet).
>
> Thanks for any advice,
>
> DAVID
>
>
> --
> ---------------------------------------------------
> David A. Lane, CNE
> ERP Technical Lead
> ManTech International Corp.
> +1.703.218.8241 VOICE
> +1.703.218.8391 FAX
> PGP ID: 679DF4EE
>
------------------------------
Date: Wed, 28 Mar 2001 11:57:12 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: flock with file dup fails
Message-Id: <99rnbl$f1e@netnews.hinet.net>
Dear all,
The original flock program works:
use Fcntl ':flock';
open F,">>lock" or die $!;
flock F,LOCK_EX|LOCK_NB or die "lock fail\n";
print F sleep 1 for 1..10;
print F "\n";
When one program is running, all the later entrances will get:
lock fail
But if I change it into:
use Fcntl ':flock';
open F,">>lock" or die $!;
flock F,LOCK_EX|LOCK_NB or die "lock fail\n";
open STDOUT,">>&F" or die $!;
print sleep 1 for 1..10;
print "\n";
the locking won't work any more.
What's going on? What can I do?
Thank you.
John Lin
------------------------------
Date: Wed, 28 Mar 2001 08:06:59 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: flock with file dup fails
Message-Id: <3ac19bb3.7516$3c6@news.op.net>
In article <99rnbl$f1e@netnews.hinet.net>,
John Lin <johnlin@chttl.com.tw> wrote:
>But if I change it into:
>
>use Fcntl ':flock';
>open F,">>lock" or die $!;
>flock F,LOCK_EX|LOCK_NB or die "lock fail\n";
>open STDOUT,">>&F" or die $!;
>print sleep 1 for 1..10;
>print "\n";
>
>the locking won't work any more.
It works OK for me. (The second process aborts with 'lock fail' as it
should.) Are you sure? What OS are you using?
If what you think you observed really occurred, then
it might be an OS bug, or it might be a Perl bug.
To tell the difference, write the same program in C.
If the C version shows the same failure, your OS is at fault.
------------------------------
Date: Wed, 28 Mar 2001 08:35:40 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: flock with file dup fails
Message-Id: <3ac1a26c.ce$31f@news.op.net>
In article <3ac19bb3.7516$3c6@news.op.net>,
Mark Jason Dominus <mjd@plover.com> wrote:
>If what you think you observed really occurred, then
>it might be an OS bug, or it might be a Perl bug.
>
>To tell the difference, write the same program in C.
>If the C version shows the same failure, your OS is at fault.
John and I have investigated this, and it does appear to be a bug in
Perl, on the following version/os combinations:
5.005_03/solaris bad (Dominus)
5.6.0 /solaris bad (Lin)
5.6.0 /hpux bad (Lin)
5.6.0 /linux good (Dominus)
5.6.0 /WinNT good (Lin)
I filed a bug report.
Thanks, John!
------------------------------
Date: Wed, 28 Mar 2001 15:58:03 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: flock with file dup fails
Message-Id: <99s5fa$dhs@netnews.hinet.net>
P.S. Environment:
Perl5.6 on 'hpux', 'solaris' will fail to lock.
But Perl5.6 on WinNT is OK!!!
------------------------------
Date: Wed, 28 Mar 2001 16:14:52 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: flock with file dup fails
Message-Id: <99s6en$g5l@netnews.hinet.net>
[Posted and Mailed]
"Mark Jason Dominus" <mjd@plover.com>
> Are you sure? What OS are you using?
Perl5.6 on 'hpux', 'solaris' will fail to lock.
But Perl5.6 on WinNT is OK!!!
What about yours?
Thank you.
John Lin
------------------------------
Date: 28 Mar 2001 10:20:09 +0100
From: nobull@mail.com
Subject: Re: flock with file dup fails
Message-Id: <u9wv9a5jxy.fsf@wcl-l.bham.ac.uk>
"John Lin" <johnlin@chttl.com.tw> writes:
> use Fcntl ':flock';
> open F,">>lock" or die $!;
> flock F,LOCK_EX|LOCK_NB or die "lock fail\n";
> open STDOUT,">>&F" or die $!;
> print sleep 1 for 1..10;
> print "\n";
>
> the locking won't work any more.
>
> What's going on?
This is due to an interaction between the way Perl implements >& and
an utterly moronic mistake in POSIX!
Highlights of the OS calls from the above code are:
open("lock", O_WRONLY|O_APPEND|O_CREAT|O_LARGEFILE, 0666) = 3
flock(3, LOCK_EX|LOCK_NB) = 0
dup(3) = 4
dup2(4, 1) = 1
close(4) = 0
The problem is that POSIX defines that if you dup() a file descriptor
and then closed either one of the resulting descriptors that all locks
on the file are released.
This is moronic. The people who approved this standard should be
taken out an publicly pelted with rotten fruit.
> What can I do?
Lock after you dup().
------------------------------
Date: Wed, 28 Mar 2001 06:14:40 GMT
From: d.lebbing@*no*spam*.iquip.nl
Subject: Re: form post parameter looks like directory but is a script ?!
Message-Id: <3ac1806f.62959899@news.euronet.nl>
Thank you!
I was afraid it would be something like this, I might never have found
it myself.
After I removed it from the form-action url it still worked so it
looks like some legency stuff.
Greetings,
Denniss.
On Wed, 21 Mar 2001 18:17:02 GMT, heiner@DrB.Insel.DE (Heiner Marxen)
wrote:
>In article <3ab89f9c.89011191@news.euronet.nl>,
> <d.lebbing@*no*spam*.iquip.nl> wrote:
>>Folks,
>>
>>The folowing situation is uncomprehenseble to me and I need to know
>>how this works.
>>
>>A script is beeing called from a form like:
>><form action="/secured/edit/article.cgi/3ab8a09e077a0001" method=POST
>>-->
>>This is special because article.cgi is the script and it takes
>>3ab8a09e077a0001 as a parameter! I am puzzled, does anyone have any
>>idea to enlighten me on this one? What is the trick?
>
>This is actually not a perl question, but is about the http demon.
>With Apache the above works this way:
>
>When scanning the URL, the server detects, that the prefix
>"/secured/edit/article.cgi" is an CGI program, which is configured to
>be executable. It does set up this program with (among others)
>two environment variables:
>
>SCRIPT_NAME the above prefix, i.e. "/secured/edit/article.cgi"
>PATH_INFO the rest, i.e. "/3ab8a09e077a0001"
>
>The CGI program then can use the PATH_INFO to decide for some subfunction.
>This is a nice form of parameter passing, an alternative to "?name=value".
>
>Whether this is specific to Apache I don't know.
>--
>Heiner Marxen heiner@drb.insel.de http://www.drb.insel.de/~heiner/
------------------------------
Date: Wed, 28 Mar 2001 07:52:57 +0200
From: Lluís Armengol <llarmengol@iro.es>
Subject: GD library newbie question
Message-Id: <985758908.1287802690@news.uab.es>
Hi folks!
just installed the GD library and some modules and I was trying to make them
work, but I felt into problems when trying to display images.
I basically used the example that one can find in the description of the
library (you can see it attached at the end of the email) ... but when I
run it I only get a bunch of characters, what's wrong with it?. Shouldn't the
script generate an image as output?
Thanks in advance
---
#!/usr/local/bin/perl
use GD;
# create a new image
$im = new GD::Image(100,100);
# allocate some colors
$white = $im->colorAllocate(255,255,255);
$black = $im->colorAllocate(0,0,0);
$red = $im->colorAllocate(255,0,0);
$blue = $im->colorAllocate(0,0,255);
# make the background transparent and interlaced
$im->transparent($white);
$im->interlaced('true');
# Put a black frame around the picture
$im->rectangle(0,0,99,99,$black);
# Draw a blue oval
$im->arc(50,50,95,75,0,360,$blue);
# And fill it with red
$im->fill(50,50,$red);
# make sure we are writing to a binary stream
binmode STDOUT;
# Convert the image to PNG and print it on standard output
print $im->png;
--
________________________________________________________________________
_____
Lluís Armengol Dulcet
Tf. 932.607.775
Fx. 932.607.776
llarmengol@iro.es
------------------------------
Date: Wed, 28 Mar 2001 21:54:43 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: GD library newbie question
Message-Id: <slrn9c3k83.ugg.mgjv@martien.heliotrope.home>
On Wed, 28 Mar 2001 07:52:57 +0200,
Lluís Armengol <llarmengol@iro.es> wrote:
> Hi folks!
>
> just installed the GD library and some modules and I was trying to make them
> work, but I felt into problems when trying to display images.
> I basically used the example that one can find in the description of the
> library (you can see it attached at the end of the email) ... but when I
> run it I only get a bunch of characters, what's wrong with it?. Shouldn't the
It does. Those characters are the image data. Store that in a file, and
use an image viewer to view the result.
Unless you have a shell that can read image data coming though like
that, you will have to use a viewer.
If you have ImageMagick installed, the following should work:
$ perl program.pl | display -
If not, you'll need another image viewer that can read from stdin, or
use an intermediate file, as I suggested earlier.
Martien
--
Martien Verbruggen |
Interactive Media Division | Never hire a poor lawyer. Never buy
Commercial Dynamics Pty. Ltd. | from a rich salesperson.
NSW, Australia |
------------------------------
Date: Wed, 28 Mar 2001 04:55:31 GMT
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Good Perl Code Syntax Highlighting Editor for Linux??
Message-Id: <3AC16F90.8CA22A4E@earthlink.net>
Aaron Cline wrote:
>
> Well, the title says most of what I mean. I need a good Perl syntax
> highlighting editor for Linux (glibc-2.1, i386). I like to use Vim,
> and I have found that supposedly it has syntax highlighting
> capabilities but I can't figure out how to get them to work. If
> anyone has instructions on how to do this, I would be very grateful,
> or if you have a favorite editor, please enlighten me.
>
> Thanks,
>
> Aaron Cline
Nedit has syntax highlighting, but I'm not sure if it has a builtin mode
for perl. Probably, but since I last used nedit in college, on their
unix machines, and am now at home on a Win, I can't recall.
And if it doesn't have a syntax highlighter for perl, you could pretty
easily build one, based on looking at the highlighting syntax for the 20
or so other languages it *does* support.
--
Sometimes the journey *is* its own reward--but not when you're trying to
get to the bathroom in time.
------------------------------
Date: 28 Mar 2001 15:11:22 GMT
From: kodemaniak@gmx.de (Carsten Saathoff)
Subject: Re: Good Perl Code Syntax Highlighting Editor for Linux??
Message-Id: <slrn9c3vlu.c8.kodemaniak@kodemaniak.matrix>
Benjamin Goldberg <goldbb2@earthlink.net> wrote:
[...]
> Nedit has syntax highlighting, but I'm not sure if it has a builtin mode
> for perl. Probably, but since I last used nedit in college, on their
> unix machines, and am now at home on a Win, I can't recall.
>
> And if it doesn't have a syntax highlighter for perl, you could pretty
> easily build one, based on looking at the highlighting syntax for the 20
NEdit has perl syntax highlighting built-in AFAIK. If not, you can find
the perl patterns definately on the nedit homepage www.nedit.org. I use
NEdit all the time for programming and it's a great editor.
--
Carsten Saathoff <kodemaniak@gmx.de>
ICQ #52558095
...powered by Linux
------------------------------
Date: Wed, 28 Mar 2001 08:05:31 +0200
From: Ronald Fischer <ronald.fischer.gp@icn.siemens.de>
Subject: Re: grep(EXPR,LIST) behaves strangely
Message-Id: <3AC17F2B.F6CD96AF@icn.siemens.de>
Bart Lateur wrote:
>
> Ronald Fischer wrote:
>
> >Ooops ... I know it is a string, but I thought grep would eval it for
> >each element in the list. Thank you for pointing this out.
>
> This might seem confusing at first... but the expression is not
> calculated immediately. Instead, a reference to the code consisting of
> this expression is passed to grep. This code is in turn executed once
> for every item in the LIST.
>
> I think the official term is "higher order function".
I see; so this implies that 'grep' could not be written in Perl itself
(at least not if it should assume the same calling convention of the
original grep(EXPR,LIST)), as there is no need to indicate that a
user-defined sub expects an *expression* as a parameter? Of course this
is an academic question, as you can always achieve the same effect by
passing a reference to an anonymous sub (though this looks syntactically
different at the call site).
Ronald
--
Ronald Otto Valentin Fischer <rovf@earthling.net>
[now at: Siemens ICM N MR UR DE 6, phone: +49(Germany)+89-722-23368]
http://profiles.yahoo.com/ronny_fischer/
http://fusshuhn.ourfamily.com/cppincomp.html
------------------------------
Date: Wed, 28 Mar 2001 07:47:20 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: grep(EXPR,LIST) behaves strangely
Message-Id: <ad53ct4lj1fk4chqjn8o1oku5i6mdedngv@4ax.com>
Ronald Fischer wrote:
>I see; so this implies that 'grep' could not be written in Perl itself
>(at least not if it should assume the same calling convention of the
>original grep(EXPR,LIST)), as there is no need to indicate that a
>user-defined sub expects an *expression* as a parameter?
Indeed. The other syntax, with a code block, IS feasable in Perl, thanks
to function prototypes (but only for the first parameter). Once Perl
expects a code ref as a first parameter, it expects to see a bare block
and no comma for the first parameter, instead of a sub BLOCK plus comma
it would normally accept.
sub mymap (&@) {
my $sub = shift;
my @result;
push @result, $sub->($_) foreach @_;
return @result;
}
$, = ':'; $\ = "\n";
print mymap { "$_.$_" } 1 .. 5; # with prototype
print &mymap(sub { "$_.$_" }, 'a' .. 'e'); # ignore prototype
-->
1.1:2.2:3.3:4.4:5.5
a.a:b.b:c.c:d.d:e.e
--
Bart.
------------------------------
Date: Wed, 28 Mar 2001 09:41:33 -0500
From: Jim T Schumacher <jimts@prodigy.net>
Subject: Help, looking for a learning perl video
Message-Id: <3AC1F81D.2A1A7FD1@prodigy.net>
I'm looking for a basic get your feet wet introductory perl VHS video
for a class of students to watch before we begin learning perl. I've
had no luck at various online web stores (amazon.com, etc..). If
anyone knows of one or where to obtain one, please respond.
We watched a different video a few weeks ago on basic linux BASH
commands before sitting
at our terminals working with the commands and it seemed to work well. I
would like to try the same
again with perl. Any help would be greatly appreciated.
Thank you,
Jim Schumacher
------------------------------
Date: Wed, 28 Mar 2001 12:02:59 +0200
From: ALEXANDRU <BOBOC@eltcv.epfl.ch>
Subject: how to access HTML pages with username and password
Message-Id: <3AC1D2F3.67FB4A0E@eltcv.epfl.ch>
-- Hy everbody
I have some acces to scientifical revue with USERNAME and password.
Becauseare many article i want to fetshc only the articles for my
interest with a Perl program.
I want to know hao to make a program in perl to make a request typo:
$content= HTTP request ($url,$username,$password)
thanks
Alex
------------------------------
Date: Wed, 28 Mar 2001 12:55:27 +0800
From: <jackkon@pchome.com.tw>
Subject: How to use Net::Telnet?
Message-Id: <99rr48$m2m@netnews.hinet.net>
hi......all
I practice to use Net::Telnet. In the perl document, I find a example. It
looks like the code below. I
don't understand how to use it. I have a accout in a remote linux server.
When I login the linux, my prompt looks like "[myname]" and my shell is
/bin/bash. How can I chage the code below to use in my own program.
Thanks a lot ^^
## Make sure prompt won't match anything in send data.
$prompt = '_funkyPrompt_';
$host->prompt("/$prompt\$/");
$host->cmd("set prompt = '$prompt'");
------------------------------
Date: Tue, 27 Mar 2001 23:00:26 -0500
From: "David J. Marcus" <djmarcus@ex-pressnet.com>
Subject: Re: HTTP Headers
Message-Id: <tc2oeppnqj95fb@corp.supernews.com>
"S Warhurst" <s.warhurst@rl.ac.uk> wrote in message
news:99pt18$itk@newton.cc.rl.ac.uk...
> Hi
>
> Can anyone tell me how to retrieve all the http header information passed
> from the client to server, and break it down into pairs? I have been
> searching for a while but can't find any routines to do it.
>
> Thanks
> Spencer
>
>
I recommend you read Chapter 9 of the Network Programming With Perl book by
Lincoln Stein (ISBN: 0-201-61571-1).
The example on page 256 allows you to get all the responses for a single
message (there may be multiple if redirection took place).
You can then extract the headers from the $response->request objects using
the $request->scan(\&sub) method (see bottom of page 251).
You to see all the gory details of the headers, even the fields added by the
agent.
-Enjoy
David
------------------------------
Date: 28 Mar 2001 17:02:29 GMT
From: sendthis@yahoo.delthisandasdf.com (e)
Subject: Is there an easier way of doing this? (Multiple file handling)
Message-Id: <A25500B57F006CF1.7F004100B17514B4.B33AB9146EE2987E@lp.airnews.net>
I have a working solution but I'm curious if there is an easier way.
I have two files with the same number of elements. Two different fields from
the same database.
I have two sets of data that I want to manipulate.
Right now, I combine them into one file using "paste -d" " file1 file2 >
work_with_me;" in unix.
What I want to know, is can I open them separately in perl and do the same
thing. I've attached what I'm doing below.
This isn't actually what I'm doing, just the part essential in understanding my
question.
Thanks,
E
#!/bin/perl
open (FILE,"test/work_with_me");
@array = <FILE>;
close (FILE);
foreach $line (@array )
{
@work = split (/\t/,$line); # Splits the variable into an array by <tab>
@date = split (/\//,$work[0]); # Splits the variable into an array of three
# delimited by '/'
$release = $work[1];
$release =~ s/ +$//g; # Remove all trailing spaces
$date_mo = $date[0];
$date_da = $date[1];
$date_yr = $date[2];
print $release;
print $date_mo;
print $date_da;
print $date_yr;
}
------------------------------
Date: Wed, 28 Mar 2001 02:53:14 GMT
From: Gisle Aas <gisle@ActiveState.com>
Subject: Re: LWP help
Message-Id: <m37l1a61re.fsf@ActiveState.com>
"Eric" <mail@ericmarques.net> writes:
> Thanks
> the thing with the limiting bytes is because im using a kind of proxy server
> for html files only and i dont want ppl trying to get large files and
> slowing down the server
Try to use something like:
$ua->max_size(1024);
--
Gisle Aas
------------------------------
Date: Tue, 27 Mar 2001 22:51:52 -0600
From: brian d foy <comdog@panix.com>
Subject: Re: More Help please :-)
Message-Id: <comdog-C0D54E.22515227032001@news.panix.com>
In article <n1d2ctc273v3mhslvue2dtm2fe0o8k5ael@4ax.com>, Bart Lateur
<bart.lateur@skynet.be> wrote:
> p.s. You chose keep the first occurence of an item. What if one wants to
> keep the last occurence instead?
or the middle one even ;)
--
brian d foy <comdog@panix.com>
------------------------------
Date: Wed, 28 Mar 2001 05:37:44 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: More Help please :-)
Message-Id: <x766guzc5y.fsf@home.sysarch.com>
>>>>> "BL" == Bart Lateur <bart.lateur@skynet.be> writes:
BL> my %hash = map { $_, 1 } @array;
BL> my @unique = sort keys %hash;
BL> That's more like it.
BL> p.s. You chose keep the first occurence of an item. What if one wants to
BL> keep the last occurence instead?
first, that keeps the last occurrance as later entries will override the
earlier assignments. secondly, how can you tell since it only saves the
keys?
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: 28 Mar 2001 06:11:40 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: More Help please :-)
Message-Id: <slrn9c303l.k85.damian@puma.qimr.edu.au>
Uri Guttman chose Wed, 28 Mar 2001 05:37:44 GMT to say this:
>>>>>> "BL" == Bart Lateur <bart.lateur@skynet.be> writes:
>
> BL> p.s. You chose keep the first occurence of an item. What if one wants to
> BL> keep the last occurence instead?
>
>first, that keeps the last occurrance as later entries will override the
>earlier assignments. secondly, how can you tell since it only saves the
>keys?
>
This is what I first thought, and began a followup about how to tell the
difference between 'foo' and 'foo' that happen to have come from $array[1]
and $array[42] respectively, but realised BL was referring to the *order*
in which those occurences ... uh ... occur. So for @array = qw( a b a d ),
do we want to keep (a b d) or (b a d)?
I would suggest that this is meaningless if the list is already sorted :-).
I had really only suggested the order-preserving version for completeness.
Cheers,
Damian
--
@;=0..23;@;{@;}=split//,<DATA>;while(@;){for($;=@;;--$;;){next if($:=rand($;
+1))==0+$;;@;[$;,$:]=@;[$:,$;]}print map{$;{$_}}(@| ,@;);push@|,shift@;if$;[
0]==@|;$|=1;select$&,$&,$&,1/80;print"\b"x(@;+@|)}print"\n"__END__
Just another Perl Hacker
------------------------------
Date: Wed, 28 Mar 2001 19:06:06 +0200
From: h.m.brand@hccnet.nl (H. Merijn Brand)
To: comp.lang.perl.misc
Subject: Re: Most efficient way to extract unique array elements?
Message-Id: <Xns9072C250828D4Merijn@192.0.1.90>
abigail@foad.org (Abigail) wrote in
<slrn9b43ed.863.abigail@tsathoggua.rlyeh.net>:
>Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMDCCLIV
>September MCMXCIII in <URL:news:98st2f$pn5$1@mamenchi.zrz.TU-Berlin.DE>:
>.. According to John Bokma <john@castleamber.co.nz>:
>..
>.. [...]
>..
>.. > Use a hash. A long example:
>.. >
>.. > my %hash;
>.. > foreach my $item (@array1)
>.. > {
>.. > $hash{$item} = 1;
>.. > }
>.. >
>.. > keys %hash now contain the unique elements
>.. >
>.. > shorter way:
>.. >
>.. > my %hash;
>.. > @hash{@array1} = (1) x @array1;
>..
>.. Still shorter:
>..
>.. @hash{ @array1} = ();
>
>
>And as one line:
>
> my %hash = map {$_ => 1} @array1;
extending that to not using a named hash:
my @keys = sort keys %{ { map { $_ => 1 } @array1 } };
sort is optional
--
H.Merijn Brand Amsterdam Perl Mongers
(http://www.amsterdam.pm.org/)
using perl-5.005.03, 5.6.0, 5.6.1, 5.7.1 & 623 on HP-UX 10.20 & 11.00, AIX
4.2
AIX 4.3, WinNT 4, Win2K pro & WinCE 2.11 often with Tk800.022 &/| DBD-
Unify
ftp://ftp.funet.fi/pub/languages/perl/CPAN/authors/id/H/HM/HMBRAND/
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 579
**************************************