[25648] in Perl-Users-Digest
Perl-Users Digest, Issue: 7890 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 17 06:05:42 2005
Date: Thu, 17 Mar 2005 03:05:09 -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 Thu, 17 Mar 2005 Volume: 10 Number: 7890
Today's topics:
Re: Extract data using Curl Unix Command & Perl Script <tadmc@augustmail.com>
Re: Extract data using Curl Unix Command & Perl Script <ifiaz@hotmail.com>
Re: Hashes, flattening, evaluation <nospam@bigpond.com>
How to use Perl Graph module to solve travel salesperso (Meng)
Re: How to use Perl Graph module to solve travel salesp <postmaster@castleamber.com>
Re: How to use Perl Graph module to solve travel salesp m.fangtao@genesis.co.nz
Re: How to use Perl Graph module to solve travel salesp <postmaster@castleamber.com>
Re: Maximum string length in perl <pilkowsk@informatik.uni-marburg.de>
Re: Maximum string length in perl <appumail@gmail.com>
Re: Maximum string length in perl <someone@example.com>
Re: Maximum string length in perl <appumail@gmail.com>
Re: Maximum string length in perl <pilkowsk@informatik.uni-marburg.de>
Re: Maximum string length in perl <pilkowsk@informatik.uni-marburg.de>
Re: Maximum string length in perl <tadmc@augustmail.com>
Re: perl bug with pos() and placing matches in an array <pilkowsk@informatik.uni-marburg.de>
Perl equiv to PHP print_r <nospam.aweraw@gmail.com>
Re: Perl equiv to PHP print_r <smoNOSPAM@smo.onthenet.com.au>
Re: perlcc error <elmakko@gmail.com>
Re: PerlScript (WSH) - Cannot set property <smugs_boy@yahoo.com>
Re: Regex - every character but " <see.sig@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 17 Mar 2005 00:08:55 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Extract data using Curl Unix Command & Perl Script from Webpage
Message-Id: <slrnd3i7nn.1kn.tadmc@magna.augustmail.com>
ifiaz <ifiaz@hotmail.com> wrote:
[ Please provide a proper attribution when you quote someone. ]
>> It gets all 318 of them when I try it.
>>
>> > Could you or someone explain why?
>>
>> Nope, since I cannot duplicate the problem.
> Did you make any code changes on your script?
Yes, the ones you described.
> Is it to do anything with network overloading, etc. etc.?
Could be that, we can't see your network, so we cannot help with that.
It could be that the website is throttling you too.
Or it might be something else, since there may be tiny differences
in the code we are running since there have been a few edits
on each end since then...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 17 Mar 2005 01:19:06 -0800
From: "ifiaz" <ifiaz@hotmail.com>
Subject: Re: Extract data using Curl Unix Command & Perl Script from Webpage
Message-Id: <1111051146.908866.163430@l41g2000cwc.googlegroups.com>
> >> It gets all 318 of them when I try it.
> >>
> >> > Could you or someone explain why?
> >>
> >> Nope, since I cannot duplicate the problem.
>
>
> > Did you make any code changes on your script?
>
>
> Yes, the ones you described.
>
>
> > Is it to do anything with network overloading, etc. etc.?
>
>
> Could be that, we can't see your network, so we cannot help with
that.
>
> It could be that the website is throttling you too.
>
> Or it might be something else, since there may be tiny differences
> in the code we are running since there have been a few edits
> on each end since then...
This simple code for the URL content downloads 150 times of the same
thing without any breaks.
CODE FOLLOWS:
#!/usr/bin/perl
use strict;
use warnings;
use LWP::Simple;
my $regno;
for ($regno=1; $regno<=150; $regno=$regno+1) {
my $content =
get("http://www.chennaionline.com/msuniversity/submit1.asp?code=B
A1TO4");
die "Couldn't get it!" unless defined $content;
print "$content\n";
}
CODE ENDS:
But, only with the earlier results extraction code it breaks after the
90th student.
I don't think any of the server is trying to cut you off due to network
overload.
May be it is to do with how the extraction code is written.
Please bear with me and show me how I can accomplish what I wanted
earlier.
------------------------------
Date: Thu, 17 Mar 2005 12:08:05 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: Hashes, flattening, evaluation
Message-Id: <39s745F62nh43U1@individual.net>
A. Sinan Unur wrote:
> Gregory Toomey <nospam@bigpond.com> wrote in
> news:39r4mbF5vb5tqU1@individual.net:
>
>> Theres a section in the cookbook on using closures as objects
>> http://www.india-seo.com/perl/cookbook/ch11_08.htm
>
> You know that is an illegal copy, right? Have you informed O'Reilley about
> the site?
>
> Sinan
I just found it with google. I didnt know it was illegal.
gtoomey
------------------------------
Date: 16 Mar 2005 19:29:08 -0800
From: m.fangtao@genesis.co.nz (Meng)
Subject: How to use Perl Graph module to solve travel salesperson problem (TSP)?
Message-Id: <1ddc56b5.0503161929.35dadfdd@posting.google.com>
Hi All,
I'm designing a project to solve TSP issue with Perl. I found Graph
module is quite helpful but it's not good enough. I want to create a
undirected graph,each node can connect each other with different
weights in the graph. I can set up the start ('a') and end ('e')
points,the routine should start from 'a' and pass every node,finish at
'e'. The script can find the shortest routine at last, for example
a->c->b->d->e. I can use APSP_Floyd_Warshall and
$SP->path_vertices('a','e') functions. But it will only return the
shortest way between 2 points, such as a->e,it doesn't pass and count
every node. Does anybody can help me?
Thank you very much.
David Meng
-------------------Start-----------
#!/usr/bin/perl -w
use strict;
use Graph::Undirected;
my $g = new Graph::Undirected->new;
$g->add_weighted_edge('a', 'b', 1);
$g->add_weighted_edge('a', 'c', 2);
$g->add_weighted_edge('a', 'd',3);
$g->add_weighted_edge('a', 'e',4);
$g->add_weighted_edge('b', 'c',5);
$g->add_weighted_edge('b', 'd',6);
$g->add_weighted_edge('b', 'e',7);
$g->add_weighted_edge('c', 'd',8);
$g->add_weighted_edge('c', 'e',9);
$g->add_weighted_edge('d', 'e',10);
my $SP = $g->APSP_Floyd_Warshall;
$path = $SP->path_length('a', 'e');
print " The shortest path from a to e is $path \n";
@pp= $SP->path_vertices('a','e');
print "path=@pp\n";
--------------END--------
output :
The shortest path from a to e is 4
path=a e
------------------------------
Date: 17 Mar 2005 03:38:15 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: How to use Perl Graph module to solve travel salesperson problem (TSP)?
Message-Id: <Xns961BDC1BCBB94castleamber@130.133.1.4>
Meng wrote:
> Hi All,
> I'm designing a project to solve TSP issue with Perl.
You probably want an approximation since if the number of cities is big you
can drink quite some coffee.
Look for flexmap [1] (easy to implement). I have no idea how good it is
nowadays (i used it over 10 years ago)
I also found this one: http://portal.acm.org/citation.cfm?id=965276
[1] Fritzke, B., & Wilke, P. (1991). FLEXMAP--A neural network for the
traveling salesman problem with linear time and space complexity.
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: 16 Mar 2005 19:49:45 -0800
From: m.fangtao@genesis.co.nz
Subject: Re: How to use Perl Graph module to solve travel salesperson problem (TSP)?
Message-Id: <1111031385.683931.272820@z14g2000cwz.googlegroups.com>
Thanks John. the number of nodes is <10.
------------------------------
Date: 17 Mar 2005 04:00:20 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: How to use Perl Graph module to solve travel salesperson problem (TSP)?
Message-Id: <Xns961BDFDA0E501castleamber@130.133.1.4>
wrote:
> Thanks John. the number of nodes is <10.
Ah, ok,
so that means creating 9! = 362880 paths (at most) and keeping the shortest
one.
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Thu, 17 Mar 2005 05:08:49 +0100
From: Fabian Pilkowski <pilkowsk@informatik.uni-marburg.de>
Subject: Re: Maximum string length in perl
Message-Id: <MPG.1ca3213a5de0d5269898e0@news.individual.de>
* Murugesh wrote:
>
> Anyidea on the maximum length a string in perl can contain.I
> cannot read the whole content of a file into a string,where it trims off
> after a particular limit.Is there any restriction.
No, there isn't one.
> Is there any way to read whole file into a single string?
I prefer to use
my $str = do{ undef $/; <FH> };
but on windowish systems this could be
my $str = do{ undef $/; binmode FH; <FH> };
to read files with binary content correctly. From `perldoc -f binmode`:
Another consequence of using binmode() (on some systems) is that
special end-of-file markers will be seen as part of the data stream.
For systems from the Microsoft family this means that if your binary
data contains \cZ, the I/O subsystem will regard it as the end of
the file, unless you use binmode().
regards,
fabian
------------------------------
Date: Thu, 17 Mar 2005 09:49:58 +0530
From: Murugesh <appumail@gmail.com>
Subject: Re: Maximum string length in perl
Message-Id: <dR7_d.48$W3.37@news.oracle.com>
Fabian,
Thanks ! that works!
My content is not a binary file.In Windows, I tried ,
my $str = do{ undef $/; <FH> };
My question is,
why the follwing code doesnt work,
$/="";
my $str=<FH>;
How does the above code is different from undef $/;
Fabian Pilkowski wrote:
> * Murugesh wrote:
>
>> Anyidea on the maximum length a string in perl can contain.I
>>cannot read the whole content of a file into a string,where it trims off
>>after a particular limit.Is there any restriction.
>
>
> No, there isn't one.
>
>
>>Is there any way to read whole file into a single string?
>
>
> I prefer to use
>
> my $str = do{ undef $/; <FH> };
>
> but on windowish systems this could be
>
> my $str = do{ undef $/; binmode FH; <FH> };
>
> to read files with binary content correctly. From `perldoc -f binmode`:
>
> Another consequence of using binmode() (on some systems) is that
> special end-of-file markers will be seen as part of the data stream.
> For systems from the Microsoft family this means that if your binary
> data contains \cZ, the I/O subsystem will regard it as the end of
> the file, unless you use binmode().
>
> regards,
> fabian
------------------------------
Date: Thu, 17 Mar 2005 04:40:21 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Maximum string length in perl
Message-Id: <VS7_d.51082$KI2.32771@clgrps12>
Murugesh wrote:
>
> Thanks ! that works!
> My content is not a binary file.In Windows, I tried ,
> my $str = do{ undef $/; <FH> };
You shouldn't undef() a global variable like that, it will affect your whole
program. You should use local() instead:
my $str = do{ local $/; <FH> };
> My question is,
>
> why the follwing code doesnt work,
> $/="";
> my $str=<FH>;
>
> How does the above code is different from undef $/;
Because assigning a zero length string to the input record separator variable
sets it to paragraph mode.
perldoc perlvar
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 17 Mar 2005 10:27:05 +0530
From: Murugesh <appumail@gmail.com>
Subject: Re: Maximum string length in perl
Message-Id: <0o8_d.49$W3.108@news.oracle.com>
John,
Does local method also undefines $/.There is no undef inside the do
block.
John W. Krahn wrote:
> Murugesh wrote:
>
>>
>> Thanks ! that works!
>> My content is not a binary file.In Windows, I tried ,
>> my $str = do{ undef $/; <FH> };
>
>
> You shouldn't undef() a global variable like that, it will affect your
> whole
> program. You should use local() instead:
>
> my $str = do{ local $/; <FH> };
>
>
>> My question is,
>>
>> why the follwing code doesnt work,
>> $/="";
>> my $str=<FH>;
>>
>> How does the above code is different from undef $/;
>
>
> Because assigning a zero length string to the input record separator
> variable
> sets it to paragraph mode.
>
> perldoc perlvar
>
>
>
> John
------------------------------
Date: Thu, 17 Mar 2005 06:06:26 +0100
From: Fabian Pilkowski <pilkowsk@informatik.uni-marburg.de>
Subject: Re: Maximum string length in perl
Message-Id: <MPG.1ca32ebe9ebdc7fa9898e2@news.individual.de>
* John W. Krahn wrote:
> Murugesh wrote:
> >
> > Thanks ! that works!
> > My content is not a binary file.In Windows, I tried ,
> > my $str = do{ undef $/; <FH> };
>
> You shouldn't undef() a global variable like that, it will affect your whole
> program. You should use local() instead:
>
> my $str = do{ local $/; <FH> };
Err... this is the second time I'm doing this mistake. Each time it was
in a newsgroup so that everyone could see my inattention ;-( Of course,
I want to localize that var ...
But also, each time one corrects my intention a few minutes later ;-)
thanks,
fabian
------------------------------
Date: Thu, 17 Mar 2005 06:12:06 +0100
From: Fabian Pilkowski <pilkowsk@informatik.uni-marburg.de>
Subject: Re: Maximum string length in perl
Message-Id: <MPG.1ca33011716cd7c29898e3@news.individual.de>
* Murugesh wrote:
>
> Thanks ! that works!
> My content is not a binary file.In Windows, I tried ,
> my $str = do{ undef $/; <FH> };
> My question is,
>
> why the follwing code doesnt work,
> $/="";
> my $str=<FH>;
>
> How does the above code is different from undef $/;
Please take notice what John has posted. Use local() instead of undef().
But in
my $str = do{ local $/; <FH> };
the value of $/ is *undef* since I don't assign any value. In your case
$/ contains an empty string, which isn't the same. All of these values
are described in `perldoc perlvar`. Have a look at it.
Btw, please localize your $/-assignment into an own block, otherwise
this will affect your whole program.
regards,
fabian
------------------------------
Date: Thu, 17 Mar 2005 00:17:26 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Maximum string length in perl
Message-Id: <slrnd3i87m.1kn.tadmc@magna.augustmail.com>
Murugesh <appumail@gmail.com> wrote:
Please do not top-post. Learn how to compose a proper followup.
> Thanks ! that works!
> my $str = do{ undef $/; <FH> };
> My question is,
>
> why the follwing code doesnt work,
> $/="";
> my $str=<FH>;
>
> How does the above code is different from undef $/;
If you are wondering about the values of the $/ variable, then
you should look up the $/ variable in the docs that came with perl:
perldoc perlvar
treating empty lines as a terminator if set to
the null string.
...
You may set it ... to undef to read through the end of file.
...
So, setting it to the empty string (para mode) reads records
that are separated by blank lines (and your code above only
does one read, it never looks at the rest of the file).
Setting it to undef (slurp mode) reads the *entire file*
in one input operation.
[snip TOFU]
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 17 Mar 2005 05:55:10 +0100
From: Fabian Pilkowski <pilkowsk@informatik.uni-marburg.de>
Subject: Re: perl bug with pos() and placing matches in an array?
Message-Id: <MPG.1ca32c17788f59029898e1@news.individual.de>
* t13_e@yahoo.com wrote:
>
> I want to find the first match in the string, place all the submatches
> of the first match into an array, @vars. I also would like to find the
> position in $x of the first match.
>
> It seems like the answer is to attempt the match twice, as follows:
>
> $x = "abcdefg";
> $re = qr/([bd])(.)/;
>
> if(@vars = $x =~ /$re/) #get the submatches of the first match
> {
> $x =~ /$re/g; #find the position of the first match
> $p = pos($x) - length $&;
> print "pos is $p\n";
> print "vars = ".join(' ',@vars)."\n";
> }
Have a look at `perldoc perlvar` where you can learn more about Perl's
predefined variables. The array @+ should contain the same value as what
the pos function returns.
if ( @vars = $x =~ /$re/ ) {
$p = $+[0] - length $&;
print "pos is $p\n";
print "vars = @vars\n"; # special var $" is a blank per default
}
Since you want to know the offset of the start of your match, you could
use the array @- instead of @+.
if ( @vars = $x =~ /$re/ ) {
print "pos is $-[0]\n";
print "vars = @vars\n";
}
regards,
fabian
------------------------------
Date: Thu, 17 Mar 2005 03:29:49 GMT
From: "Aidan" <nospam.aweraw@gmail.com>
Subject: Perl equiv to PHP print_r
Message-Id: <newscache$l19hdi$jtd$1@titan.linknet.com.au>
Hi Perl Peoples,
I'm quit new to perl, but have a pretty good knowledge of PHP. I'm playing
around with a few packages, and I'm having a bit of trouble figuring out how
to deal with hashes. In PHP, if I wanted to view the contents of $hash, all
I needed to do would be dump it out by using:
<? print_r($hash); ?>
And I would get a nice heirachial display of the data contained within
$hash. Is there an equivalent function in Perl? I'm sure there is, but
after much googling, I still can't find what it is... can anyone here tell
me what it is?
TIA
Aidan
------------------------------
Date: Thu, 17 Mar 2005 13:37:10 +1000
From: SMO <smoNOSPAM@smo.onthenet.com.au>
Subject: Re: Perl equiv to PHP print_r
Message-Id: <newscache$gq8hdi$ust1$1@elise.onthenet.com.au>
Aidan wrote:
> Hi Perl Peoples,
>
> I'm quit new to perl, but have a pretty good knowledge of PHP. I'm playing
> around with a few packages, and I'm having a bit of trouble figuring out how
> to deal with hashes. In PHP, if I wanted to view the contents of $hash, all
> I needed to do would be dump it out by using:
>
> <? print_r($hash); ?>
>
> And I would get a nice heirachial display of the data contained within
> $hash. Is there an equivalent function in Perl? I'm sure there is, but
> after much googling, I still can't find what it is... can anyone here tell
> me what it is?
>
> TIA
>
> Aidan
Have a look at Data::Dumper
MS
------------------------------
Date: 17 Mar 2005 02:21:25 -0800
From: "makko" <elmakko@gmail.com>
Subject: Re: perlcc error
Message-Id: <1111054885.462412.154570@g14g2000cwa.googlegroups.com>
PP works perfect thanx, but do the executables work on a machine with
the same operating sysytem but without perl installed?
Example: i make the executable on Linux_X86-perl_installed and run it
on Linux_SPARC64-perl_!_installed.
regards,
Makko
------------------------------
Date: 17 Mar 2005 00:07:09 -0800
From: "Smugsboy" <smugs_boy@yahoo.com>
Subject: Re: PerlScript (WSH) - Cannot set property
Message-Id: <1111046829.302496.238030@z14g2000cwz.googlegroups.com>
No it does not.
------------------------------
Date: Thu, 17 Mar 2005 04:07:07 GMT
From: Bob Walton <see.sig@rochester.rr.com>
Subject: Re: Regex - every character but "
Message-Id: <Ln7_d.83606$vK5.13086@twister.nyroc.rr.com>
Sherm Pendley wrote:
> Cyde Weys wrote:
...
> [\x00..\x7f]
That should probably be:
[\x00-\x7f]
...
> sherm--
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
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 7890
***************************************