[23751] in Perl-Users-Digest
Perl-Users Digest, Issue: 5955 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 18 18:05:43 2003
Date: Thu, 18 Dec 2003 15: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, 18 Dec 2003 Volume: 10 Number: 5955
Today's topics:
Re: $dbh->tables() returns nothing (Bryan Castillo)
array of NAMED hashes instead of ANONYMOUS hashes; is t <jwngaa@att.net>
Re: array of NAMED hashes instead of ANONYMOUS hashes; <shondell@cis.ohio-state.edu>
Re: array of NAMED hashes instead of ANONYMOUS hashes; <noreply@gunnar.cc>
Re: array of NAMED hashes instead of ANONYMOUS hashes; (Malcolm Dew-Jones)
Re: array of NAMED hashes instead of ANONYMOUS hashes; <noreply@gunnar.cc>
Re: array of NAMED hashes instead of ANONYMOUS hashes; <uri@stemsystems.com>
Benchmark 2 codes (Edo)
Re: Benchmark 2 codes <uri@stemsystems.com>
Re: Can you undo a read from a file <usenet@morrow.me.uk>
Re: Determine DaysInMonth($month) <jundy@jundy.com>
How to apend 1 file to another? <test@test.com>
Re: How to apend 1 file to another? <uri@stemsystems.com>
Re: How to apend 1 file to another? <test@test.com>
Re: How to apend 1 file to another? <uri@stemsystems.com>
Re: logonserver value <jwillmore@remove.adelphia.net>
perl golf techniques (Scott)
Re: Please critique this short script that scans a log <uri@stemsystems.com>
Re: Problems reading in "£" character from a file <usenet@morrow.me.uk>
Re: reading from an url (Bryan Castillo)
Re: RegExp check for nothing or pattern (Sam Holden)
Re: Signaling another machine <mahesha@mahesha.net>
Re: Signaling another machine <jundy@jundy.com>
Re: Signaling another machine (Jim)
Re: Signaling another machine <jwillmore@remove.adelphia.net>
Re: Signaling another machine <jwillmore@remove.adelphia.net>
Re: strange results using m//g in while loop... (Anno Siegel)
Re: strange results using m//g in while loop... <usenet@morrow.me.uk>
Re: When closing DOS window... <usenet@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 18 Dec 2003 11:39:04 -0800
From: rook_5150@yahoo.com (Bryan Castillo)
Subject: Re: $dbh->tables() returns nothing
Message-Id: <1bff1830.0312181139.4462acda@posting.google.com>
"Julia deSilva" <jds@nospantrumpetweb.co.uk> wrote in message news:<3xXDb.22875$5F2.897@news-binary.blueyonder.co.uk>...
> Hi there all,
>
> Unix Perl MYSQL
>
> Has anyone experienced on some servers ...
>
> my @tables = $dbh->tables() returning nothing Nil Nada zilch when you are
> 100% sure you have oodles of tables ?
>
> Is this a known problem, is there a fix, workaround ?
>
> TIA and Merry Xmas.
>
> J
I haven't experience the problem, but if you need the tables in the meantime.
Here ya go:
sub show_tables {
my $dbh = shift;
my @tables;
my $st = $dbh->prepare('show tables');
$st->execute;
while (my $row = $st->fetchrow_arrayref) {
push(@tables, $row->[0]);
}
return @tables;
}
------------------------------
Date: Thu, 18 Dec 2003 13:40:44 -0600
From: J.W. <jwngaa@att.net>
Subject: array of NAMED hashes instead of ANONYMOUS hashes; is this possible?
Message-Id: <opv3uv4uplng3riee3443us7qjbp2uefb3@4ax.com>
The "Learning Perl" and "Programming Perl" books don't seem to explain
the problem I have with the program I have below.
Every example of arrays of hashes I've seen so far in books uses
anonymous hashes. Can you reliably use named hashes in arrays in
Perl? If so what's the trick?
For example, the @x using anonymous hash works. When the hash is
pushed onto the array, the number of elements is 1 and the
$x[0]->{"Tablespace_name"} syntax works as expected.
However, when I push a NAMED hash onto @y, the number of elements is 4
and the print $y[0]->{"Tablespace_name"} syntax doesn't work.
What's the difference between @x and @y? It seems that Perl expands
%ss_data into 4 elements during the push operation. Why does it do
that?
#-------
my @x;
my @y;
print "elements: " . scalar(@x) . "\n";
print "elements: " . scalar(@y) . "\n";
print "\n";
push @x, {"Tablespace_name" => "SYS", "PS" => 4096};
print "elements: " . scalar(@x) . "\n";
print $x[0]->{"Tablespace_name"} . "\n";
my %ss_data = ("Tablespace_name" => "SYS", "PS" => 4096);
push @y, %ss_data;
print "elements: " . scalar(@y) . "\n";
print $y[0]->{"Tablespace_name"} . "\n";
#---- output of the script
elements: 0
elements: 0
elements: 1
SYS
elements: 4
Use of uninitialized value in concatenation (.) or string at c:\ww.pl
line 16.
------------------------------
Date: 18 Dec 2003 15:01:03 -0500
From: Ryan Shondell <shondell@cis.ohio-state.edu>
Subject: Re: array of NAMED hashes instead of ANONYMOUS hashes; is this possible?
Message-Id: <xcwu13xx5ds.fsf@psi.cis.ohio-state.edu>
J.W. <jwngaa@att.net> writes:
> The "Learning Perl" and "Programming Perl" books don't seem to explain
> the problem I have with the program I have below.
>
> Every example of arrays of hashes I've seen so far in books uses
> anonymous hashes. Can you reliably use named hashes in arrays in
> Perl? If so what's the trick?
No trick. Context, context, context. :-)
push takes an array, and a list. perl is nice enough to use your
second argument in list context...even if you didn't mean it that way,
exactly.
> For example, the @x using anonymous hash works. When the hash is
> pushed onto the array, the number of elements is 1 and the
> $x[0]->{"Tablespace_name"} syntax works as expected.
>
> However, when I push a NAMED hash onto @y, the number of elements is 4
> and the print $y[0]->{"Tablespace_name"} syntax doesn't work.
A hash in list context interpolates all the keys and values into the
list.
> What's the difference between @x and @y? It seems that Perl expands
> %ss_data into 4 elements during the push operation. Why does it do
> that?
>
>
> #-------
>
> my @x;
> my @y;
>
> print "elements: " . scalar(@x) . "\n";
> print "elements: " . scalar(@y) . "\n";
> print "\n";
>
>
> push @x, {"Tablespace_name" => "SYS", "PS" => 4096};
Here you are pushing a list of 1 item onto @x, an anonymous hash
reference.
> print "elements: " . scalar(@x) . "\n";
> print $x[0]->{"Tablespace_name"} . "\n";
Since $x[0] is a reference to your hash, you can use the
$hashref->{key} notation to get your value.
>
> my %ss_data = ("Tablespace_name" => "SYS", "PS" => 4096);
> push @y, %ss_data;
push takes an array and a list. By using %ss_data, you are telling
perl to use that hash in list context, and push all the elements of
that list onto @y. It would be the same as doing...
push @y, ("Tablespace_name", "SYS", "PS", 4096);
> print "elements: " . scalar(@y) . "\n";
> print $y[0]->{"Tablespace_name"} . "\n";
This is essentially doing
"Tablespace_name"->{"Tablespace_name"}
Which obviously isn't what you want. And perl doesn't particularly
care for it either.
However, you can push a named hash reference onto an array. Or you
could push a reference to a named hash... :-)
# named hash reference
$some_ref = {"Tablespace_name" => "SYS", "PS" => 4096};
push @x, $some_ref;
# reference to named hash
%some_hash = ("Tablespace_name" => "SYS", "PS" => 4096);
push @x, \%some_hash;
Ryan
--
perl -e '$;=q,BllpZllla_nNanfc]^h_rpF,;@;=split//,
$;;$^R.=--$=*ord for split//,$~;sub _{for(1..4){$=
=shift;$=--if$=!=4;while($=){print chr(ord($;[$%])
+shift);$%++;$=--;}print " ";}}_(split//,$^R);q;;'
------------------------------
Date: Thu, 18 Dec 2003 21:10:07 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: array of NAMED hashes instead of ANONYMOUS hashes; is this possible?
Message-Id: <brt1t8$7bs1u$1@ID-184292.news.uni-berlin.de>
J.W. wrote:
> It seems that Perl expands %ss_data into 4 elements during the push
> operation. Why does it do that?
<snip>
> my %ss_data = ("Tablespace_name" => "SYS", "PS" => 4096);
> push @y, %ss_data;
Because the push() function expects a list as its second argument, so
that just populates @y with the keys and values of the hash. Like when
you do
@y = %ss_data;
I'm not sure what you mean by array of named hashes, but you can of
course do:
push @y, \%ss_data;
but it results in an anonymous hash just as in your @x example.
Maybe you would prefer a hash of hashes:
my %y;
my %ss_data = ("Tablespace_name" => "SYS", "PS" => 4096);
$y{ss_data} = \%ss_data;
print $y{ss_data}->{'Tablespace_name'}, "\n";
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 18 Dec 2003 12:59:58 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: array of NAMED hashes instead of ANONYMOUS hashes; is this possible?
Message-Id: <3fe2154e@news.victoria.tc.ca>
Gunnar Hjalmarsson (noreply@gunnar.cc) wrote:
: J.W. wrote:
: > It seems that Perl expands %ss_data into 4 elements during the push
: > operation. Why does it do that?
: <snip>
: > my %ss_data = ("Tablespace_name" => "SYS", "PS" => 4096);
: > push @y, %ss_data;
: Because the push() function expects a list as its second argument, so
: that just populates @y with the keys and values of the hash. Like when
: you do
: @y = %ss_data;
: I'm not sure what you mean by array of named hashes, but you can of
: course do:
: push @y, \%ss_data;
: but it results in an anonymous hash just as in your @x example.
not quite
If you push \%ss_data then the result is a reference to the named hash.
If you change the values in the named hash and then access the hash from
the array then you will see the changes, and vice versa.
This might be useful. For example to update a specific item, (by the
name of the hash) or to scan through a list of all your hashes.
my %main_window_config;
# we want to directly control the top window
$main_window_config{x}=100;
my @window_things;
push @window_things , \%main_window_config;
# we want to modify all the windows, the top plus any children
foreach my $thing (@window_things)
{ $thing->{width}++;
}
------------------------------
Date: Thu, 18 Dec 2003 22:22:58 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: array of NAMED hashes instead of ANONYMOUS hashes; is this possible?
Message-Id: <brt66u$7bttg$1@ID-184292.news.uni-berlin.de>
Malcolm Dew-Jones wrote:
> Gunnar Hjalmarsson wrote:
>> ... you can of course do:
>>
>> push @y, \%ss_data;
>>
>> but it results in an anonymous hash just as in your @x example.
>
> not quite
>
> If you push \%ss_data then the result is a reference to the named
> hash.
>
> If you change the values in the named hash and then access the hash
> from the array then you will see the changes, and vice versa.
You are right, of course. The reference does not refer to a new
(anonymous) copy, but to the existing named hash, which can be
accessed both ways.
Thanks for correcting me!
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 18 Dec 2003 21:44:09 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: array of NAMED hashes instead of ANONYMOUS hashes; is this possible?
Message-Id: <x7oeu5ajiv.fsf@mail.sysarch.com>
>>>>> "GH" == Gunnar Hjalmarsson <noreply@gunnar.cc> writes:
> Malcolm Dew-Jones wrote:
>> Gunnar Hjalmarsson wrote:
>>> ... you can of course do:
>>> push @y, \%ss_data;
>>> but it results in an anonymous hash just as in your @x example.
>> not quite
>> If you push \%ss_data then the result is a reference to the named
>> hash.
>> If you change the values in the named hash and then access the hash
>> from the array then you will see the changes, and vice versa.
> You are right, of course. The reference does not refer to a new
> (anonymous) copy, but to the existing named hash, which can be
> accessed both ways.
but if you do this in a loop and declare the named hash with my, it will
allocate a new hash for you. if my detects the named hash has a ref to
it, it will do this. so you can build in the named hash and accumulate
them in something else and get unique hash refs that way. way you can
even return a ref to a my variable and not leak or corrupt the stack
(unlike c where if you return a pointer to something on the stack, you
are dead).
another way perl is smarter than you. :)
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 18 Dec 2003 13:52:48 -0800
From: phddas@yahoo.com (Edo)
Subject: Benchmark 2 codes
Message-Id: <27fcd8bd.0312181352.3dc2d56c@posting.google.com>
Hello
I am not able to run these 2 codes to find which is faster because I
just don't know how to. any help is appriciated.
thanks
#!/perl -w
use strict;
use warnings;
use List::Permutor;
use Algorithm::Permute;
use Benchmark qw(:all);
my $perm = new List::Permutor qw/ a b c d e /;
while (my @set = $perm->next) {
print "@set.\n";
}
my $p = new Algorithm::Permute(['a'..'e']);
while (my @res = $p->next) {
print join(", ", @res), "\n";
}
cmpthese($count, {
'Name1' => '...code1...',
'Name2' => '...code2...',
});
------------------------------
Date: Thu, 18 Dec 2003 22:29:08 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Benchmark 2 codes
Message-Id: <x765gdahfw.fsf@mail.sysarch.com>
>>>>> "E" == Edo <phddas@yahoo.com> writes:
> I am not able to run these 2 codes to find which is faster because I
> just don't know how to. any help is appriciated.
> my $perm = new List::Permutor qw/ a b c d e /;
> while (my @set = $perm->next) {
> print "@set.\n";
> }
> my $p = new Algorithm::Permute(['a'..'e']);
> while (my @res = $p->next) {
> print join(", ", @res), "\n";
> }
wrap those two snippets in subs.
> cmpthese($count, {
> 'Name1' => '...code1...',
> 'Name2' => '...code2...',
call the subs in the strings. choose better names (like the module names)
done.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Thu, 18 Dec 2003 22:17:45 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Can you undo a read from a file
Message-Id: <brt929$evr$1@wisteria.csv.warwick.ac.uk>
timothy@greenwood.name (Tim Greenwood) wrote:
> Is it possible (and preferably simple) to undo a line input from STDIN
> or any file handle? I want to do something like
If you're using 5.8 and have a perl built with PerlIO (you probably
have if it's 5.8), you can use my module IO::Unread. It uses
Inline::C, and due to issues with Inline::MakeMaker you will need to
install at least Inline first: CPAN.pm will probably install Inline::C
for you.
Ben
--
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes, [ Heracles shoots Vulture with arrow. Vulture bursts into ]
/Alcestis/) [ flame, and falls out of sight. ] ben@morrow.me.uk
------------------------------
Date: Thu, 18 Dec 2003 19:14:23 GMT
From: Erik Tank <jundy@jundy.com>
Subject: Re: Determine DaysInMonth($month)
Message-Id: <e9c2d8126c35efd3b35203b59312885a@news.teranews.com>
You can install the perl modules locally:
http://servers.digitaldaze.com/extensions/perl/modules.html#install
This way you don't need to recreate the module nor do you have to have
root privileges to intall it.
The only draw back I see with this is that you need to have the 'use
lib <path>' statement so if you move the program to a different server
you need to make sure that this is correct before you are able to use
it again.
PS: I would recommend using Date::Calc, but I think that is more of a
personal preference.
On Thu, 18 Dec 2003 12:57:39 -0000, "Eric" <Eric@nowhere.com> wrote:
>Hi,
>
>Can you help me write a piece of code to do this:
>
>my $daysinmonth = &DaysInMonth($month)
>
>Where $month is the month num (1-12).
>
>I don't have the ability to install modules as I'm on a shared server. And I
>don't have Time::DaysInMonth installed.
>
>Thank you!
>
>
>Eric
>
------------------------------
Date: Thu, 18 Dec 2003 20:13:01 GMT
From: "Wow" <test@test.com>
Subject: How to apend 1 file to another?
Message-Id: <hTnEb.485841$0v4.21460202@bgtnsc04-news.ops.worldnet.att.net>
Do I have to read file1 and do a >> to file2? Any easiler way? Perl or Shell
scripts are both OK.
------------------------------
Date: Thu, 18 Dec 2003 20:52:00 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: How to apend 1 file to another?
Message-Id: <x7ad5pc0i7.fsf@mail.sysarch.com>
>>>>> "W" == Wow <test@test.com> writes:
> Do I have to read file1 and do a >> to file2? Any easiler way? Perl
> or Shell scripts are both OK.
use File::Slurp ;
my $text = read_file( 'file1' ) ;
append_file( 'file2', $text ) ;
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Thu, 18 Dec 2003 22:08:44 GMT
From: "Public Interest" <test@test.com>
Subject: Re: How to apend 1 file to another?
Message-Id: <MzpEb.487144$0v4.21466612@bgtnsc04-news.ops.worldnet.att.net>
is there a way to apend it without read it first? such as cat a.txt b.txt >
b.txt
> > Do I have to read file1 and do a >> to file2? Any easiler way? Perl
> > or Shell scripts are both OK.
>
> use File::Slurp ;
>
> my $text = read_file( 'file1' ) ;
> append_file( 'file2', $text ) ;
>
> uri
>
> --
> Uri Guttman ------ uri@stemsystems.com --------
http://www.stemsystems.com
> --Perl Consulting, Stem Development, Systems Architecture, Design and
Coding-
> Search or Offer Perl Jobs ----------------------------
http://jobs.perl.org
------------------------------
Date: Thu, 18 Dec 2003 22:27:25 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: How to apend 1 file to another?
Message-Id: <x78yl9ahiq.fsf@mail.sysarch.com>
>>>>> "PI" == Public Interest <test@test.com> writes:
> is there a way to apend it without read it first? such as cat a.txt b.txt >
> b.txt
don't top post. read the group guidelines (posted regularly)
what do you think cat is doing there, twiddling its thumbs? it is
reading the file. and that shell example has a classic bug in it.
and even if you fixed the bug, it reads the second file which is not
needed.
file systems don't usually provide ways of moving data without reading
them. so how would you do it without reading the file?
and you asked for a perl solution and i gave you one. what more do you want?
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Thu, 18 Dec 2003 22:56:54 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: logonserver value
Message-Id: <20031218175654.78421e64.jwillmore@remove.adelphia.net>
On Thu, 18 Dec 2003 17:19:05 -0000
"Chris Arnott" <chris.arnottHATESSPAM@uk.lionbioscience.com> wrote:
> I have a perl script which gathers information on a remote machine
> and creates a php file from the gathered info.
>
> I'd like to gather the logonserver value from the remote machine but
> if I try reading the hkcu/volatile environment/logonserver value i
> get a overlapped io in progress error.
>
> Does anyone know of a good way to achieve this?
[Sigh]
Please post some code and we may be able to help. From what you've
written it's like *me* asking *you* for directions to *my* home.
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
What I tell you three times is true.
------------------------------
Date: 18 Dec 2003 11:10:55 -0800
From: googlegroups@scottsavarese.com (Scott)
Subject: perl golf techniques
Message-Id: <677a147d.0312181110.f890f6d@posting.google.com>
My company is running a perl golf contest and I am looking for some
tricks hints and techniques that I could use to help with my code. Do
you guys know any good websites, or news threads, that I could look at
which discuss the things people do to help to reduce the length of
their code?
Thanks,
Scott
------------------------------
Date: Thu, 18 Dec 2003 19:18:31 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Please critique this short script that scans a log file
Message-Id: <x7smjiaq9k.fsf@mail.sysarch.com>
>>>>> "MP" == Matija Papec <perl@my-header.org> writes:
> I guess this partly depends on personal style, more important is that elsif
> is shorter (this also reads "cleaner" if it isn't obfuscation) as you only
> need "els" in front of "if" and with if/next you'll need "next;\n", which is
> also an additional command while "elsif" isn't.
> == if/next ==
> if () {
> ..
> next;
> }
> if () {
> ..
> next;
> }
> ..
> next;
> == if/elsif ==
> if () {
> ..
> }
> elsif () {
> ..
> }
> else {
> ..
> }
but you are missing the real win there. use statement modifiers when you
can. elsif can't be used like that.
next if /blah/ ;
last unlexx /foo/ ;
return if $bar == 3 ;
you lose the {}, the indent and the extra lines.
if the if clause or block is too long or complex, i will use a full if
(and else/elsif if needed) but i try to use that style of flow control
with statement modifiers as much as possible. it is amazing how much
code can be shrunk using them and you don't lose any clarity if done
correctly. i have restructured loops/subs and such just to make the work
better this way and the code is markedly better then. but as i said,
don't go overboard and force this on all flow statements, use it only for
the short and clear ones. but coding so that your conditionals are short
and clear is another skill in itself.
>> in over 8000 lines of stem code i have 15 elsif's. so it isn't something
>> i need to use often. long cascaded if/else/elsif's are a poor coding
>> construct IMO. there are usually better ways to do it.
> I did some reading on it, can it be used for automating tasks on remote
> computers?(sorry if you already covered this in the docs)
yep. all sorts of remote and local operations can be automated. stem
doesn't do that directly but it is a framework which makes it much
easier to do that. you need much less code and get a more flexible
system when you use it. message passing is a universal API in stem and
it can be looked at as a super glue application :).
one key thing is that you can prototype an application in one stem
process on one box and without any new code (just configuration changes)
expand it to work on multiple processes on multiple boxes. the same
message passing API works locally or remotely.
also .11 (due out SOON i hope) has a great way to handle flow control of
sync AND async methods on an object. that is a very tricky problem with
most complex local/remote control designs and it is much easier in stem.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Thu, 18 Dec 2003 22:48:38 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Problems reading in "£" character from a file
Message-Id: <brtas6$fmn$3@wisteria.csv.warwick.ac.uk>
"Stephen Adam" <stephen.adaam@ntlworld.com> wrote:
> Just run this program and make sure you place a file the same directory
> called test.txt with some pound signs (£) in it, they keep getting
> mytseriously turned into accented u's.
This is not a perl problem, it is a problem with DOS windows being
stupid about character encodings. If you direct your output to a file
instead you should find that your £s are intact.
Ben
--
'Deserve [death]? I daresay he did. Many live that deserve death. And some die
that deserve life. Can you give it to them? Then do not be too eager to deal
out death in judgement. For even the very wise cannot see all ends.'
:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-: ben@morrow.me.uk
------------------------------
Date: 18 Dec 2003 11:55:06 -0800
From: rook_5150@yahoo.com (Bryan Castillo)
Subject: Re: reading from an url
Message-Id: <1bff1830.0312181155.57c6d162@posting.google.com>
raj1_iit@yahoo.com (Rajesh) wrote in message news:<bb6dafde.0312162336.1836cba5@posting.google.com>...
> Hi,
>
> I checked the archives and faq in Perl. ostly from the archives, I got
> to put up the following code to read from an url. But, if i run this
> code i get the error,
> 500: Can't connect to www.yahoo.com:80 ((Bad hostname www.yahoo.com)
>
> I believe it has something to do with internet connectivity. But, i
> can acces the page using Internet explorer. So, do i have to specify
> some proxy or something in the program?
^^^^^
Do you have a proxy configured in IE?
If so you might try setting the proxy.
From LWP::UserAgent docs
$ua->proxy(...)
Set/retrieve proxy URL for a scheme:
$ua->proxy(['http', 'ftp'], 'http://proxy.sn.no:8001/');
$ua->proxy('gopher', 'http://proxy.sn.no:8001/');
The first form specifies that the URL is to be used for proxying
of access methods listed in the list in the first method argument,
i.e. 'http' and 'ftp'.
The second form shows a shorthand form for specifying proxy URL
for a single access scheme.
> Or is something wrong with the script?
> P.S... I am running the perl script in Windows XP.
>
> #!/usr/local/bin/perl -w
>
> use LWP::Simple;
> use LWP::UserAgent;
>
> $url = "http://www.yahoo.com";
>
> $ua = new LWP::UserAgent;
> $ua->agent("$0/0.1");
>
> $req = new HTTP::Request 'HEAD', $url;
> $req->header('Accept' => 'text/html');
>
> # send request
> $res = $ua->request($req);
>
> # check the outcome
> if ($res->is_success) {
> print "The link <$url> is ok.\n";
> } else {
> print "<$url>\n";
> print " " . $res->code . " " . $res->message . "\n\n";
> }
>
>
> Rajesh
------------------------------
Date: 18 Dec 2003 20:47:10 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: RegExp check for nothing or pattern
Message-Id: <slrnbu44ie.vas.sholden@flexal.cs.usyd.edu.au>
On Thu, 18 Dec 2003 19:00:09 -0000, Eric <Eric@nowhere.com> wrote:
> Jeez you guys take this so seriously don't you!
>
> It wasn't _really_ to annoy him, it was a simple mistake. My comment was an
> example of what's referred to as 'sarcasm'. Perhaps you've not come across
> it.
>
> Get a grip guys!
A remarkably foolish thing to do. Since things like sarcasm tend not
to work very well in usenet and email (hence the use of "smileys"), due
to the lack of tone of voice, facial expression, etc, etc.
This newsgroup is very high volume, and a large number of the most
knowledgable and helpful posters use killfiles, so that they won't
be overwhelmed by the garbage. They know that there is some
"collateral damage", but also know that ignoring some reasonable posts
is better than ignoring all posts (because the volume it too high).
Welcome to the "collateral damage" group.
--
Sam Holden
------------------------------
Date: Thu, 18 Dec 2003 11:19:30 -0800
From: Mahesha <mahesha@mahesha.net>
Subject: Re: Signaling another machine
Message-Id: <vu3ve2fcoqec48@corp.supernews.com>
Palaniappan wrote:
> Hi all,
>
> Is there any way to signal another machine?
>
> My problem is...
> I like to do run a sequence of perl scripts automatically in
> different machines. They should be run one by one in different
> machines in a sequence.
>
> After completing a script in one machine, how to signal another
> machine to start next script.
>
> All machines are connected through LAN.
I am not into networking, but this seemed to be a possible solution.
If the sequence in which a particular script is to be run on a specific
host is known, can you let one machine do the scheduling? Something on
the lines of...
------------
#!/usr/local/bin/perl -w
use strict;
my @work = (["host1" , "host1script"],
["host2" , "host2script"],
["host3" , "host3script"],
["host4" , "host4script"]
);
my $user="username";
foreach (@work) {
print `rsh -l $user @$_`;
}
----------------
HTH.
--
Mahesh
------------------------------
Date: Thu, 18 Dec 2003 19:20:06 GMT
From: Erik Tank <jundy@jundy.com>
Subject: Re: Signaling another machine
Message-Id: <bafb41532a00719dc6df5533b3e41b7a@news.teranews.com>
Check out SOAP::Lite on CPAN.
FYI: SOAP -> Simple Object Access Protocol
On 18 Dec 2003 07:55:07 -0800, palam_analog@yahoo.co.in (Palaniappan)
wrote:
>Hi all,
>
>Is there any way to signal another machine?
>
>My problem is...
>I like to do run a sequence of perl scripts automatically in
>different machines. They should be run one by one in different
>machines in a sequence.
>
>After completing a script in one machine, how to signal another
>machine to start next script.
>
>All machines are connected through LAN.
>
>I know this group discusses mostly about perl coding. but i don't
>have good knowledge about computer networks. so i am looking for
>a perl solution directly, that's why i posted here.. :-)
>
>-with regards
>palam
------------------------------
Date: 18 Dec 2003 12:56:42 -0800
From: james.woodworth@ricardo.com (Jim)
Subject: Re: Signaling another machine
Message-Id: <d1b55932.0312181256.2d753b77@posting.google.com>
> Is there any way to signal another machine?
i think what you want is:
$ perldoc perlfaq9
$ perldoc perlipc
also, try browsing:
$ perldoc perltoc (table of contents)
this is documentation that comes with perl.
do these help?
------------------------------
Date: Thu, 18 Dec 2003 22:48:56 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Signaling another machine
Message-Id: <20031218174855.25d65aec.jwillmore@remove.adelphia.net>
On Thu, 18 Dec 2003 11:19:30 -0800
Mahesha <mahesha@mahesha.net> wrote:
> Palaniappan wrote:
> I am not into networking, but this seemed to be a possible solution.
>
> If the sequence in which a particular script is to be run on a
> specific host is known, can you let one machine do the scheduling?
> Something on the lines of...
> ------------
> #!/usr/local/bin/perl -w
>
> use strict;
>
> my @work = (["host1" , "host1script"],
> ["host2" , "host2script"],
> ["host3" , "host3script"],
> ["host4" , "host4script"]
> );
>
> my $user="username";
>
> foreach (@work) {
> print `rsh -l $user @$_`;
> }
> ----------------
Nice, but not portable. What if these are Windoze boxes?
If you goes this route, you might as well use expect or the Expect
module for Perl.
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
WARNING TO ALL PERSONNEL: Firings will continue until morale
improves.
------------------------------
Date: Thu, 18 Dec 2003 22:52:12 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Signaling another machine
Message-Id: <20031218175212.55fad6ee.jwillmore@remove.adelphia.net>
On 18 Dec 2003 07:55:07 -0800
palam_analog@yahoo.co.in (Palaniappan) wrote:
> Is there any way to signal another machine?
>
> My problem is...
> I like to do run a sequence of perl scripts automatically in
> different machines. They should be run one by one in different
> machines in a sequence.
>
> After completing a script in one machine, how to signal another
> machine to start next script.
>
> All machines are connected through LAN.
>
> I know this group discusses mostly about perl coding. but i don't
> have good knowledge about computer networks. so i am looking for
> a perl solution directly, that's why i posted here.. :-)
You could set up a client script to run on each client and a server
script to run on a server box. The server script contacts the clients
ands then does whatever needs to be done.
Net::EasyTCP is a module that could aid in this task.
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
A continuing flow of paper is sufficient to continue the flow of
paper. -- Dyer
------------------------------
Date: 18 Dec 2003 22:30:27 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: strange results using m//g in while loop...
Message-Id: <brt9q3$4hp$1@mamenchi.zrz.TU-Berlin.DE>
Damian <not_a_real@adress.getting.too.much.spam.org> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
>
> > Another way is to provide the behavior of /g in scalar context
> > explicitly
> > while calling it in list context:
> >
> > while ( my @matches = /\G<something>/ ) {
> > pos = $+[ 0];
> > # ...
> > }
>
> Thank you Anno, I tried using the above, as it seems to be the solution
> I'm looking for, though it never seems to enter the loop:
>
> my $re_d = qr|(\d),(\d),(\d)|;
>
> my $s = "abcde1,2,3hk4,5,6hkgk7,8,9dfdfdfd";
>
> while (my @r = $s =~ m/\G$re_d/) {
> pos($s) = $+[0];
> print "[@r]\n";
> }
>
> (I tried it with the /g modifier too, though I didn't think it should be
> there in this case.)
No, I was assuming something that wasn't given, namely that your regex
matched everything from the last match (or start of string) to, well,
where the next match should begin. Make it so and it works. One could
use \w* to eat the leading alphabetics:
my $re = qr|\w*(\d),(\d),(\d)|;
Anno
------------------------------
Date: Thu, 18 Dec 2003 22:32:24 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: strange results using m//g in while loop...
Message-Id: <brt9to$fmn$1@wisteria.csv.warwick.ac.uk>
Brian McCauley <nobull@mail.com> wrote:
> The number of the last successful capture in the regex is $#- and the
> total number of captures in the regex is in $#+.
Ouch! These *really* ought to be the same.
I would prefer to write $#+ as @+-1, because $#+ is an ordinal
while scalar(@+) is a cardinal. This would bite if you were daft
enough to change $[... :)
Ben
--
If you put all the prophets, | You'd have so much more reason
Mystics and saints | Than ever was born
In one room together, | Out of all of the conflicts of time.
ben@morrow.me.uk |----------------+---------------| The Levellers, 'Believers'
------------------------------
Date: Thu, 18 Dec 2003 22:44:05 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: When closing DOS window...
Message-Id: <brtajl$fmn$2@wisteria.csv.warwick.ac.uk>
"Richard S Beckett" <spikeywan@bigfoot.com.delete.this.bit> wrote:
> However, I have found that if the user presses the X button on the window,
> then I am again left with an orphan Excel process.
"Windows cannot shut down this program automatically. It is
recommended that you exit this program with its quit or exit command"
If a user ignores a warning like that, they get what they deserve :).
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.
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 5955
***************************************