[25547] in Perl-Users-Digest
Perl-Users Digest, Issue: 7791 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 16 18:10:40 2005
Date: Wed, 16 Feb 2005 15:10:30 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 16 Feb 2005 Volume: 10 Number: 7791
Today's topics:
Help Programming in Perl for File Renaming crazycelicagts@gmail.com
Re: Help Programming in Perl for File Renaming <lynn.watts@ugs.com>
LWP HTTP request corrupted file (Ang Talunin)
Re: LWP HTTP request corrupted file <nospam@bigpond.com>
Re: LWP HTTP request corrupted file <postmaster@castleamber.com>
Re: Problem with IO::Socket [... on Mac OS X] <news@chaos-net.de>
Re: Problem with IO::Socket <news@chaos-net.de>
Re: Problem with IO::Socket <1usa@llenroc.ude.invalid>
Re: Problem with IO::Socket <news@chaos-net.de>
Re: Problem with IO::Socket xhoster@gmail.com
Re: The Problem with Perl <tzz@lifelogs.com>
Re: The Problem with Perl <jussij@zeusedit.com>
Re: The Problem with Perl <jussij@zeusedit.com>
Re: The Problem with Perl <jussij@zeusedit.com>
Using Perl to Parse Excel File <mull0024@juno.com>
Re: Using Perl to Parse Excel File <anomousty@webwonders.org>
Re: Using Perl to Parse Excel File <matternc@comcast.net>
Re: Using Perl to Parse Excel File xhoster@gmail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 16 Feb 2005 11:32:05 -0800
From: crazycelicagts@gmail.com
Subject: Help Programming in Perl for File Renaming
Message-Id: <1108582325.067355.145570@z14g2000cwz.googlegroups.com>
Hello everyone. I was wondering if someone can help me write a perl
program that does the following. I have a folder which contains a bunch
of files such as:
[folder]
a,b,c,d,e,f,g,.....
within those files is a line that has a statement, "File name:
TestA"...how do I write a program that goes in each of the files and
extract the "TestA" and rename the file "a" to "TestA" file. So in the
end, it will look like this:
[folder]
TestA, TestB, TestC, TestD, TestE, ....
If anyone can help me out, I would greatly appreciate it. Thanks.
------------------------------
Date: Wed, 16 Feb 2005 13:20:24 -0800
From: "Lynn" <lynn.watts@ugs.com>
Subject: Re: Help Programming in Perl for File Renaming
Message-Id: <4213b86d$1@usenet.ugs.com>
Hello,
<crazycelicagts@gmail.com> wrote in message
news:1108582325.067355.145570@z14g2000cwz.googlegroups.com...
> Hello everyone. I was wondering if someone can help me write a perl
> program that does the following. I have a folder which contains a bunch
> of files such as:
Well the first thing I would do is get a list file files that are located
within the directory in question. See http://tinyurl.com/4k4ej
Then I would slurp the file into an array or varable See:
http://tinyurl.com/5c354
find and extract what you want
http://tinyurl.com/6bxa2
and then rename the files in question
http://tinyurl.com/5225f
> If anyone can help me out, I would greatly appreciate it. Thanks.
That should get you started, If you run into any problems just
post the code that you have written and someone here will gladly
help you fix it.
Hope this helps
Lynn
------------------------------
Date: 16 Feb 2005 13:05:37 -0800
From: wslob@hotmail.com (Ang Talunin)
Subject: LWP HTTP request corrupted file
Message-Id: <7cdea63a.0502161305.268c1258@posting.google.com>
Hey,
I'm trying to create a perl script to download a zip file from a
website.
This is my code to download the file:
my $ua = new LWP::UserAgent;
my $reg = new HTTP::Request 'GET',"http://www.site.com/file.zip";
my $result = $ua->request($reg);
$html = $result->content if $result->is_success;
open OUT, ">file.zip" || die "Cannot write to outputfile";
print OUT $html;
close OUT;
But the stored zipfile is corrupted....
So I think that there's something wrong with the way I pass the file
from the HTTP request to the file, but can't find the right
solution....
Does anybody knows how to do this without corrupting the file? Thanx!
A.T.
------------------------------
Date: Thu, 17 Feb 2005 07:22:38 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: LWP HTTP request corrupted file
Message-Id: <37hrsvF5degdnU1@individual.net>
Ang Talunin wrote:
> Hey,
>
> I'm trying to create a perl script to download a zip file from a
> website.
> This is my code to download the file:
>
> my $ua = new LWP::UserAgent;
> my $reg = new HTTP::Request 'GET',"http://www.site.com/file.zip";
> my $result = $ua->request($reg);
> $html = $result->content if $result->is_success;
> open OUT, ">file.zip" || die "Cannot write to outputfile";
Maybe you need:
binmode(OUT)
> print OUT $html;
> close OUT;
>
gtoomey
------------------------------
Date: 16 Feb 2005 21:24:50 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: LWP HTTP request corrupted file
Message-Id: <Xns95FF9CCB7B461castleamber@130.133.1.4>
Ang Talunin wrote:
> Hey,
>
> I'm trying to create a perl script to download a zip file from a
> website.
> This is my code to download the file:
>
> my $ua = new LWP::UserAgent;
$ua->get( $url , ':content_file' => 'file.zip' );
> my $reg = new HTTP::Request 'GET',"http://www.site.com/file.zip";
Don't use site.com in an example, but example.com
> Does anybody knows how to do this without corrupting the file? Thanx!
HTH,
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Wed, 16 Feb 2005 23:32:53 +0100
From: Martin Kissner <news@chaos-net.de>
Subject: Re: Problem with IO::Socket [... on Mac OS X]
Message-Id: <slrnd17igl.1rr.news@maki.homeunix.net>
A. Sinan Unur wrote :
> Martin Kissner <news@chaos-net.de> wrote in
> news:slrnd178eu.1hq.news@maki.homeunix.net:
>> Sorry, but I still do not understand this; therefor I am still
>> interested if it works for anyone else.
>> If I have overseen something, please point me to it.
>
> You will need to give some more information regarding the system on which
> you are testing this in a clear and concise way.
Of course.
I should have done in the first place.
% uname -msr
Darwin 7.8.0 Power Macintosh
# which is Mac OS X
% perl -v
This is perl, v5.8.1-RC3 built for darwin-thread-multi-2level
(with 1 registered patch, see perl -V for more detail)
> Now, you can check if perl is able to do the mapping from service names
> to port addresses on your system by running this script (from Perl docs):
Thank you for the script.
% ./test_services.pl smtp
port for smtp is 25, aliases are
% ./test_services.pl http
port for http is 80, aliases are www www-http
works optimally and makes it still more surprising that the script doesn't
--
perl -e 'print 7.74.117.115.116.11.32.13.97.110.111.116.104.101.114.11
.32.13.112.101.114.108.11.32.13.104.97.99.107.101.114.10.7'
------------------------------
Date: Wed, 16 Feb 2005 20:41:18 +0100
From: Martin Kissner <news@chaos-net.de>
Subject: Re: Problem with IO::Socket
Message-Id: <slrnd178eu.1hq.news@maki.homeunix.net>
phaylon wrote :
> Martin Kissner wrote:
>
>> I would rather be interested if anyone out there could run the script
>> successfully without any changes and with servicenames instead of
>> portnumbers as it is suggested in the book.
>
> A better way is to use the docs. For IO::Socket::INET it is documented,
> that
This will not give me any information on the above question.
btw: I did read the docs for IO::Socket::INET.
>
>| If the constructor is only passed a single argument, it is assumed to be
>| a PeerAddr specification.
>
> A few lines up, we see
>
>| The PeerAddr can be a hostname or the IP-address on the "xx.xx.xx.xx"
>| form. The PeerPort can be a number or a symbolic service name. The
>| service name might be followed by a number in parenthesis which is used
>| if the service is not known by the system. The PeerPort specification
>| can also be embedded in the PeerAddr by preceding it with a ":".
| "The PeerPort can be a number or a service name."
I have used a service name. No contradiction to the docs so far.
And as sugessted in the last sentence I have embedded the service name
in the PeerAddr by preceding it with a ":".
The service is known by the system.
Farther, while finding the solution to my question in the first place, I
did some testing with unexpected results, which I did not want to
mention in my first post to keep it scarce and tidy.
The following script did not run either unless I didn't use use the
line, which is commented out below for creating the socket object.
The syntax for the constructor is taken from the docs.
The number in parantheses seems to be not used and the service name
seems to not work although known by the system.
-----
#!/usr/bin/perl
use IO::Socket;
my $fh = IO::Socket::INET->new(PeerAddr => 'localhost:smtp(25)');
# my $fh = IO::Socket::INET->new(PeerAddr => 'localhost:25');
my $line = <$fh>;
print $line;
-----
Also
my $fh = IO::Socket::INET->new(PeerAddr => 'localhost',
PeerPort => 'PeerPort(25)');
did not work as construcor whereas
my $fh = IO::Socket::INET->new(PeerAddr => 'localhost',
PeerPort => '25');
did.
Sorry, but I still do not understand this; therefor I am still
interested if it works for anyone else.
If I have overseen something, please point me to it.
Regards
Martin
--
perl -e 'print 7.74.117.115.116.11.32.13.97.110.111.116.104.101.114.11
.32.13.112.101.114.108.11.32.13.104.97.99.107.101.114.10.7'
------------------------------
Date: 16 Feb 2005 21:53:08 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Problem with IO::Socket
Message-Id: <Xns95FFABC47E46asu1cornelledu@132.236.56.8>
Martin Kissner <news@chaos-net.de> wrote in
news:slrnd178eu.1hq.news@maki.homeunix.net:
> Sorry, but I still do not understand this; therefor I am still
> interested if it works for anyone else.
> If I have overseen something, please point me to it.
I am not sure. Here is some info:
Microsoft Windows 2000 [Version 5.00.2195]
This is perl, v5.8.6 built for MSWin32-x86-multi-thread
C:\> perl -MIO::Socket::INET -e "print $IO::Socket::INET::VERSION"
1.27
I tried your script against a variety of hosts using the service name
'smtp'. The script worked as expected.
You will need to give some more information regarding the system on which
you are testing this in a clear and concise way.
Now, you can check if perl is able to do the mapping from service names
to port addresses on your system by running this script (from Perl docs):
#! /usr/bin/perl
use strict;
use warnings;
use Net::servent;
my $s = getservbyname(shift) || die "no service";
printf "port for %s is %s, aliases are %s\n",
$s->name, $s->port, "@{$s->aliases}";
__END__
On the system I mentioned above, this gives me:
C:\> perl s.pl smtp
port for smtp is 25, aliases are mail
C:\> perl s.pl chargen
port for chargen is 19, aliases are ttytst source
Exploring from here is an option.
Sinan
------------------------------
Date: Wed, 16 Feb 2005 23:07:05 +0100
From: Martin Kissner <news@chaos-net.de>
Subject: Re: Problem with IO::Socket
Message-Id: <slrnd17h09.1rr.news@maki.homeunix.net>
xhoster@gmail.com wrote :
> Martin Kissner <news@chaos-net.de> wrote:
>> my $fh = IO::Socket::INET->new($server);
>
> One should probably check for success:
Yes, that's probably true.
> my $fh = IO::Socket::INET->new($server) or die $@;
>> % ./lgetr.pl wuarchive.wustl.edu:daytime
>> is supposed to output the current date of that server.
>
> It gives me a connection refused message.
The book is from 2002; the service is discontinued, I guess.
But it proves, that the script tried to connect.
>> % ./lgetr.pl wuarchive.wustl.edu:ftp
>> should print the welcome message of the ftp service on
>> wuarchive.wustl.edu
>
> For me, it does do that.
Thank you for that information.
What is your OS? Mine is Darwin 7.8 (Mac OS X)
Which Version of Perl are you using. I am using Perl 5.8.1
>> % ./lgetr.pl mail.hotmail.com:smtp
>> should print the welcome message of the smtp-server on mail.motmail.com
>
> the smtp-server on mail.hotmail.com doesn't seem to have a welcome
> message.
With telnet I get
| 220 mc9-f7.hotmail.com Sending unsolicited commercial or bulk e-mail to
| Microsoft's computer network is prohibited. Other restrictions are found
| at http://privacy.msn.com/Anti-spam/. Violations will result in use of
| equipment located in California and other states. Wed, 16 Feb 2005
| 13:48:09 -0800
I do still not know how to find out why it doesn't work on my system.
Any suggestions are welcome.
Regards
Martin
--
perl -e 'print 7.74.117.115.116.11.32.13.97.110.111.116.104.101.114.11
.32.13.112.101.114.108.11.32.13.104.97.99.107.101.114.10.7'
------------------------------
Date: 16 Feb 2005 21:04:05 GMT
From: xhoster@gmail.com
Subject: Re: Problem with IO::Socket
Message-Id: <20050216160405.287$G0@newsreader.com>
Martin Kissner <news@chaos-net.de> wrote:
> Hello group,
>
> I am trying to use a script from the book "Networkprogramming with Perl"
> by Lincoln D. Stein.
>
> ----
> #!/usr/bin/perl
>
> use warnings;
> use strict;
>
> use IO::Socket;
>
> my $server = shift;
> my $fh = IO::Socket::INET->new($server);
One should probably check for success:
my $fh = IO::Socket::INET->new($server) or die $@;
> my $line = <$fh>;
> print $line;
> ----
>
> It is supposed to read the first line from a remote server's welcome
> message.
>
> % ./lgetr.pl wuarchive.wustl.edu:daytime
> is supposed to output the current date of that server.
It gives me a connection refused message.
>
> % ./lgetr.pl wuarchive.wustl.edu:ftp
> should print the welcome message of the ftp service on
> wuarchive.wustl.edu
For me, it does do that.
> % ./lgetr.pl mail.hotmail.com:smtp
> should print the welcome message of the smtp-server on mail.motmail.com
the smtp-server on mail.hotmail.com doesn't seem to have a welcome
message.
> and so on.
> In my case the script hangs infinitely without any output.
The only one that hangs for me is hotmail, and given the behavior of that
server, this is not unexpected.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Wed, 16 Feb 2005 14:42:00 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: The Problem with Perl
Message-Id: <4nacq4fg1j.fsf@lifelogs.com>
On 16 Feb 2005, rhugga@yahoo.com wrote:
> I believe you are suffering from learning an interpreted language
> before learning a true language like C or C++.
I believe you are suffering from learning a compiled language before
learning a true language like assembler.
Ted
------------------------------
Date: Thu, 17 Feb 2005 09:20:18 +1100
From: Jussi Jumppanen <jussij@zeusedit.com>
Subject: Re: The Problem with Perl
Message-Id: <4213C722.5F3D@zeusedit.com>
Arndt Jonasson wrote:
> It may be C++, but it's not C.
This is a bit harsh.
It is true that the C compiler might not produce any errors for
the code but it only compilers the code under duress.
As any good C programmer will tell you it is very dangerous to
ignore or cast away warnings, as they are a good indication
that something is very wrong with the code.
IMHO the original poster is correct.
The C++ compiler gets it right and refuses to compile the code
because they are different, while the C compiler the compiles
the code "saying I hope you know what you are doing, because I
certainly don't, but here it is compile code anyway".
Jussi Jumppanen
Author of: Zeus for Windows (New version 3.94 out now)
"The C/C++, Cobol, Java, HTML, Python, PHP, Perl programmer's editor"
Home Page: http://www.zeusedit.com
------------------------------
Date: Thu, 17 Feb 2005 09:20:03 +1100
From: Jussi Jumppanen <jussij@zeusedit.com>
Subject: Re: The Problem with Perl
Message-Id: <4213C713.404B@zeusedit.com>
Arndt Jonasson wrote:
> It may be [true] C++, but it's not [true] C.
This is a bit harsh. It is true that the C compiler might
well compile the code, but it does so only under duress.
As any good C programmer knowns it is dangerous to ignore
or cast away warnings, as they are a strong indication that
something is not quite right with the code.
IMHO the original poster is correct.
The C++ compiler gets it right and refuses to compile the code
because they are functions are different, while the C compiler
the compiles the code "saying I hope you know what you are doing,
because I certainly don't, but here is your compile code anyway".
Jussi Jumppanen
Author of: Zeus for Windows (New version 3.94 out now)
"The C/C++, Cobol, Java, HTML, Python, PHP, Perl programmer's editor"
Home Page: http://www.zeusedit.com
------------------------------
Date: Thu, 17 Feb 2005 09:04:30 +1100
From: Jussi Jumppanen <jussij@zeusedit.com>
Subject: Re: The Problem with Perl
Message-Id: <4213C36E.1307@zeusedit.com>
Charlton Wilbur wrote:
> The question here is not whether you'd choose a small team of
> good programmers or a large team of mediocre ones.
IHMO this question is well answered by book "The Mythical Man Month".
If I remember correctly, it basically says it is not possible to
just throw bodies at task in the hope of get the work done more
quickly. The common misconception is that as you add bodies a
project, the work load can be shared, thus the task gets done
faster.
The book shows that adding an extra body always comes at some
cost. The cost refers to things like management, planning,
co-ordination communication etc etc.
Thus there comes a point where this extra cost outweighs the
gain or the extra body. Once this point is reached adding
extra bodies actually hinders the project.
Jussi Jumppanen
Author of: Zeus for Windows (New version 3.94 out now)
"The C/C++, Cobol, Java, HTML, Python, PHP, Perl programmer's editor"
Home Page: http://www.zeusedit.com
------------------------------
Date: 16 Feb 2005 11:33:30 -0800
From: "mull0024@juno.com" <mull0024@juno.com>
Subject: Using Perl to Parse Excel File
Message-Id: <1108582410.892014.226930@c13g2000cwb.googlegroups.com>
I'm using Perl to parse through an Excel file and I'm having trouble
with a date field. The date displays as 1-Jan-63 (for example) but
when the script runs it is printing as
"Win32::OLE::Variant=SCALAR(0x2626704)" If I print it using two $
signs then Perl prints it as "39047808"
So I guess I have two questions:
1) How does the extra $ sign change anything?
2) How do I get the data from Excel to print in Perl as dd/mm/yy ?
Thanks in advance for your thelp,
Chris
------------------------------
Date: Wed, 16 Feb 2005 14:03:39 -0600
From: m <anomousty@webwonders.org>
Subject: Re: Using Perl to Parse Excel File
Message-Id: <cv08v4$3fl$1@nntp.msstate.edu>
mull0024@juno.com wrote:
> I'm using Perl to parse through an Excel file and I'm having trouble
> with a date field. The date displays as 1-Jan-63 (for example) but
> when the script runs it is printing as
> "Win32::OLE::Variant=SCALAR(0x2626704)" If I print it using two $
> signs then Perl prints it as "39047808"
>
> So I guess I have two questions:
>
> 1) How does the extra $ sign change anything?
>
the extra $ is used to dereference an address. i have jst begun to learn
perl and this is what i have understood. its like go to address and pick
up the value there. so i think $($) would go to the address 0x2626704
and pick up whatever is there.
could it b like this?
------------------------------
Date: Wed, 16 Feb 2005 15:51:14 -0500
From: Chris Mattern <matternc@comcast.net>
Subject: Re: Using Perl to Parse Excel File
Message-Id: <GZidnbnLI_bZL47fRVn-tA@comcast.com>
mull0024@juno.com wrote:
> I'm using Perl to parse through an Excel file and I'm having trouble
> with a date field. The date displays as 1-Jan-63 (for example) but
> when the script runs it is printing as
> "Win32::OLE::Variant=SCALAR(0x2626704)" If I print it using two $
> signs then Perl prints it as "39047808"
>
> So I guess I have two questions:
>
> 1) How does the extra $ sign change anything?
It dereferences. If $date is a reference to the scalar (which is
what you have; the SCALAR(address) is what you get when you ask
Perl to print a reference), then $$date is the scalar it references.
>
> 2) How do I get the data from Excel to print in Perl as dd/mm/yy ?
perldoc Date::Format
>
> Thanks in advance for your thelp,
> Chris
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
------------------------------
Date: 16 Feb 2005 23:03:35 GMT
From: xhoster@gmail.com
Subject: Re: Using Perl to Parse Excel File
Message-Id: <20050216180335.126$5L@newsreader.com>
"mull0024@juno.com" <mull0024@juno.com> wrote:
> I'm using Perl to parse through an Excel file and I'm having trouble
> with a date field. The date displays as 1-Jan-63 (for example) but
> when the script runs it is printing as
> "Win32::OLE::Variant=SCALAR(0x2626704)"
That means that what you have is an object of the class
Win32::OLE::Variant. (and that class appears to use a scalar
as its storage mechanism.)
> If I print it using two $
> signs then Perl prints it as "39047808"
>
> So I guess I have two questions:
>
> 1) How does the extra $ sign change anything?
It dereferences the object directly, bypassing any accessor methods
defined by the class (unless the class overrides scalar dereferncing).
> 2) How do I get the data from Excel to print in Perl as dd/mm/yy ?
I don't know. Did you try the docs for Win32::OLE::Variant?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
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 7791
***************************************