Re: Can anyone comment on Sams Teach Yourself Perl in 21 Days ?

2009-03-14 Thread Raymond Wan


Hi Shlomi,


Shlomi Fish wrote:
Yes, those or Beginning Perl ( http://www.perl.org/books/beginning-perl/ ) 
would be my choice too. I admit I haven't read them, but I'm judging them 
based on reputation.


However, my point was that my pupil found this book in a library and borrowed 
it (which didn't cost her anything), and I can either tell her that it's OK to 
read it and learn from it, or that she should print or buy (depending on her 
preferences) a different book.



I think the consensus seems to be that if your student had asked you for a book 
suggestion, this one might not have many people's choices.  :-)  But as a teacher, I 
think you should use the learn-it-my-way card as rarely as possible.  I, for 
one, prefer books over web pages and perldoc since I prefer to read on paper than on a 
screen (printing's close...but not quite the same...)

If your pupil has chosen this book from the library all on her own, I think you should let her be and 
wait to see if she says, I don't understand this chapter since it gives very little 
details  To this, you open your bag and answer, Funny you should ask because I have 
another book here with the answer you need...  :-)

Ray


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Error: Can't call method x without a package or object reference...

2009-03-14 Thread M. Coiffure
Hi all

I'm getting this error on the following (test) script: 

Can't call method x without a package or object reference at test.pl line 12 
ENT line 1

What I want to do is create a HashMap where the keys are names of accented 
characters (as they are used in entities) and the values the UTF character 
itself. 

What am I doing wrong?

ENT has lines that look like this: 
aacute 00E1


here's my script (test.pl): 


---

#!/usr/bin/perl
use strict;
use warnings;

my %ent;
open ENT, entities.txt or die cannot read entities: $!;

while (ENT) {
chomp;
m/^(.+) (.+)$/;
print [$1]\t[$2]\n;
$ent{$1} = \x{$2};
}


---

before the error, the script prints (as expected): [aacute]\t[00E1]\n

Is there anything very fundamental I'm overlooking? (please be patient with me, 
I'm not a computer scientist, but a linguist doing some basic programming.)

Many thanks for your help!

MCoiff

-- 
Nur bis 16.03.! DSL-Komplettanschluss inkl. WLAN-Modem für nur 
17,95 ¿/mtl. + 1 Monat gratis!* http://dsl.gmx.de/?ac=OM.AD.PD003K11308T4569a

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




How to use a configuration file?

2009-03-14 Thread Michael Renner
Moin,

I wrote a simple http proxy. This script have some configuration entries like

my $remoteProxy = 'http://localhost:8080/';
$ENV{'http_proxy'} = $remoteProxy;
.
.
# initialisation
my $proxy = HTTP::Proxy-new( port = 3128 );
$proxy - host(127.0.0.1);


I want to get some of these values (remoteProxy, the port and the IP address 
and some things more) from a configuration file. What is a good way to do 
this? What is a good format for this file? Human readable and easy to parse?

Thanks
-- 
|Michael Renner  E-mail: michael.ren...@gmx.de  |
|D-81541 Munich  GermanyICQ: #112280325 |
|Germany Don't drink as root!  ESC:wq

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




What's up with NNTP?

2009-03-14 Thread Gunnar Hjalmarsson
The NNTP interface to this list (and possibly other @perl.org lists) 
seems not to work any longer. Does anybody know what the problem is? Is 
it a temporary thing, or has the service been permanently disabled?


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


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Error: Can't call method x without a package or object reference...

2009-03-14 Thread Chas. Owens
On Sat, Mar 14, 2009 at 08:28, M. Coiffure coiff...@gmx.at wrote:
 Hi all

 I'm getting this error on the following (test) script:

 Can't call method x without a package or object reference at test.pl line 
 12 ENT line 1
snip
        $ent{$1} = \x{$2};
snip

The \x{hex value} literal syntax only works in side of strings and
only works with constant values (i.e. \x{00E1} never
\x{$somevalue}).  The way you convert numbers to characters in Perl
is the chr function*.  It takes an offset into the character set (In
this case UNICODE) and returns the character at that offset.  You have
one other issue, that offset is specified in decimal, not hexadecimal,
so you will need to convert the hexadecimal value 00E1 into its
decimal value 225.  Happily there is a function in Perl to do this:
hex**.  So instead of saying

$ent{$1} = \x{$2};

you should say

$ent{$1} = chr hex $2;

Some other things to watch for:
* bareword filehandles have many issues, use lexical filehandles instead
* the two argument version of open has issues, use the three
argument version instead
* why use $1 and $2 when you store the captures directly to scalars
* never try to use values gotten from a regex without testing to
see if the regex was successful

Here is how I would write the code:


#!/usr/bin/perl

use strict;
use warnings;

open my $ent, , entities.txt
or die cannot read entities: $!;

my %ent;
while ($ent) {
#skip any lines that don't match what we want
next unless my ($entity, $ordinal) = /^(\S+)\s+(\S+)$/;
$ent{$entity} = chr hex $ordinal;
}

print $_ = $ent{$_}\n for sort keys %ent;


* http://perldoc.perl.org/functions/chr.html
** http://perldoc.perl.org/functions/hex.html

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Assigning an array to a dereferenced hash slice - syntax!

2009-03-14 Thread Chas. Owens
On Sat, Mar 14, 2009 at 01:06, Chap Harrison c...@pobox.com wrote:

 On Mar 13, 2009, at 7:52 AM, Jenda Krynicky wrote:

 That's prettymuch it, except that it's not an array of aliases, but
 LIST of aliases. The difference is subtle, but important.
 See http://perldoc.perl.org/perlfaq4.html#What-is-the-difference-
 between-a-list-and-an-array%3f and
 http://www.perlmonks.org/?node_id=130861

 Thanks - I've read the FAQ several times in the past without really getting
 it, but the perlmonks thread looks promising.  It IS subtle, all right.  :-/
snip

The eureka moment for me was when I realized that lists are a data
type (like number or string) and arrays and hashes are containers that
hold that data type.  Once you realize that it is easy to see why they
have different behaviours.


-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How to use a configuration file?

2009-03-14 Thread Chas. Owens
On Sat, Mar 14, 2009 at 08:41, Michael Renner michael.ren...@gmx.de wrote:
 Moin,
snip
 I want to get some of these values (remoteProxy, the port and the IP address
 and some things more) from a configuration file. What is a good way to do
 this? What is a good format for this file? Human readable and easy to parse?
snip

I like YAML*, it is human readable, cross language, and can handle
almost any data structure you need to store.  I use YAML::Syck** in
Perl to read it.

* http://en.wikipedia.org/wiki/Yaml
** http://search.cpan.org/dist/YAML-Syck/lib/YAML/Syck.pm

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: What's up with NNTP?

2009-03-14 Thread Randal L. Schwartz
 Gunnar == Gunnar Hjalmarsson nore...@gunnar.cc writes:

Gunnar The NNTP interface to this list (and possibly other @perl.org lists) 
seems not
Gunnar to work any longer. Does anybody know what the problem is? Is it a 
temporary
Gunnar thing, or has the service been permanently disabled?

The NNTP interface is how I read your message, and how I posted
this reply, and I've changed nothing.

Perhaps it was broken for a while, and is now working again.  Maybe it was
during the recent perl.org got deregistered fiasco?

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
mer...@stonehenge.com URL:http://www.stonehenge.com/merlyn/
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Can anyone comment on Sams Teach Yourself Perl in 21 Days ?

2009-03-14 Thread Shlomi Fish
On Saturday 14 March 2009 08:34:56 Raymond Wan wrote:
 Hi Shlomi,

 Shlomi Fish wrote:
  Yes, those or Beginning Perl ( http://www.perl.org/books/beginning-perl/
  ) would be my choice too. I admit I haven't read them, but I'm judging
  them based on reputation.
 
  However, my point was that my pupil found this book in a library and
  borrowed it (which didn't cost her anything), and I can either tell her
  that it's OK to read it and learn from it, or that she should print or
  buy (depending on her preferences) a different book.

 I think the consensus seems to be that if your student had asked you for a
 book suggestion, this one might not have many people's choices.  :-)  But
 as a teacher, I think you should use the learn-it-my-way card as rarely
 as possible.  I, for one, prefer books over web pages and perldoc since I
 prefer to read on paper than on a screen (printing's close...but not quite
 the same...)

 If your pupil has chosen this book from the library all on her own, I think
 you should let her be and wait to see if she says, I don't understand this
 chapter since it gives very little details  To this, you open your bag
 and answer, Funny you should ask because I have another book here with
 the answer you need...  :-)


Thanks for your advice. I guess you're right.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Funny Anti-Terrorism Story - http://xrl.us/bjn7t

God gave us two eyes and ten fingers so we will type five times as much as we
read.


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How to use a configuration file?

2009-03-14 Thread Octavian Râşniţă

From: Chas. Owens chas.ow...@gmail.com
I want to get some of these values (remoteProxy, the port and the IP 
address

and some things more) from a configuration file. What is a good way to do
this? What is a good format for this file? Human readable and easy to 
parse?

snip

I like YAML*, it is human readable, cross language, and can handle
almost any data structure you need to store.  I use YAML::Syck** in
Perl to read it.


Like the Captchas that offer just images, YAML is human readable just for 
the humans that can see. It is very hard to read by the blind though.


It is also hard to use it in POD documentations because the POD indents the 
text and in some cases in HTML pages also.


Config::Any module allows using more configuration formats, including the 
pretty well known Apache style configuration (which is offered by 
Config::General module).


Octavian



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: What's up with NNTP?

2009-03-14 Thread Octavian Râsnita

From: Randal L. Schwartz mer...@stonehenge.com

Gunnar == Gunnar Hjalmarsson nore...@gunnar.cc writes:


Gunnar The NNTP interface to this list (and possibly other @perl.org 
lists) seems not
Gunnar to work any longer. Does anybody know what the problem is? Is it a 
temporary

Gunnar thing, or has the service been permanently disabled?

The NNTP interface is how I read your message, and how I posted
this reply, and I've changed nothing.

Perhaps it was broken for a while, and is now working again.  Maybe it was
during the recent perl.org got deregistered fiasco?

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 
0095

mer...@stonehenge.com URL:http://www.stonehenge.com/merlyn/
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside 
discussion




I've seen that the IRC server seems to not be working also.

ping irc.perl.org
Pinging g.irc.perl.org [217.168.150.167] with 32 bytes of data:
Request timed out.

I've also tried to get the list of channels with an IRC client, without 
success...


Octavian


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: What's up with NNTP?

2009-03-14 Thread rahed
Gunnar Hjalmarsson nore...@gunnar.cc writes:

 The NNTP interface to this list (and possibly other @perl.org lists)
 seems not to work any longer. Does anybody know what the problem is?
 Is it a temporary thing, or has the service been permanently disabled?

I don't know why but bear in mind that this server has reaction times
larger than others, up to tens of seconds.

-- 
Radek


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: What's up with NNTP?

2009-03-14 Thread Gunnar Hjalmarsson

Randal L. Schwartz wrote:

Gunnar == Gunnar Hjalmarsson nore...@gunnar.cc writes:


Gunnar The NNTP interface to this list (and possibly other @perl.org lists) 
seems not
Gunnar to work any longer. Does anybody know what the problem is? Is it a 
temporary
Gunnar thing, or has the service been permanently disabled?

The NNTP interface is how I read your message, and how I posted 
this reply, and I've changed nothing.


Thanks, then it's probably something on my end; I just can't figure out 
what it would be. I'm using Thunderbird, and suddenly it stopped 
downloading new messages from perl.beginners (and I hadn't changed 
anything), while it keeps downloading messages from e.g. 
comp.lang.perl.misc.


Perhaps it was broken for a while, and is now working again.  Maybe it was 
during the recent perl.org got deregistered fiasco?


Unfortunately not. I tried again a couple of minutes ago; nothing 
downloaded. :(


Well, I'll stick to emails for the time being.

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


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Late interpolation of a scalar variable inside a string

2009-03-14 Thread Chap Harrison
I want to compute a file pathname based on a template at runtime,  
when I know the value of a variable that the template uses.


In other words, the template for the path name looks like this...

/foo/bar/$project/here

...and I want to evaluate this expression once I have set the value of  
$project.


Here's what I've got:

#!/usr/bin/perl
use strict;
use warnings;

my $project = my-project;
my $all_projects_path = '/foo/bar/$project/here';
my $project_path;
my $temp = '$project_path  = $all_projects_path';

print \$project is: $project\n;
print \$all_projects_path is: $all_projects_path\n;
print Evaluating: $temp\n;
eval $temp;
print \$project_path is now: $project_path\n;

-

Output:

$ doit
$project is: my-project
$all_projects_path is: /foo/bar/$project/here
Evaluating: $project_path  = $all_projects_path
$project_path is now: /foo/bar/$project/here

-

The variable $project wasn't interpolated.
I've read perldoc on 'eval', and googled a bit, but no joy.
I know this is going to be a forehead-slapper, but what have I done  
wrong?


Thank,
Chap

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: What's up with NNTP?

2009-03-14 Thread Chas. Owens
On Sat, Mar 14, 2009 at 17:49, Gunnar Hjalmarsson nore...@gunnar.cc wrote:
snip
 Unfortunately not. I tried again a couple of minutes ago; nothing
 downloaded. :(

 Well, I'll stick to emails for the time being.
snip

Does the following work?

telnet nntp.perl.org 119

If it does try typing the following commands in:

group perl.beginners
stat 106808
body

You should see the message I am replying to.  If you do, then the
problem is probably with Thunderbird.

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Late interpolation of a scalar variable inside a string

2009-03-14 Thread Chas. Owens
On Sat, Mar 14, 2009 at 18:04, Chap Harrison c...@pobox.com wrote:
 I want to compute a file pathname based on a template at runtime, when I
 know the value of a variable that the template uses.

 In other words, the template for the path name looks like this...

 /foo/bar/$project/here
snip
 I've read perldoc on 'eval', and googled a bit, but no joy.
snip

String eval is bad mojo.  What you really need is either a template
module* (if your needs are very complex) or a simple substitution (if
you needs are simple).

#!/usr/bin/perl

use strict;
use warnings;

my $project_path_template = /foo/bar/{PROJECT}/here;

for my $project (qw/project1 project2 project3/) {
(my $project_path = $project_path_template) =~ s/\{PROJECT\}/$project/;
print the project path is $project_path\n;
}

* Search CPAN for template modules until you find one with the
features you want, this one looks fairly close to what you want:
http://search.cpan.org/dist/Text-Template/lib/Text/Template.pm

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Late interpolation of a scalar variable inside a string

2009-03-14 Thread John W. Krahn

Chap Harrison wrote:
I want to compute a file pathname based on a template at runtime, when 
I know the value of a variable that the template uses.


In other words, the template for the path name looks like this...

/foo/bar/$project/here

...and I want to evaluate this expression once I have set the value of 
$project.


Here's what I've got:

#!/usr/bin/perl
use strict;
use warnings;

my $project = my-project;
my $all_projects_path = '/foo/bar/$project/here';
my $project_path;
my $temp = '$project_path  = $all_projects_path';

print \$project is: $project\n;
print \$all_projects_path is: $all_projects_path\n;
print Evaluating: $temp\n;
eval $temp;
print \$project_path is now: $project_path\n;

-

Output:

$ doit
$project is: my-project
$all_projects_path is: /foo/bar/$project/here
Evaluating: $project_path  = $all_projects_path
$project_path is now: /foo/bar/$project/here

-

The variable $project wasn't interpolated.
I've read perldoc on 'eval', and googled a bit, but no joy.
I know this is going to be a forehead-slapper, but what have I done wrong?


Why not use sprintf() and '/foo/bar/%s/here' as the template:

my $project = my-project;
my $all_projects_path = '/foo/bar/%s/here';
my $project_path = sprintf $all_projects_path, $project;




John
--
Those people who think they know everything are a great
annoyance to those of us who do.-- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: What's up with NNTP?

2009-03-14 Thread Gunnar Hjalmarsson

Chas. Owens wrote:

On Sat, Mar 14, 2009 at 17:49, Gunnar Hjalmarsson nore...@gunnar.cc wrote:
snip

Unfortunately not. I tried again a couple of minutes ago; nothing
downloaded. :(

Well, I'll stick to emails for the time being.

snip

Does the following work?

telnet nntp.perl.org 119

If it does try typing the following commands in:

group perl.beginners
stat 106808
body

You should see the message I am replying to.


Yes, it worked, and I saw the message.


If you do, then the problem is probably with Thunderbird.


Yeah, probably. Thanks, Chas, for the help.

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


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Late interpolation of a scalar variable inside a string

2009-03-14 Thread Chap Harrison


On Mar 14, 2009, at 5:24 PM, John W. Krahn wrote:


Why not use sprintf() and '/foo/bar/%s/here' as the template:


On Mar 14, 2009, at 5:19 PM, Chas. Owens wrote:


* Search CPAN for template modules until you find one with the
features you want, this one looks fairly close to what you want:
http://search.cpan.org/dist/Text-Template/lib/Text/Template.pm



Thank you both.  Good to know about Template.pm.  Also good to know  
the eval method was inadvisable.  Since my needs are so simple, I went  
with the sprintf solution - simplest of all.


Chap

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




I'm sure this is a common question, but I can't find the solution.

2009-03-14 Thread Ron Smith

Hello all,

How do you print elements of an array, each on its own line, in a Windows' 
console?

I'm doing the following:

E:\My Documentsperl -e use ExtUtils::Installed; my $inst = 
ExtUtils::Installed-new(); my @modules = $inst-modules(); print @modules

it returns:

Archive::TarArchive::ZipArray::CompareAutoLoaderCPANCPAN::ChecksumsCPAN::DistnameInfo
 ...etc.

I need:

Archive::Tar
Archive::Zip
Array::CompareAutoLoaderCPAN
CPAN::Checksums
CPAN::DistnameInfo ...etc.

I tried \n, '\n' and a 'foreach' loop, but nothing I do seems to work. ..any 
suggestions?


Ron Smith
geeksatla...@yahoo.com

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: I'm sure this is a common question, but I can't find the solution.

2009-03-14 Thread John W. Krahn

Ron Smith wrote:

Hello all,


Hello,


How do you print elements of an array, each on its own line, in a Windows' 
console?

I'm doing the following:

E:\My Documentsperl -e use ExtUtils::Installed; my $inst = 
ExtUtils::Installed-new(); my @modules = $inst-modules(); print @modules

it returns:

Archive::TarArchive::ZipArray::CompareAutoLoaderCPANCPAN::ChecksumsCPAN::DistnameInfo
 ...etc.

I need:

Archive::Tar
Archive::Zip
Array::CompareAutoLoaderCPAN
CPAN::Checksums
CPAN::DistnameInfo ...etc.

I tried \n, '\n' and a 'foreach' loop, but nothing I do seems to work. ..any 
suggestions?


I don't have Windows to test this on but this should work:

perl -MExtUtils::Installed -lemy $inst = ExtUtils::Installed-new(); 
print for $inst-modules()




John
--
Those people who think they know everything are a great
annoyance to those of us who do.-- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: I'm sure this is a common question, but I can't find the solution.

2009-03-14 Thread David Christensen
Ron Smith wrote:
 How do you print elements of an array, each on its own line, in a
 Windows' console?

This works under Cygwin:

perl -e 'use ExtUtils::Installed; my $inst =
ExtUtils::Installed-new(); my @modules = $inst-modules(); print join
\n, @modules'

Notes:

1.  Single quotes around the script to be evaluated; double quotes
around the newline escape.

2.  Use of join() to put a newline between each element of the array.


For some good Perl books, see this message:

http://www.mail-archive.com/beginners@perl.org/msg99864.html


HTH,

David


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/