My Perl for Newbies lectures

2001-06-26 Thread Shlomi Fish


I have prepared two lectures that introduce Perl for Perl Beginners as
part of a series I gave to the Haifa Linux Club. The full material of the
lectures (explanation, examples and all) is available online at:

http://vipe.technion.ac.il/~shlomif/lecture/Perl/Newbies/

The license is Public Domain.

The lecture cover all the material from basic perl expressions and
constructs up to and including regular expressions, references and the
perl pipeline (sort, map, grep and friends).

I would be happy if http://learn.perl.org/ will link to it or mirror it.

Regards,

Shlomi Fish

--
Shlomi Fish[EMAIL PROTECTED] 
Home Page: http://t2.technion.ac.il/~shlomif/
Home E-mail:   [EMAIL PROTECTED]

A more experienced programmer does not make less bugs. He just realizes
what went wrong more quickly.




Re: VARIABLES

2004-06-18 Thread Shlomi Fish
On Fri, 18 Jun 2004 [EMAIL PROTECTED] wrote:

 All,

 Does perl have built in variable names such as in awk?  Here are the ones
 in awk
 I know perl uses ARGV, but what about:

 ARGC # of command lines arguments

For that you use scalar(@ARGV).

 FILENAME name of current input file

That's $ARGV.

 FNR record number in current file

I think it's $..

 FS controls the input field separator

Well, that's specified using -F if you use the -a and -n or -p (perldoc
perlrun for details). Other than that, you can split a string any way you
want using the split function:

@F = (split/myregex/, $string);

 NF number of fields in current record

scalar(@F) in the above example.

 NR number of records read so far

What's the difference between that and FR?

 OFMT output format for numbers

$#, but see perldoc perlvar about it.

 OFS out filed separator

$, (or $OFS or $OUTPUT_FIELD_SEPARATOR in English).

 ORS output record separtor

$\ (or $ORS or $OUTPUT_RECORD_SEPARATOR).

 RLENGTH lenght of string matched by match function

There are many variables for getting output out of the match function. You
can use the length() function on them.

 RS controls the input record separator

What does it do?

 SUBSEP subscript separtor


Again, I'm not so familiar with awk so I don't know what does it do.

In any case, the Perl philosophy (for most serious things, at least) is
different than awk's. You write your script as a full-fledged program,
where you can use explicit constructs to work with the input and produce
the output. While Perl can be invoked to behave more like awk, it is not
necessarily so.

Regards,

Shlomi Fish

 thanks again!

 Derek B. Smith
 OhioHealth IT
 UNIX / TSM / EDM Teams
 614-566-4145




--
Shlomi Fish[EMAIL PROTECTED]
Home Page: http://shlomif.il.eu.org/

You are banished! You are banished! You are banished!

Hey? I'm just kidding!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Documentation on Usin with.......

2003-06-06 Thread Shlomi Fish
On Thu, 5 Jun 2003, Saurabh Singhvi wrote:

 well if somebody can tell me how to use perl with my
 website. the main thing i want to use is password
 function. Any helps??


Do you know Perl at all?

If so, you can find a tutorial for CGI programming here:

http://perl-begin.berlios.de/cgi-bin/chiq_chaq/chiq.pl?CGI_Getting_Started

If not, you can consult one of these tutorials for learning Perl:

http://perl-begin.berlios.de/tutorials/

Contact me if you need more help or information.

Regards,

Shlomi Fish

--
Shlomi Fish[EMAIL PROTECTED]
Home Page: http://t2.technion.ac.il/~shlomif/

An apple a day will keep a doctor away. Two apples a day will keep two
doctors away.

Falk Fish

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Reading string 00 from a file

2003-06-03 Thread Shlomi Fish
On Mon, 2 Jun 2003, Sockmonkey wrote:

 My program writes string to a text file and reads them back in. I do it like
 this:

 print OUT $str\n;

 and then

 $str = IN;
 chomp($str);

 The problem is one of my strings is 00. It gets written out fine, but gets
 read in as 0. How can I stop this from happening?


Perl has no problem reading a string like this. Are you sure you don't add
it with 0 or do something else numeric in between? It works for me.tm

Regards,

Shlomi Fish

 Thx







--
Shlomi Fish[EMAIL PROTECTED]
Home Page: http://t2.technion.ac.il/~shlomif/

An apple a day will keep a doctor away. Two apples a day will keep two
doctors away.

Falk Fish

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Perl - Web Development

2003-06-05 Thread Shlomi Fish
On Wed, 4 Jun 2003, Paul Kraus wrote:

 This may be asking for biased opinions but here goes anyways...

 Is perl still a good choice for the web.

Yes. Perl is a very good choice from all aspects.

 For instance I need to setup a
 couple sites that are going to be running on IIS. Is perl still a good
 choice for speed ect...


If you're running it on IIS, you can try using ActiveState's PerlEx:

http://www.activestate.com/Products/PerlEx/

This will make Perl very fast, in a comparable speed to Apache's mod_perl.

 Or should I look at the newer technologies such as vb.net on for that
 matter c#.


I don't know too much about VB.Net C#, or ASP.Net so I cannot comment. I
know ASP.Net has a problem in which you need to explicitly deallocate all
the allocated resources, or else they'll leak.

 I know perl and the idea of being able to use the same language in
 everything I do would be great but am I going to take a hit on
 performance. Can it be embedded into html? What is mason does that run
 on IIS.


Mason can run on top of IIS by means of its CGI emulation. However,
there's also Perl ASP, which is a native IIS technology. They are similar
in spirit but Mason is more powerful.

 I use perl now for admin task and reports(yes perl is good for reporting
 ;) ). I can use the same tools I design on my Linux, UNIX, and window$
 machines. But is it wise to do so for the web. CGI has been around for a
 long time and there are a lot of new emerging technologies.


Perl can utilize other technologies besides CGI using much the same
interface. You can run Perl on top of mod_perl, or PerlEx, or something
similar. They are faster than CGI.

 Rule of thumb is choose the best tool for the job. So all input is
 appreciated.


I believe Perl is still the best tool for the job of web-publishing.

Regards,

Shlomi Fish

 PK






--
Shlomi Fish[EMAIL PROTECTED]
Home Page: http://t2.technion.ac.il/~shlomif/

An apple a day will keep a doctor away. Two apples a day will keep two
doctors away.

Falk Fish

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Changing UID/GID

2003-06-11 Thread Shlomi Fish
On Wed, 11 Jun 2003, tsg wrote:

 Hi everybody!

 Could You pease point me where I can get answers following questions:
 1. How can I now the UID of the user who started perl-script?

Try $ (or $UID or $REAL_USER_ID with use English) for the real user id.

Try $ or $EUID or $EFFECTIVE_USER_ID with use English for the effective
user ID.

 2. How can I change UID/GID the script is running under. I need to start
 script with root privilegies and when drop them to apache.apache.


perldoc POSIX.

(and search for setuid).

Regards,

Shlomi Fish

 Thanks in advance for help.
 Best regards
 Sergios





--
Shlomi Fish[EMAIL PROTECTED]
Home Page: http://t2.technion.ac.il/~shlomif/

An apple a day will keep a doctor away. Two apples a day will keep two
doctors away.

Falk Fish

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: scalar to list conversion

2003-06-28 Thread Shlomi Fish
On Sat, 28 Jun 2003, Ling F. Zhang wrote:

 say I have a string scalar $s
 I would like to convert it @s in such a way that qw
 would do it...
 i.e.
 if $s = rabbit hole\t goes\tall the way\n
 then
 @s = (rabbit,hole,goes,all,the,way\n)


@s = (split /\t/, $s);

Hope it helps.

Regards,

Shlomi Fish

 notice that I preserved the \n at the end, but I
 would settle for a solution that doesn't preserve
 it...thanx


 __
 Do you Yahoo!?
 SBC Yahoo! DSL - Now only $29.95 per month!
 http://sbc.yahoo.com





--
Shlomi Fish[EMAIL PROTECTED]
Home Page: http://t2.technion.ac.il/~shlomif/

An apple a day will keep a doctor away. Two apples a day will keep two
doctors away.

Falk Fish

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: file io and html

2003-06-28 Thread Shlomi Fish
On Sat, 28 Jun 2003, fuzzy wrote:

 i need to know how do file i/o.

 i know c, c++, php, 5 different vb, so i'm not new to programming, just
 to perl.

 i'm going to be send stuff to this script using a html form via ACTION=,
 so i need to know how to pull them in, smush them into a string in a
 format and write it (in append mode) to a file. i know how to do this in
 php, but php runs as 'nobody' and i dont want to leave this file with
 world write access

 here's the final format i need
 00-00-00,00:00,file.ext,title with spaces in quotes

 the first part is a date
 second is a time
 3rd is a file name
 fourth is a string in quotes, the quotes are important

 in php i would use
 $outout = sprintf(%s,%s,%s,\%s\, $date, $time, $file, $title);


This will work in Perl as well.

To write it to a file, use the following code:

open O, myfile.txt; ##  is for append
print O $outout;
close(O);

For more information refer here:

http://vipe.technion.ac.il/~shlomif/lecture/Perl/Newbies/lecture2/files/
http://vipe.technion.ac.il/~shlomif/lecture/Perl/Newbies/lecture4/system-funcs/
perldoc perlopentut

Regards,

Shlomi Fish

 someone please help

 -fuzzy






--
Shlomi Fish[EMAIL PROTECTED]
Home Page: http://t2.technion.ac.il/~shlomif/

An apple a day will keep a doctor away. Two apples a day will keep two
doctors away.

Falk Fish

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Perl Vs ...

2003-09-22 Thread Shlomi Fish
On Sun, 21 Sep 2003, Paul Kraus wrote:

 Perl was pretty much my first language. Not counting Business Basic and same
 old Pascal from high school. The more I learn the more I see that perl can
 handle just about anything I want to do. How do you go about deciding if you
 should use another tool such as C++ over perl? I am thinking about learning
 another language and trying to decide what language would be best to learn.
 To expand my skill set. Suggestions, Ideas, Book Recommendations?


I would suggest learning several things:

1. C is a good language to know as it is very close to machine language
and gives you important insights about programming and computers
architecture. I can't really recommend a book because I first learned it
from the Turbo C++ 3.0 manual, but I heard KR's or A Book on C are
good.

2. The book Structure and Interpretation of Computer Programs is very
interesting and enlightening. It is available online here:

http://mitpress.mit.edu/sicp/

It teaches programming through Scheme, a dialect of LISP that is very
similar to Perl. I fully understood closures after reading this book.
I also suggest doing some of the exercises in the book, because they give
a whole new dimension to learning it.

3. After you tackled Scheme and lexical scoping, then Lambda Calculus is
an extra useful enlightenment. It's a very minimalistic language that is
actually quite usable. I learned LC from a book I found about it in the
library, but I wrote a lecture about it with detailed slides:

http://vipe.technion.ac.il/~shlomif/lecture/Lambda-Calculus/

4. I found learning Haskell to be quite enlightening and I still like to
experiment with it on occasions. I learned it from the so-called Gentle
Introduction to Haskell:

http://www.haskell.org/tutorial/

O'Caml is a similar language that is more usable, but less elegant.

5. Matlab is a very nice tool for making engineering calculations. If you
deal with these kind of things, it is useful to know. Perl has an
equivalent toolkit in PDL - the Perl data language.

6. Paul Graham's On Lisp book is also very nice.

http://www.paulgraham.com/onlisp.html

Available for free download online.

---

Regards,

Shlomi Fish





 Paul Kraus





--
Shlomi Fish[EMAIL PROTECTED]
Home Page: http://t2.technion.ac.il/~shlomif/

An apple a day will keep a doctor away. Two apples a day will keep two
doctors away.

Falk Fish

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Perl Beginners Portals

2003-09-29 Thread Shlomi Fish

Hi all!

I believe learn.perl.org is very lacking:

1. Its design is ugly.

2. No links to many important online resources such as tutorials, books,
article collections, mailing lists, web forums, etc.

3. Concentration on commercial books.

4. No source code for the site is available and [EMAIL PROTECTED]
are not responsive.

5. Pretty much unmaintained for a long time.

Still, it has a pretty good Google popularity.

I did my best to resolve the problems inherent in it by setting up
http://perl-begin.berlios.de/. The site could still use some work, but
it's still better than learn.perl.org. Nevertheless, I would want to see
learn.perl.org becoming better.

When I started the perl-begin effort the beginners-workers decided I will
do a re-design of the learn.perl.org. After I was more or less finished, I
did not receive any reply when I tried to contact them. So I had no choice
but to set up my own site.

What are your opinions about the two sites? How can we make learn.perl.org
better?

Regards,

Shlomi Fish




--
Shlomi Fish[EMAIL PROTECTED]
Home Page: http://t2.technion.ac.il/~shlomif/

An apple a day will keep a doctor away. Two apples a day will keep two
doctors away.

Falk Fish

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Perl Beginners Portals

2003-10-02 Thread Shlomi Fish
On Thu, 2 Oct 2003, Todd Wade wrote:


 R. Joseph Newton [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
  Todd Wade wrote:
 
   I'm willing to pester the site owners to let you do the site. But it
 will
   probably take more than just you and I. The lack of responses to your OP
   might indicate the amount of help the rest of the group is willing to
   contribute.
 
  I think you may be misinterpreting the silence.  Although the OP makes a
 very
  positive offer of his efforts, he does not communicte it very well.
  Unfortunately, he starts off with a litany of what is wrong with...
 which
  tends to turn people away before they get to the proposal itself.

 I was. I got a couple emails referring me to the archive of the OP's thread
 in perl.advocacy. There were many suggestions made by him to fix things that
 were not broken. If I had read that thread, I wouldve ignored the post also.
 As I was replying to it, I was thinking of something simple like a faq of
 faqs. Now I understand he what is proposing is just too grandiose and
 unimplementable for the resources we have available. Im _glad_ nobody else
 responded so it didn't start over again.


What I'm suggesting is not too grandoise or unimplementable. In any case,
what I suggested regarding the Perl world in general, has little to do
with learn.perl.org vs. perl-begin.berlios.de.

I find learn.perl.org inadequate as the main community portal for people
who are trying to learn Perl. I have constructed perl-begin.berlios.de
which is much better. I am willing to perform some work on learn.perl.org
to make it better. However, I cannot because I don't have access to its
source code, and its maintainers have not been responsive lately.

The other suggestions in regard to the Perl world in general are not
directly related to my recent post to this list.

And if you think my suggestions are grandoise, you have to take into
account that I prepared perl-begin all by myself, with some input
by other people (which I still had to input into the site). And I am a
university student and have many other endeavours as well.

[1]

  FWIW, the core group of helpers posting here is generally hroic in its
 patience
  and energy, with an emphasis on the former.  While I cetainly agree that
 new
  members should read the FAQ and at least skim the archives before asking a
  repetitive question, that is somewhat to be expected on a list targeted
 toward
  beginners.  On this mailing list, we expect a certain amount of
 repitition.
  Some of us may remind posters that they should read the archives and other
  traffic on the list, but that is usually not the top priority.
 

 Oh I agree. I dont mind the repetitive posting. As you say, this list is for
 perl curious people to ask anything they want ( about perl ) without being
 criticized for it. Although I have noticed a small few taking advantage of
 that fact. Just a small few, though. Not near enough to affect me.


I agree here too. One cannot expect beginners to read the FAQ or skim
through the archives, or search Google. They may not be aware of
netiquette as more experienced people are. I think having one global list
for all newbie questions is not such a good idea, because the volume is
quite overwhelming. However, in any such list, one should be prepared to
answer as many of these questions as possible, times and again.

That's also a reason in support of having several separate mailing
lists: you get to hear the same old question less.

Regards,

Shlomi Fish

[1] - and please - how hard it is to designate #perl as the channel for
newbie discussions and to move the advanced discussions and talk to
#perlcafe? Not hard at all.



--
Shlomi Fish[EMAIL PROTECTED]
Home Page: http://t2.technion.ac.il/~shlomif/

An apple a day will keep a doctor away. Two apples a day will keep two
doctors away.

Falk Fish

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



New Website for Perl Beginners: perlmeme.org

2005-10-02 Thread Shlomi Fish
Hi good people,

there's a new web-site for Perl beginners - perlmeme.org - 

http://perlmeme.org/

It has Howto's, Tutorials and FAQs for Perl beginners - freely available and 
freely usable. Its mission ( http://perlmeme.org/start_here/index.html ) is:


It's lots of ideas that together define why Perl is so different. 

It is the idea that there should be more that one way to do it, the idea 
that a language should make easy jobs easy and hard jobs possible, the idea 
that laziness, patience and hubris are virtues (for a programer). 

 Perl itself is evolving at a rate unlike any other programming language. 
Those of us who use it for a living are excited by how powerful and 
expressive the language is and how close to the 'problem set' it is. With the 
development of Perl 6 well underway, the language is set to expand and take 
on even more functionality not found anywhere else. In our opinion, this 
makes it the language of choice for solving many of the software problems of 
the future.


I have already contributed some code, text and ideas to perlmeme.org, but we 
could always use more help. If you have a document to contribute (even if 
it's already written), can provide feedback on the site, or can help in any 
other way, feel free to visit our developers' web-site:

http://perlmeme-org.sourceforge.net/

Regards,

Shlomi Fish

-
Shlomi Fish  [EMAIL PROTECTED]
Homepage:http://www.shlomifish.org/

95% of the programmers consider 95% of the code they did not write, in the
bottom 5%.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: New Website for Perl Beginners: perlmeme.org

2005-10-03 Thread Shlomi Fish
Hi Randal!

Thank you very much for your commentary. Now for my comments.

On Sunday 02 October 2005 14:17, Randal L. Schwartz wrote:
  Shlomi == Shlomi Fish [EMAIL PROTECTED] writes:

 Shlomi Hi good people,
 Shlomi there's a new web-site for Perl beginners - perlmeme.org -

 Shlomi http://perlmeme.org/

 Unless it's hidden, I'm not finding any obvious link there to the
 defacto standard location for Perl beginners, http://learn.perl.org.

That may be possible. Perlmeme.org is still under constant development, and 
many important content and links are missing. As far as I'm concerned a link 
to learn.perl.org should be added very soon, at the very least because it 
also contains some online books including the first edition of Beginning 
Perl. 

 I think this represents broken integrity on your part, since you
 appear to be trying to replace learn.perl.org, not supplement it, so
 you're attempting to fracture the community, not enhance it.

Just a note: while being a perlmeme.org contributor I am by no means am 
leading this project. I'm sorry if I gave this impression, but my intention 
in the original message was to just publicize perlmeme.org. I believe Simon 
Taylor (CCed to this message) and other collaborators of his, are more of an 
authority as far as perlmeme.org is concerned. 

I believe they'll gladly accept any good patches to the site, either from 
Randal or from someone else. 


 If you add a prominent link to learn.perl.org, I will withdraw my
 complaint.

OK. Just note that perlmeme.org is a very different site that learn.perl.org 
(and to some extent perl-begin.berlios.de) and they both fill different 
niches. I'm still looking for more contributors for perl-begin, including 
people who can populate its wiki with useful content:

http://perl-begin.berlios.de/Wiki/mediawiki/index.php/Main_Page

Thanks again!

Regards,

Shlomi Fish

-
Shlomi Fish  [EMAIL PROTECTED]
Homepage:http://www.shlomifish.org/

95% of the programmers consider 95% of the code they did not write, in the
bottom 5%.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Module for Country/Country Codes Lists

2004-02-04 Thread Shlomi Fish

Hi!

My name is Shlomi Fish and I am a co-developer of the WWW::Form module:

http://search.cpan.org/~bschmau/WWW-Form-1.13/

Benjamin Schmaus (WWW::Form's main developer) and I decided it would be a
good idea for the module or an extension of it to provide common form
controls like a country list or a U.S. states list.

To do so we need a module that returns a country list. Ideally what we
would like is for it to return a refernece to a hash of country codes (US,
IL, UK, RU, etc.) that each map to a contry name (United States, Israel,
United Kingdom, Russia). Or alternatively, a similar interface with
similar capabilites.

We enumberated our needs here:

http://benschmaus.com/cgi-bin/twiki/view/Main/WwwFormCountryList

So, is there a good module for doing that on CPAN that is also actively
maintained and updated?

Regards,

Shlomi Fish


--
Shlomi Fish[EMAIL PROTECTED]
Home Page: http://t2.technion.ac.il/~shlomif/

You are banished! You are banished! You are banished!

Hey? I'm just kidding!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Module for Country/Country Codes Lists

2004-02-06 Thread Shlomi Fish
On Wed, 4 Feb 2004, Randy W. Sims wrote:

 On 2/4/2004 11:36 AM, Shlomi Fish wrote:

  Hi!
 
  My name is Shlomi Fish and I am a co-developer of the WWW::Form module:
 
  http://search.cpan.org/~bschmau/WWW-Form-1.13/
 
  Benjamin Schmaus (WWW::Form's main developer) and I decided it would be a
  good idea for the module or an extension of it to provide common form
  controls like a country list or a U.S. states list.
 
  To do so we need a module that returns a country list. Ideally what we
  would like is for it to return a refernece to a hash of country codes (US,
  IL, UK, RU, etc.) that each map to a contry name (United States, Israel,
  United Kingdom, Russia). Or alternatively, a similar interface with
  similar capabilites.
 
  We enumberated our needs here:
 
  http://benschmaus.com/cgi-bin/twiki/view/Main/WwwFormCountryList
 
  So, is there a good module for doing that on CPAN that is also actively
  maintained and updated?

 You should be able to build on Locale::Country  Locale::SubCountry.


Thanks, we'll take a look.

Regards,

Shlomi Fish

 Regards,
 Randy.





--
Shlomi Fish[EMAIL PROTECTED]
Home Page: http://t2.technion.ac.il/~shlomif/

You are banished! You are banished! You are banished!

Hey? I'm just kidding!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




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

2009-03-12 Thread Shlomi Fish
Hi all!

I've been tutoring someone in Perl 5, and as she wants to learn Perl from a 
paperware book, she borrowed the book Sams Teach Yourself Perl in 21 Days 
from her workplace's library, and started reading it. Now, all those in 21 
Days/in 24 hours/unleashed/for Dummies/etc. books tend to have a bad 
reputation among knowledgeable people, so I'd like to know how good this 
particular book is, so I won't have to undo the damage if it's bad.

If you've read it, can you comment how good did you find it?

Here's what I've found so far:

1. The book has a page on books.perl.org: http://books.perl.org/book/98 . 
There are no reviews, and it received an average rating of 2.2/5 from 6 votes. 
I also see that it has a second edition released in 2002.

2. The Amazon.com page is:

http://www.amazon.com/Sams-Teach-Yourself-Perl-Days/dp/0672320355

It received an average rating of 4 stars and mostly positive reviews.



So any comments on this book will be welcome.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Original Riddles - http://www.shlomifish.org/puzzles/

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: Can anyone comment on Sams Teach Yourself Perl in 21 Days ?

2009-03-13 Thread Shlomi Fish
Hi!

On Thursday 12 March 2009 18:52:05 Francisco Valladolid wrote:
 Hi

 On Thu, Mar 12, 2009 at 9:27 AM, Shlomi Fish shlo...@iglu.org.il wrote:
  Hi all!
 
  I've been tutoring someone in Perl 5, and as she wants to learn Perl from
  a paperware book, she borrowed the book Sams Teach Yourself Perl in 21
  Days from her workplace's library, and started reading it. Now, all
  those in 21 Days/in 24 hours/unleashed/for Dummies/etc. books
  tend to have a bad reputation among knowledgeable people, so I'd like to
  know how good this particular book is, so I won't have to undo the damage
  if it's bad.

 Never book is bad, it was writtent with a purpose, whenever in the
 world exists more good fine books.

Well, books that are misleading or contain dis-information or mis-information 
are bad, and may result in programmers that produce sloppy or even dangerous 
code. As such, they are bad. See, for example: http://xrl.us/bejfw7 .

 I never chose this series, such as 21 days, /Dummies/24 hrs./for busy
 people/ etc.

Neither do I. Of course, I normally try to learn new technologies from 
Internet resources, because I don't have a problem in reading long texts on 
the computer. I still read technical paper books, but it's for reading before 
going to bed.

 I think that you can choice the Learning Perl from Randal Schwartz or
 Elements of Programming with Perl (Manning Ed.)
 particularly are my favorite introductory books.

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.


  If you've read it, can you comment how good did you find it?

 No yet.


OK.

  Here's what I've found so far:
 
  1. The book has a page on books.perl.org: http://books.perl.org/book/98 .
  There are no reviews, and it received an average rating of 2.2/5 from 6
  votes. I also see that it has a second edition released in 2002.
 
  2. The Amazon.com page is:
 
  http://www.amazon.com/Sams-Teach-Yourself-Perl-Days/dp/0672320355
 
  It received an average rating of 4 stars and mostly positive reviews.

 Perl books are well know in the Perl community, please check the list
 archives for a good book recommendation.

I don't have a problem with finding a good book. But I just want to see if I 
should recommend her against the in 21 Days book.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
First stop for Perl beginners - http://perl-begin.org/

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: Can anyone comment on Sams Teach Yourself Perl in 21 Days ?

2009-03-13 Thread Shlomi Fish
Hi Raymond,

On Friday 13 March 2009 05:24:58 Raymond Wan wrote:
 Hi Shlomi,

 Shlomi Fish wrote:
  Hi all!
 
  I've been tutoring someone in Perl 5, and as she wants to learn Perl from
  a paperware book, she borrowed the book Sams Teach Yourself Perl in 21
  Days from her workplace's library, and started reading it. Now, all
  those in 21 Days/in 24 hours/unleashed/for Dummies/etc. books
  tend to have a bad reputation among knowledgeable people, so I'd like to
  know how good this particular book is, so I won't have to undo the damage
  if it's bad.

 I can't comment on this book in particular, but I did go through Sams
 Teach Yourself C++ in 21 Days.  I went through the book a long, long time
 ago and I thought this series was gone...surprised to just look on Amazon
 and see that it's up to a 5th edition.  *yikes*

 The book isn't bad and books like these or the Dummies series don't
 deserve the negative comments.  They aren't great, but they obviously sell
 and they sell because they satisfy a niche.  It's for the busy people or
 the ones who just want to have their hand held at first.  That niche would
 perhaps be not the people on this list who have chosen to use O'Reilly
 books, etc. (Learning Perl, etc.).  So, I doubt you're going to get any
 positive comments.


I see. Thanks for the comments.

 I think if the person you are tutoring has a computer science background
 (i.e., used other languages before), then she might find this book and this
 series a bit boring.  

Actually, she still has very little CS background.

 But otherwise, it's a good warm-up and if she finds
 she has a thirst for more Perl afterwards, then she might want to try
 another one like Learning Perl.

OK, thanks.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
First stop for Perl beginners - http://perl-begin.org/

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: Can anyone comment on Sams Teach Yourself Perl in 21 Days?

2009-03-13 Thread Shlomi Fish
Hi Safi!

On Friday 13 March 2009 17:44:16 Safi Newman wrote:
 Dear Shlomi,

 I tried posting this reply to the list yesterday, but am having some
 problems (I have emailed the list owner). In the meantime, I thought I
 would email you directly:

I see, thanks. Maybe it's because you sent an HTML-only email, that was more 
likely to be classified as spam. I also got the following SpamAssassin 
classification of it (which was not enough for it to end up in my spam folder, 
but still offending):

{{
X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on
telaviv1.shlomifish.org
X-Spam-Level: **
X-Spam-Status: No, score=2.3 required=5.0 tests=BAYES_50,HTML_MESSAGE,
HTML_MIME_NO_HTML_TAG,MIME_HTML_ONLY,RDNS_DYNAMIC,SPF_NEUTRAL,
UNPARSEABLE_RELAY autolearn=no version=3.2.5
}}



 As someone who is trying to teach herself Perl by using hardcopy books,
 online tutorials, asking a friend who is a computer
 professional/instructor, and by lurking on this list, I would say that I
 know the O'Reilly books are highly rated by programmers and I have looked
 at them, but I have always found them difficult if not impossible to learn
 from -- they *assume* you are already a programmer, understand the
 concepts, needing only to concisely get down to the nitty-gritty. 

OK. 

 I got the
 Sam's book, started working my way through it, but pretty much stay away
 from it now -- on page 51/listing3.3, an example is provided of the last
 statement -- unfortunately it is also the first time a nested loop is used
 (without any explanation at all), and if I told you how long I banged my
 head against that one ...

I see. My pupil may find it more obvious. Did you detect any important mis-
information or dis-information in the Sams' book?


 I usually find the Wrox books, Programmer to Programmer, most helpful in
 walking you through all the steps (currently working my way through their
 Perl Programming and their Regular Expressions books). My
 computer-instructor friend dislikes them *because* they walk through all
 the steps (but, then, he's been programming for over 30 years and umpteen
 languages ).


I see. Well, alternative books' recommendations are not really the problem, as 
I can always recommend her to buy/print Beginning Perl or Learning Perl or 
whatever. I just want to know whether the Sams/in 21 days should be avoided.

 I don't know how experienced your friend is. Although I've been a computer
 support professional (PC and MAC) for over ten years, I find programming to
 demand a completely different skill/headset. I'm not saying I'm giving up,
 just that it is a definite struggle as many of the materials I've looked at
 assume what really needs, for a beginner, to be explained.

Well, I'd rather not tell too much about her for confidentiality reasons. But 
thanks for your email.

Regards,

Shlomi Fish


 HTH,
 Safi Newman

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Parody on The Fountainhead - http://xrl.us/bjria

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: 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: recommendations for web/database applications

2009-07-28 Thread Shlomi Fish
On Tuesday 28 July 2009 02:00:13 David Christensen wrote:
 Perl Beginners:

 I am thinking about a Perl web/ database application for political
 organizing and campaigns -- generating precinct walk lists, generating
 phone banking lists, tracking contacts, etc..  I am using Debian
 GNU/Linux 5 with Apache 2.2, mod_perl 2, PostgreSQL 8.3, and Perl 5.10.
 I would like to start with a single-user, simple UI, and small databases
 (1~10k records, ~1kB each), but pick technologies that will allow the
 application to be grown into multi-user, rich UI, and large databases
 (10M+ records).


 Over the years, I have read Programming Perl, Learning Perl, Perl
 Cookbook, Object Oriented Perl, Learning Perl Objects, References, 
 Modules, Advanced Perl Programming, Mastering Perl, Mastering
 Algorithms with Perl, Official Guide to Programming with CGI.pm,
 Programming the Perl DBI, CGI Programming with Perl, Writing Apache
 Modules with Perl and C, MYSQL, MYSQL and Perl for the Web, and
 countless man pages, POD, and other online documentation.  Recently, I
 have read Perl Template Toolkit, Embedding Perl in HTML with Mason,
 and PostgreSQL.  My web/ database experience has been limited to book
 examples/ exercises, some toy applications, and some dead-end attempts
 at e-commerce and CMS applications.


 I plan to start with the database portion of the application and am
 curious what people have to say about object-relational mapping and/or
 other tools that provide a higher-level interface than DBI.pm -- e.g.
 Alzabo, Fey::ORM, DBI::Class, etc..


 Also, what about the various WWW tools -- e.g. CGI.pm, CGI::Application,
 HTML::Template, Template::Toolkit, Mason, Catalyst, Gantry, etc..


Here are my preferences:

1. For the templating system, I really like the Template-Toolkit 
(Template.pm). It's very powerful and convenient. I hate HTML::Template with 
a passion and find it confusing, counter-intuitive and not as powerful as TT2 
is.

2. I've been using mostly plain-DBI in my work (not always web-related), but 
lately been working quite a lot with DBIx::Class, and think it's very nice. 

3. I've programmed some small web-apps using CGI::Application. Recently, I 
started contributing to two Catalyst projects, and like Catalyst a lot. I once 
started reading the Catalyst tutorial (in Catalyst::Manual), but forgot most 
of it, and now just hack on the existing Catalyst code as it is, and it's 
working after some trial and error.

Catalyst seems better than CGI::App.

4. I haven't made use of the new Moose-y features of Catalyst, but they may be 
useful.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
My Aphorisms - http://www.shlomifish.org/humour.html

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/




[ANN] Recent Additions to http://perl-begin.org/

2009-07-28 Thread Shlomi Fish
After the last news item, a lot of work was invested in 
http://perl-begin.org/ , the Perl Beginners' Site. making
it even better than it used to be. Here's a summary of the changes:

* A testimonials page ( http://perl-begin.org/learn/who-is-using/ )
was added, with some honest-to-God testimonial quotes which are now featured 
in the Testimonials side-bar.

* There's a new IDEs and
tools page:

http://perl-begin.org/IDEs-and-tools/ , featuring some Integrated Development 
Environments.

* There's a new page sporting links to collections of blogs.

* Several new topical pages were added:

* * Perl and Databases

* * GUI Development in Perl

* * Perl for XML Processing

* * Debugging

* * Object-oriented Programming in Perl

* * Using CPAN

* A ShareThis ( http://sharethis.com/ ) button was added to the
bottom of every page for easy bookmarking and sharing.

* Many writing errors (spelling, grammar, syntax, phrasing, etc.) have been
corrected by Alan Haggai Alavi ( http://alanhaggai.org/ ). He
seems to have a good eye for catching such problems, and I am indebted to
him.

* Corrected several broken links including those to Ovid's CGI course.

--

We hope you enjoy the new Perl Beginners' Site and please recommend it
to your friends.

All content on Perl-Begin is available under the Creative Commons Attribution 
Licence.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Rethinking CPAN - http://xrl.us/bjn7p

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: recommendations for web/database applications

2009-07-28 Thread Shlomi Fish
On Tuesday 28 July 2009 03:59:36 Dan wrote:
 On Mon, 27 Jul 2009 16:00:13 -0700, David Christensen

 dpchr...@holgerdanske.com wrote:
  Perl Beginners:
 
  I am thinking about a Perl web/ database application for political
  organizing and campaigns

 snipped

  I plan to start with the database portion of the application and am
  curious what people have to say about object-relational mapping and/or
  other tools that provide a higher-level interface than DBI.pm -- e.g.
  Alzabo, Fey::ORM, DBI::Class, etc..
 
 
  Also, what about the various WWW tools -- e.g. CGI.pm, CGI::Application,
  HTML::Template, Template::Toolkit, Mason, Catalyst, Gantry, etc..

 Ah. My favourite topic. Firstly, I hate web applications with a passion.
 They're cheap, clunky approximations of desktop applications, and are
 simply not necessary. Have a look at some of my software ( Gtk2::Ex::DBI,
 Gtk2::Ex::Datasheet::DBI, PDF::ReportWriter ) at:
 http://entropy.homelinux.org/axis - there are some screenshots of
 production apps around. Gtk2-Perl apps are a pleasure to write compared to
 web apps, honestly. Keep in mind people install Gtk2 these days for things
 like pidgin, so it's not too much to ask to install a toolkit for a
 database app. As for scalability, Gtk2::Ex::DBI has built-in record paging,
 and the page size is adjustable. In one of my production apps, I've got a
 config page where people can select different profiles ( LAN, DSL, etc ),
 which changes the page size. And yes, it works very well across DSL.


I believe this page which I've written would be of relevance here:

http://www.shlomifish.org/philosophy/computers/web/use-qmail-instead/

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Freecell Solver - http://fc-solve.berlios.de/

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: On using $_ in subroutines

2009-07-28 Thread Shlomi Fish
On Tuesday 28 July 2009 20:06:34 Bryan R Harris wrote:
  Bryan Harris wrote:
  John W. Krahn wrote:
  Bryan Harris wrote:
  ... but by modifying $_ I was clobbering $_ elsewhere in the larger
  program!
 
  Yes because $_ is a special global variable.  This effect is called
  action at a distance which is why it is better to use named lexically
  scoped variables instead of $_.
 
  I have the Perl Bookshelf on CD (and perldoc, obviously) -- where can I
  read more about this?
 
  perldoc perlvar
 
  http://shoebox.net/articles/perl-warts.html
  http://en.wikipedia.org/wiki/Action_at_a_distance_(computer_science)

 Great info, thanks.

 Curiously, perlvar seems to recommend localizing $_ with local, but I
 thought I read somewhere to never use local and only use my.  I still don't
 understand how those two are different.


Well, my $_ is only possible starting from perl-5.10.0. Not below it. If you 
want your scripts to be compatible with previous version of perl5 (including 
5.8.x) you'll need to use local $_.

local $_ is usually good enough from my experience. I should note that I try 
to avoid using $_ as much as possible in any half-serious code, because 
relying on it is prone to errors because so many Perl built-ins modify it.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Optimizing Code for Speed - http://xrl.us/begfgk

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: Need some advice on learning perl

2009-08-10 Thread Shlomi Fish
On Sunday 09 August 2009 12:18:51 Xu Peter wrote:
 Hi, everyone,

 This is the first time I post my words on a mail list, so I would be
 enlighted if it works ...

 I am a newbie of perl. I have got through some classic perl books, such as
 Learning Perl and Intermediate Perl, and I did some tiny works on perl,
 e.g. a Tk helper that helps me with my vocabulary study, and a BBS search
 engine works under TELNET(which is really poor ... ).

 I really liked perl since it's really convenient in programming(not only
 the syntaxs, but also CPAN, e.g. we can use IO::Socket to do network jobs
 rather than system APIs), and I want to get deeper in learning perl. Does
 anyone can give me some advice on HOW?

 My rough idea is :
 1. What I need now is more code reading, and maybe write a module of my
 own? Is there any suggested modules to learn for a beginner?
 2. Maybe I am not fully prepared, but I really want to anticipate in some
 free software projects(or say, devote some of my time to the free software,
 from where I got lots of help), but I don't know what to start.


I maintain a site with resources for Perl beginners here:

http://perl-begin.org/

You may wish to go over the pages for links and references. You can also see 
my recommendations for Perl (and other non-fiction books) here:

http://www.shlomifish.org/philosophy/books-recommends/

I see you want to read other people's code and write some of your own. If you 
want, I have some Perl projects that may prove of interest to you and that I'd 
love to get some help with:

1. http://github.com/bricas/cpanhq/tree/master

2. http://github.com/shlomif/catable/tree

3. http://web-cpan.berlios.de/ (and 
http://svn.berlios.de/svnroot/repos/web-cpan/ )

There are many other Perl projects out there that people could use help with.

Other than that, you may wish to read some of Ingy's code, which tends to be 
very high-quality:

* http://search.cpan.org/~ingy/

(Although you should probably avoid using Spiffy for OOP.)

Regards,

Shlomi Fish

 Thanks for your suggestions, if possible ...

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Star Trek: We, the Living Dead - 

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: Need some advice on learning perl

2009-08-11 Thread Shlomi Fish
On Tuesday 11 August 2009 17:22:46 Xu Peter wrote:
 David, Octavian, Mr. Randal Schwartz, Shlomy  Lan

 Thank all of you!:)

You're welcome. Just note that it's Shlomi and Ian - not Shlomy and 
Lan.


 I really didn't expected to receive so many helps from all of you, that
 really inspired me alot. And I was really stunned when I first saw Randal's
 name appeared in my reply list... Maybe that's what mail-list is.

 I think I'll always go to stonehenge to read the columns, since I found it
 really another way to learn perl, and enjoy the reading.

 I really want to take part in the programs Shlomy mentioned, but I don't
 think I'm capable now, since I found that still don't know how to use
 git. Maybe I have to do more study before I get to know how to take part
 in it?

Well, in addition to what Chas. Owens said about git, I should note that 
http://web-cpan.berlios.de/ (which was one of the projects I mentioned) is 
using Subversion instead of git, which may be easier for you to get into. 

If you're not using version control yet, you should really start using it, 
because developing code without it is not recommended. For more motivation 
see:

* http://www.shlomifish.org/lecture/Perl/Newbies/lecture5/version-control/

* http://better-scm.berlios.de/

* http://en.wikipedia.org/wiki/Revision_control

I wouldn't recommend using CVS anymore (and Microsoft Visual SourceSafe even 
less than that), but I still find Subversion pretty decent, despite the fact 
that I've been working quite a lot with git. You can find some references to 
other modern version control systems on http://better-scm.berlios.de/ . 
Subversion, git, Bazaar (bzr), Mercurial, Darcs, and Monotone are all open-
source and free, and they seem to be the most popular choices nowadays among 
open-source developers.

Regards,

Shlomi Fish


 Anyway, I'll go on my study.
 2009/8/11 Ian pcs...@gmail.com

  Xu,
 
  I'm a Mainframe Systems Programmer. Assembler and JCL is the only
  languages I knew.
 
  When I decided to learn perl, I looked for some application I need in my
  daily routine,
  bought Randal Schwartz's  Learning Perl to get the basics down and just
  started coding.
 
  I ended up writing an application that collects statistics, put them in
  MySQL and show me nice graphs.
 
  When you have a goal, it is easier to learn to use the tools to achieve
  the goal.
  If this old mainframer can learn perl you will have no problem with it
  ;-)
 
 
  Good luck
  Ian

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Freecell Solver - http://fc-solve.berlios.de/

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/




Improvements to http://perl-begin.org/

2009-08-13 Thread Shlomi Fish
I thought the Perl Beginners' Site - http://perl-begin.org/ 
was perfect after the last update, but boy I was wrong. A quick review and 
critique of the site by a certain prominent Perl developer revealed many
issues with it, and afterwards I had found a lot of stuff that was lacking. So 
here's what has changed.

We're now mirroring the public domain Perl for Newbies tutorial on
http://perl-begin.org/tutorials/perl-for-newbies/ as well as the GFDLed book
Impatient Perl by Greg London ( http://www.greglondon.com/ ). Their
presence on the site was done in order to preserve Perl-Begin's common look 
and feel, and to make sure people would be able to access them without
having to go to a different site, which may be blocked by over-zealous
web-filters. We hope to mirror other freely distributable material that
may prove useful to beginners on Perl-Begin in the future.

The call-for-action notice at the beginning was changed to 
Learn Perl Now! and now appears on all the pages.

We also fixed several look and style glitches.   

There are also several corrections to the text and the hyperlinks.

Stack Overflow was added to http://perl-begin.org/web-forums/ .

There are now mentionings of two new topical books at
http://perl-begin.org/books/topics/ - 
Perl amp; LWP and Programming the Perl DBI.

Finally, the About this site page at http://perl-begin.org/about.html 
was updated and made more modern.

We hope you enjoy the new site. If you like it, please recommend it to
your friends - if you don't - let us know and we'll see what we can do. Unless
mentioned otherwise, all the material on http://perl-begin.org/ is made
available under the Creative Commons Attribution Licence (CC-by) for almost
unlimited distribution and re-use.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
http://www.shlomifish.org/humour/ways_to_do_it.html

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: Coding best practices

2009-08-13 Thread Shlomi Fish
On Friday 14 August 2009 07:21:00 Uri Guttman wrote:
  SB == Steve Bertrand st...@ibctech.ca writes:
i don't use it but i know plenty who do and it seems to be a good
idea. i would recommend it for most perl hackers and if you want to
enforce a known set of coding styles. i strongly enforce my own style
as i edit so i don't generally need an outside agent. but then i don't
like or need syntax highlighting or use debuggers other than print.

   SB Interesting. So, print is a debugging tool that does a complete full
   SB circle. Many on the list have helped me with using different debug
   SB techniques which have greatly helped me advance my understanding of
 what SB my code is actually doing. I appreciate what you say in your last
 SB paragraph, and although have questions, I don't think I need to ask
 them.

 i started with punch cards. print was all you had besides thorough and
 deep analysis of your code. that is a talent lost on too many coders
 today. and even today proper use of print is better than any debug
 tool. but it is still a skill to learn, where and what to print and how
 to analyze the results. i have seen many good coders not get that and
 they stick with debuggers. i find the simplicity of print and my total
 control of what gets printed, etc better than learning more commands,
 having to repeat a set of debug commands (yes, you can macro and preset
 them but that is still more work), etc. print is always there in any
 programs (and debuggers have issues with complex sets of processes, and
 daemons and such).


My recent impression of most Perl programmers has been the opposite - most of 
them have been too lazy or unmotivated to learn about the perl -d flag (or 
similar interactive debuggers), and are always using print's or going on IRC 
asking What is wrong with this code? I find the perl debugger an 
indispensable tool and am actively using it.

While print's have their rightful place, I still think the perl debugger is 
too under-used.

BTW, you may wish to look at my Devel-LineTrace module as a replacement for 
print's:

http://search.cpan.org/dist/Devel-LineTrace/

It allows one to assign print's and other arbitrary debugging code into 
arbitrary locations in the code, without having to directly modify it. Thus, 
one doesn't have to get rid of the print's after one is done with debugging.

I wrote by inspiration from some discussion on Perl-Israel (first in a meeting 
and then on the mailing list). Lately, I've been mostly too lazy to use it and 
just inserted print's directly, but you may fare better with it.

Regards,

Shlomi Fish

 uri

-- 
-
Shlomi Fish   http://www.shlomifish.org/

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: Which blowfish? Can it run from lib in user's account?

2009-08-18 Thread Shlomi Fish
Hi Danjo Creations!

On Monday 17 August 2009 22:48:28 Danjo Creations wrote:
 My script is working fine one our dev server, but I've run into a problem
 with client server with missing modules. No root access, so I did upload 2
 other missing modules into a 'lib' in the account, and they're fine.

 No such luck with Blowfish.

   my $cipher=Crypt::CBC-new( {   cipher = 'Blowfish',
   prepend_iv = 0,
   key= $key,
   iv = $iv   } );
   if ($mode eq 'e') { return encode_base64($cipher-encrypt($input));
 }
   elsif ($mode eq 'd') { return
 $cipher-decrypt(decode_base64($input)); }

 MIME::Base64 is working on its own in a test script.

 I uploaded Crypt::CBC /Crypt/CBC.pm and all the other files that came with
 including the 't' folder with Blowfish.t and Blowfish_PP.t

 The Can't find module error went away, but was replaced with:
 Couldn't load Crypt::Blowfish: Can't locate loadable object for module
 Crypt::Blowfish in @INC
 Compilation failed in require at (eval 15) line 1

 I uploaded Crypt::Blowfish - in the same /Crypt/ folder as CBC

 The error persists


That's because you probably haven't compiled the Crypt::Blowfish binary 
extensions (.so, .dll or whatever). Crypt::Blowfish has some parts written 
in C that are compiled into machine code, and used as a Perl extension and you 
need to upload them to the server. Just uploading it isn't enough.

Do you have a C compiler (such as http://gcc.gnu.org/ ) on the server? If so, 
you can do the perl Makefile.PL ; make ; make test ; make install routine. 
For more information see:

http://perl-begin.org/topics/cpan/

Regards,

Shlomi Fish

 Do I also need /Net/SSH/Perl/Cipher/Blowfish.pm which I see on the dev
 server or am I missing something else? Or am I dealing with module(s) that
 can only be installed higher up the food chain?

 Everything I found via Google mentioning Can't locate loadable object for
 module alluded to a missing or incorrect installation. There was also a
 mention of permissions. All are the account's owner:group with 755 on the
 folders and 644 on the files, same as the 2 modules that are working.

 Jo

-- 
-
Shlomi Fish   http://www.shlomifish.org/
http://www.shlomifish.org/humour/ways_to_do_it.html

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: Coding best practices

2009-08-19 Thread Shlomi Fish
On Friday 14 August 2009 16:18:38 Shawn H. Corey wrote:
 Shlomi Fish wrote:
  My recent impression of most Perl programmers has been the opposite -
  most of them have been too lazy or unmotivated to learn about the perl -d
  flag (or similar interactive debuggers), and are always using print's or
  going on IRC asking What is wrong with this code? I find the perl
  debugger an indispensable tool and am actively using it.
 
  While print's have their rightful place, I still think the perl debugger
  is too under-used.

 We will encourage you to develop the three great virtues of a
 programmer: laziness, impatience, and hubris. -- Larry Wall
 from http://www.c2.com/cgi/wiki?LazinessImpatienceHubris

 The last time I used a debugger was on a large C project.  For small
 programs and unit testing, it was fine, but when things went over 2000
 lines, it became increasingly frustrating to use.  Of course, print
 statements have their limits too but it happens at about 5000 lines.

According to SLOCCount by David A. Wheeler, for Freecell Solver's 
trunk/fc-solve/source :

{{
Totals grouped by language (dominant language first):
ansic:16832 (80.85%)
perl:  2914 (14.00%)
python: 446 (2.14%)
sh: 354 (1.70%)
ruby:   274 (1.32%)

Total Physical Source Lines of Code (SLOC)= 20,820

}}

I've successfully used gdb on this application, and I used it in the past, 
before I heavily refactored and trimmed it lately. Granted, it's an almost 
pure ANSI C program that doesn't do a lot of system stuff, but it is still 
pretty complex and pedantic. I've also used gdb on the GIMP and Subversion, 
which are much larger than Freecell Solver. In Subversion I ran into a (yet 
another) gdb bug, but they are otherwise OK.

I'm using debuggers simply because I know it's often faster and quicker to use 
them than to use traces. I'm not saying traces don't have their place, but 
debuggers are often time saving.

I also wrote some gdb scripts:

http://www.mail-archive.com/linux...@cs.huji.ac.il/msg54660.html

Regards,

Shlomi Fish


 I use Data::Dumper a lot, so most of my debugging statements have
 Dumper in them, making them easy to find.  For those that don't, I add
 # TEMPORARY at the end.  And I leave them behind; I just put a # in
 front of them. :)

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Stop Using MSIE - http://www.shlomifish.org/no-ie/

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: Procedural modules in an object-oriented project

2009-08-19 Thread Shlomi Fish
On Wednesday 19 August 2009 16:03:01 Peter Scott wrote:
 On Tue, 18 Aug 2009 19:39:29 -0400, Steve Bertrand wrote:
  While reviewing my POD to ensure that I've been keeping it up-to-date
  properly, and so that I can still easily understand the API at the
  documentation level, I've noticed that two of my modules have
  subroutines that only perform global tasks, and don't need to be
  object-oriented at all.
 
  Is it recommended that I stick with the overall style of the project by
  making all of the modules object-oriented, or is it better to create
  procedural modules when objects are not required?

 No, you can mix it up.

 Consider whether a subclass might have a reason to override any of these
 global procedures.  If you can postulate a rationale for that, they should
 be class methods.

 The Exporter isn't hard to learn, and Exporter::Simple is even easier and
 prettier.  Non O-O procedures should be exported.

Just for completeness sake, one should note that there's also Sub::Exporter:

http://search.cpan.org/dist/Sub-Exporter/

The POD page has comparisons with other exporters. 

Here's a presentation about Sub-Exporter:

http://www.slideshare.net/rjbs/crafting-custom-interfaces-with-subexporter

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
First stop for Perl beginners - http://perl-begin.org/

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: Fwd: This code is not giving the required output.

2009-08-19 Thread Shlomi Fish
Hi Raheel!

On Wednesday 19 August 2009 15:59:44 Raheel Hassan wrote:
 -- Forwarded message --
 From: Raheel Hassan raheel.has...@gmail.com
 Date: Wed, Aug 19, 2009 at 2:48 PM
 Subject: This code is not giving the required output.
 To: beginners-h...@perl.org


 Hello,

 I have problems in executing the under given code. I need to restart my
 database, apache etc services using on ubuntu machine. for that i have
 written thsi code, but the result of the command is not saving in the file
 , any suggestions please.


 my $result = 'service mysql start 2/var/log/comm.log';

You probably meant:


my $result = `service mysql start 2/var/log/comm.log`;


With backticks instead. a '...' is just a constant string (with no 
interpolation). backticks execute a command and return its output. For more 
information see:

http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Best Introductory Programming Language - http://xrl.us/bjn84

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: Load perl module and all its dependencies together locally

2009-08-19 Thread Shlomi Fish
On Wednesday 19 August 2009 17:49:46 Vitthal Gogate wrote:
 Is there a tool that would load a perl module and automatically all its
 dependencies (i.e. Other perl modules) locally?


By load a perl module do you mean install it? 

 I package dependent perl modules locally that I find missing on my
 development machine, but on production deployment it finds some other
 sub-modules missing!

Please see this page:

http://perl-begin.org/topics/cpan/

Regards,

Shlomi Fish


 How to resolve this problem!

 Regards, Suhas


-- 
-
Shlomi Fish   http://www.shlomifish.org/
Optimizing Code for Speed - http://xrl.us/begfgk

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: PDF generation from a database!!

2009-08-30 Thread Shlomi Fish
On Sunday 30 August 2009 06:18:10 ficovh wrote:
 Hi folks

 I need ideas, suggest for generating a report in .pdf  from a data
 containing in a MySQL database.
 Basically, the idea is putting information from many tables in a
 simple concentrate report. I want tutos, or simple scripts
 for doing this task.

 Thank you for reading this mail.


In addition to what ficovh said, one option is perhaps to generate a file in 
an intermediate format such as POD, HTML, LaTeX, DocBook/XML, or one of them 
lightweight markup languages:

http://en.wikipedia.org/wiki/Category:Lightweight_markup_languages

And then convert that to PDF using a processor. Generating them should be 
easier than generating PDF, but the entire process may be slower.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
My Aphorisms - http://www.shlomifish.org/humour.html

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: PDF generation from a database!!

2009-09-01 Thread Shlomi Fish
Hi ficovh!

On Tuesday 01 September 2009 10:20:43 ficovh wrote:
 Hi.

 I have installed the module in my laptop, and have a question.
 How can generate the xml files ?


XML files? In which XML grammar? (XSL-FO, perhaps?) Or do you mean PDFs?

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
First stop for Perl beginners - http://perl-begin.org/

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: Perl6

2009-09-01 Thread Shlomi Fish
On Wednesday 02 September 2009 02:46:01 Steve Bertrand wrote:
 All,
 
 Can those who have experience comment with their opinions? Perhaps this
 isn't a newb question, but hopefully many have heard about Perl6 [1].
 
 Which changes do you like? What changes don't you like? Are any of you
 developing programs that are strictly Perl6?
 
 Would it be worth attempting to start a project with Perl6 for practise,
 or is it too far off yet?
 

My 2 cents:

Perl 6 seems like it has many interesting concepts and innovative features (or 
such ones that are innovative for the Perl world). We have been seeing more 
and more ideas from it ending up into Perl 5 either as CPAN modules, or as 
core languages features (in perl-5.10.x, etc.).

My main qualm with Perl 6 is its name - it's so radically different from Perl 
5 (which is still mostly backwards-compatible with all previous Perl versions 
down to 1), that calling it Perl 6 is confusing and causes many other 
strategic problems. For example, people wonder if they should learn Perl 5 
while Perl 6 is underway.

The Perl 6 implementations (of which Rakudo seems the most promising) are 
still incomplete and still have bad performance. I don't imply they will stay 
this way forever, naturally, but that's the case for them now. As a result, 
Rakudo can be used for experimenting with Perl 6, but should probably not be 
used in production for most tasks.

For the lighter side, see:

http://perl.net.au/wiki/Perl_Humour#Perl_6

For some of my earlier, and now mostly out-of-date criticism about Perl 6, you 
can see:

* http://www.shlomifish.org/rindolf/

* http://freshmeat.net/articles/critique-of-where-perl-6-is-heading

For some other stuff, see:

* http://perl.net.au/wiki/Perl_6

* http://perl.net.au/wiki/Perl_6_-_Common_Criticisms

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
The Human Hacking Field Guide - http://shlom.in/hhfg

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: Perl's superior text parsing power

2009-09-02 Thread Shlomi Fish
On Thursday 03 September 2009 06:44:40 Uri Guttman wrote:
  SHC == Shawn H Corey shawnhco...@gmail.com writes:
 
   SHC Dave Tang wrote:
I wanted to ask why is Perl, in comparison to other programming
languages, so powerful in text processing?
 
   SHC Undoubtedly, when it was written, Perl was the most powerful text
   SHC processing language available.  This is no longer the case (thanks
   SHC largely to Perl :).  Today's scripting languages have the same text
   SHC processing abilities as Perl.  You will find this true of Perl's
   SHC documentation; some of it has not been updated in quite some time.
 
 why would documentation that is accurate need to be updated? 

Right - it shouldn't. And it has been corrected, updated slightly, or made 
more accessible.

 and each
 new version of perl has added many more perldocs including tutorials,
 quick references and more? as for text processing, see my other
 post. most other langs still don't have perl's text munging power no
 matter how loudly they claim to. power is not only speed but
 expressiveness. 

See also:

* http://www.paulgraham.com/power.html - Succinctness is Power

I should note that what Graham says about the length of the program measured 
in tokens is not entirely accurate. In a way, it is also measured in 
characters - for example most people will prefer len or length over 
string_length or even strlen, and +/./~/, are preferable to 
concatenate.

* http://www.paulgraham.com/popular.html - see Brevity and other factors that 
have made languages like Perl popular.

* http://greenokapi.net/talks/ReadablePerl.pdf - a little about Perl's 
dedicated regular expression syntax (e.g: m{...}), etc.

In addition to regular expressions (as first-order syntactical objects), there 
are also things like pos(), /g, \G, (which is not present in Ruby 1.8.x 
unfortunately) etc. as well as an lvalue-substr, index, rindex, substr with 
negative parameters, and other goodies.

 my favorite simple example of how perl's text and other
 ops work well together is a trivial parser for a simple key=value file
 with one entry per line.
 
 use File::Slurp ;
 my %config = read_file( $file ) =~ /^(\w+)=(.*)$/mg ;
 
 that is concise, clear and not terse. 

I should note that often brevity results in conciseness and succinctness - not 
in terseness. Perl 5 code can be made very terse (in Golf, etc.), and code of 
APL/J/etc. can be much worse than that. But it's not necessary that it will. I 
find Perl's expressive power useful in expressing my thoughts, and don't like 
languages that try to restrict in the name of readability, regularity, or 
any other higher cause.

Regards,

Shlomi Fish

 show me a better simple parser in
 any other lang. that is text processing power. you can parse out the
 keys/values line by line and also assign them to a hash to be used later
 in the program. that is what config parsing should be and too often
 isn't. complexity isn't the same as power.
 
 uri
 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Why I Love Perl - http://shlom.in/joy-of-perl

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: $| = 1 ???

2009-09-10 Thread Shlomi Fish
On Thursday 10 September 2009 11:17:33 Tariq Doukkali wrote:
 Hi,
 
 i can not understand, what does this code:
 
 
 $| = 1;
 

$| is a special variable. Reading its description from perldoc perlvar:


   $|  If set to nonzero, forces a flush right away and after every
   write or print on the currently selected output channel.
   Default is 0 (regardless of whether the channel is really
   buffered by the system or not; $| tells you only whether you've
   asked Perl explicitly to flush after each write).  STDOUT will
   typically be line buffered if output is to the terminal and
   block buffered otherwise.  Setting this variable is useful
   primarily when you are outputting to a pipe or socket, such as
   when you are running a Perl program under rsh and want to see
   the output as it's happening.  This has no effect on input
   buffering.  See getc in perlfunc for that.  See select in
   perldoc on how to select the output channel.  See also
   IO::Handle. (Mnemonic: when you want your pipes to be piping
   hot.)


What it means is that after you do it, then print will output everything 
immediately, without buffering it beforehand.

Hope it helps,

Shlomi Fish

 Thanks
 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Optimising Code for Speed - http://shlom.in/optimise

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: text html from file to a scalar and mail

2009-09-12 Thread Shlomi Fish
Hi John!

Nice to meet you, and welcome to Perl. I'll try to answer as well as I can. 
Note that I will also give you some general Perl best practices and links that 
may not be a cause of the problems you are having.

On Saturday 12 September 2009 11:32:20 John Plum wrote:
 HI Folk,
 
 May I introduce myself, John Plumridge, London, UK.
   - I'm still in awe of this whole creation we're in.
 
 Nice to meet you.
 

:-)

 
 I have a reason of course, for approaching you, via my MTNews 'console'.
 What a great application!
 
 MY problem is obtaining and passing text/html from file to a scalar
 variable to be printed to mail, (using MIME::Creator).
 
 Unfortunately I get: 'printFile(FileHandle=GLOB(0x84b66b8))'
 

This means it is a typeglob (a generic entry in the Perl 5 packages (= 
namespaces)) that is blessed into the FileHandle class. Generally, 
FileHandle is deprecated and you should use IO::Handle and friends instead.

  The reference assigned to the scalar variable is from a FileHandle sub
 routine. However, with a similar reference to sub routines, i.e.
 OrderFromForm_html(),  I get the output printed to mail without a
 problem. That sub routine  is perl processed form data passed from a
 preceding visible page in browser - 'form.html')
 
 With mixed success then, I'v worked hard at this. Take a look:
 
 ###signature (html)from external file###
 
 my $signature_file = /path_to/signature.html;
 

It's nice that you're declaring your variables using my, but why don't you 
have the use strict; and use warnings; pragmata? See:

* http://www.perlmonks.org/?node_id=111088

* http://perl-begin.org/tutorials/perl-for-newbies/part2/#page--my--DIR

In case, they were included, you should have placed them here, so we won't be 
led into believing they were omitted from the original program.

 use FileHandle;
my $signature = new FileHandle;
   $signature-open($signature_file)or die Could not open
 file\n;

You should use IO::Handle instead of File::Handle (or IO::File in your case), 
and use the three args open. It's nice you've used die.

$signature is not a good name for a filehandle - better call it $signature_fh.

 
 
 sub printFile($) {

Don't use prototypes.

  my $fileHandle = $_[0];

Accessing $_[$idx] is not very robust - you should do:


my $fileHandle = shift;


Or:


my ($fileHandle) = @_;


 while ($fileHandle) {
 my $line = $_;

Just do: 


while (my $line = $fileHandle) {


 chomp($line);
 print $line\n;
 $fileHandle-close(); # automatically closes file

You shouldn't close the fileHandle inside the line reading loop, as you won't 
be able to read from it further.

 }
 }
 
 
 
 #---Assemble/concatenate references in both ascii and html, to make full
 confirmatory message bodies with order details---
 
 $scalar_sig = \printFile($signature);

Perl won't call printFile for you from within the string. Neither will the 
print be returned to the string. 

Please do:


my $scalar_sig = slurpFile($signature);


Look at http://search.cpan.org/dist/File-Slurp/ , and there are some other 
modules on the CPAN that can do it. (like http://search.cpan.org/dist/IO-All/ 
).

 
 my $customer_msg_html = $customer_msgStart_html  . OrderFromForm_html()
 . $customer_msgEnd_html . $scalar_sig;

Your style is inconsistent between camelCase, and 
underscore_separated_identifiers. 

 
 # Create Message ---
 
 Email::MIME-create(
 attributes = {
 content_type = text/html,
 charset  = UTF-8,
 encoding = quoted-printable,
 format   = flowed,
 },
 body = $customer_msg_html,
 ),
 
 
 
 So, as I suggested, the message arrives with the body message all nicely
 concatenated , except for the $scalar_sig variable, which is moissing:
 and I have the 'printFile(FileHandle=GLOB(0x84b66b8))' as a nice fat
 error.
 
 I would really appreciate your help, and outright suggestions, as I have
 struggled with is and tests for three days now, (but I have got a lot of
 the work done (: -  though this problem has me stumped)!
 

For more information see:

1. http://perl.net.au/wiki/Freenode_Sharp_Perl_FAQ

2. http://faq.perl.org/

3. http://perl-begin.org/

4. http://www.perl.org/books/beginning-perl/

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
The Case for File Swapping - http://shlom.in/file-swap

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: text html from file to a scalar and mail

2009-09-14 Thread Shlomi Fish
On Sunday 13 September 2009 02:43:52 Jenda Krynicky wrote:
 From: Shlomi Fish shlo...@iglu.org.il
 
   use FileHandle;
  my $signature = new FileHandle;
 $signature-open($signature_file)or die Could not open
   file\n;
 
  You should use IO::Handle instead of File::Handle (or IO::File in your
  case), and use the three args open. It's nice you've used die.
 
 Nope. You should not be bothering with thatever class is at the
 moment behind the Perl filehandles and just use open() as a function.
 Not everything has to be an object
 
   open my $SIGNATURE, '', $signature_file
 or die Could not open '$signature_file': $^E\n;
 

Indeed. No need to call $SIGNATURE with all-caps. $signature_fh is good 
enough. I should note that if you do use IO::Handle; at the top, then you 
can all methods on $signature_fh.

  $signature is not a good name for a filehandle - better call it
  $signature_fh.
 
 I use all capitals for filehandles. Both oldstyle and lexical.

I dislike all-capitals because it's like shouting and are harder to read. But 
this is a colour of the bike-shed argument:

http://bikeshed.com/

 
my $fileHandle = $_[0];
 
  Accessing $_[$idx] is not very robust - you should do:
 
  
  my $fileHandle = shift;
 
 
  Or:
 
  
  my ($fileHandle) = @_;
 
 Nope. Accessing $_[$idx] all over the place within the subroutine
 would be prone to errors and inconvenient (though sometimes
 necessary), what syntax do you use to copy the parameters into
 lexical variables is largely unimportant. And sometimes you can't
 just shift() off parameters from @_, you need to keep them there.
 

Generally, I sometimes use something like:

sub my_method
{
my $self = shift;

my ($param1, $param2, $param3) = @_;

.
.
.
if (COND())
{
return $self-other_method(@_);
}
}

Normally I don't like using $_[0], $_[1], etc. directly. The only use I can 
think for them is to modify them in place using aliases. But in this case it 
is better and safer to pass them as references.

   my $customer_msg_html = $customer_msgStart_html  . OrderFromForm_html()
   . $customer_msgEnd_html . $scalar_sig;
 
  Your style is inconsistent between camelCase, and
  underscore_separated_identifiers.
 
 Maybe there is a meaning to the underscores on some places and case
 change in others. Don't be so quick. The fact that you do not see a
 pattern from a very short example doesn't necessarily mean there
 isn't one. It may very well be too big to fit in the small cut hole
 that you see.


Maybe. It's still hard to read.

Regards,

Shlomi Fish
 
 Jenda
 = je...@krynicky.cz === http://Jenda.Krynicky.cz =
 When it comes to wine, women and song, wizards are allowed
 to get drunk and croon as much as they like.
   -- Terry Pratchett in Sourcery
 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Freecell Solver - http://fc-solve.berlios.de/

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: Giving away my code

2009-09-15 Thread Shlomi Fish
In addition to what other people say, and other caveats apply (I am not a 
lawyer, etc.).

On Tuesday 15 September 2009 04:14:50 Steve Bertrand wrote:
 Ok.
 
 Some of you have probably come across my post on monks, but I ask here
 with a bit more detail.
 
 My project is a suite for Internet Service Provider management. The core
 engine is topped off with a web gui interface. This project contains
 about 7,800 lines of code, POD and unit tests.
 
 The HTML/email templates are separate, but I do intend to integrate them
 into the core of the project.
 
 There are also a few other personal packages which I've written that I
 tap into, but they are better left separate ( RadiusMgmt, EmailMgmt
 etc). These will be re-written, because what I know now, I didn't know
  then.
 
 The company that employs me is very small, and although I don't believe
 there will ever be a problem with giving my code away, I want to take
 advantage of the fact that I have never signed anything to say I
 ``can't'' give it away. I'm at a stage where some of our staff is
 testing, so before the powers-that-be decide that this is company code:

You should make sure. An employer may make claim to code you've written on job 
time, and for job purposes. So you should get their explicit permission for 
releasing the source into the wild as Free and Open Source Software (FOSS).

 
 What is the quickest and easiest way to ensure my code is truly licensed
 as public domain, if I don't feel that the code is quite CPAN worthy?

You may wish to read what I wrote about it here:

http://www.shlomifish.org/philosophy/computers/open-source/foss-licences-wars/

Also see the Coverage and Comments section at the bottom - some good stuff 
there.

As other people noted, putting code under the public domain is problematic 
because the Public Domain is not widely understood or accepted 
internationally, and because licensing code under the Public Domain may not be 
possible. (to quote the article). See:

http://linuxmafia.com/faq/Licensing_and_Law/public-domain.html

You can get pretty close to the American conception of the Public Domain using 
a permissive licence. The MIT/X11 Licence ( 
http://en.wikipedia.org/wiki/MIT_License ) explicitly allows sub-licensing, 
and the current interpretation of the 2-clause or 3-clause BSD licences is 
similar. There's also the http://en.wikipedia.org/wiki/ISC_license which is 
similar to the BSD, but uses a simpler language, and is favoured by the 
OpenBSD project for their own project.

According to what I've heard from some people, such licences require that the 
entire licence be present in each source file. Though with similar and longer 
permissive licences such as the Apache Licence, this is not necessary.

Note that you should be sure that by public domain you actually mean that 
people can take your code, and create derived copies under different (possibly 
non-open-source) licences. If that's not what you want, make sure you license 
your code under weak-copyleft or strong-copyleft licenses. (See my article for 
a description). As someone noted the Artistic License 2.0 is not exactly weak 
copyleft, but rather weak-weak-copyleft, in the sense that one can still 
distribute modified binaries under different licences. I'm not aware of a good 
weak copyleft that's also compatible with GPLv2 and above, and I went over all 
the GPL-compatible licences on:

http://www.gnu.org/philosophy/license-list.html

 
 Do I put it somewhere with a license in it? Can I simply share it with
 someone else, with a license in it?
 

Assuming you get a green light from the company that contracted you, you can 
host it somewhere like http://sourceforge.net/ , http://berlios.de/ 
http://code.google.com/hosting/ , http://github.com/ , 
http://savannah.gnu.org/ , http://bitbucket.org/ , and the list goes on:

http://en.wikipedia.org/wiki/Comparison_of_open_source_software_hosting_facilities

 Steve
 

Regards,

Shlomi Fish 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
What Makes Software Apps High Quality -  http://shlom.in/sw-quality

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: Giving away my code

2009-09-15 Thread Shlomi Fish
On Tuesday 15 September 2009 09:06:29 Shlomi Fish wrote:
 In addition to what other people say, and other caveats apply (I am not a
 lawyer, etc.).
 
[SNIP]
 Assuming you get a green light from the company that contracted you, you
  can host it somewhere like http://sourceforge.net/ , http://berlios.de/
  http://code.google.com/hosting/ , http://github.com/ ,
 http://savannah.gnu.org/ , http://bitbucket.org/ , and the list goes on:
 
 http://en.wikipedia.org/wiki/Comparison_of_open_source_software_hosting_fac
 ilities
 

In addition to that, I should note that you should announce it on 
http://freshmeat.net/ , http://directory.fsf.org/ , http://lwn.net/ , etc.

Regards,

Shlomi Fish

  Steve
 
 Regards,
 
   Shlomi Fish
 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Original Riddles - http://www.shlomifish.org/puzzles/

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: Tell your lawyers [Was - Re: Out Of Memory]

2009-09-20 Thread Shlomi Fish
On Sunday 20 Sep 2009 19:12:31 Shawn H Corey wrote:
 Telemachus wrote:
  On Sun Sep 20 2009 @ 10:13, Shawn H Corey wrote:
  Telemachus wrote:
  Ok, I'll bite: do you really mean to say that it's a crime somewhere to
  put this bullshit drivel into an email and then send that mail to a
  public list? Annoying, sure. Pointless, sure. Non-binding, sure. But a
  crime?
 
  Speeding is illegal but not a crime.  Not all laws are part of the
  criminal code.
 
  I think that my meaning was reasonably clear, but apparently not.
 
  Is it part of hte civil code then? Is there some law - be it criminal or
  otherwise - against putting the silly disclaimers into emails and then
  sending those emails to a public mail list?
 
  I'm genuininely curious (and find it a little hard to believe).
 
 It is misrepresentation.  By participating in a public newsgroup,
 mailing list or forum, you automatically place that correspondence in
 the public domain since their stated purpose is to share information.

The term the public domain may be misleading here. What you meant is that 
work is now public or public knowledge or something, not that its 
copyright has expired or that the author has explicitly waived all rights:

* http://en.wikipedia.org/wiki/Public_domain

* http://wiki.creativecommons.org/CC0_FAQ

For all we know, an email that was posted to a mailing list could be 
proprietary and restricted, and by default it is. However, it is a public 
artwork, that is meant for public consumption and is archived etc. As I noted 
here:

http://www.shlomifish.org/philosophy/case-for-file-swapping/

public artworks are those that are not secret, confidential, private, 
personal, etc. In this day and age, we can expect them to be copied, 
digitised, distributed and redistributed, quoted, sampled, remixed, etc. up to 
the limits of the respect that people put into the originator, and the limits 
of the reach of the law.

(This is not the place to discuss the opinions which I voice in the essay, but 
if you have any comments on it feel free to use the Disqus comments system on 
the page, or alternatively reply to my private E-mail.)

 Then claiming that anyone who reads it cannot use it as they see fit,
 violates the agreement that you willing accepted.  It is illegal to
 claim ownership to something you no longer have ownership of.
 

I'm not sure whether we should discuss it so exhaustively. Many workplaces add 
it to their employee's E-mails, and it is a common practice, and it gets 
posted to public mailing lists with publicly accessible archives, and it may 
be legally iffy - but that's life. And it's more amusing to read them than 
saddening.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
The Human Hacking Field Guide - http://shlom.in/hhfg

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: Requesting peer review...

2009-09-21 Thread Shlomi Fish
On Monday 21 Sep 2009 01:30:33 Steve Bertrand wrote:
 Hi everyone,
 
 On my ISP project, I've done a personal 'code freeze'. My objective is
 to go through every sub and ensure tests and POD are accurate. Where
 they are not, I'll (re)write them.
 
 During this procedure, I noticed that many methods did not have decent
 return values... so I added them.
 
 I know it's much to ask, but I'm asking for review on my 'style'. I want
 to ensure that what I do is understandable to most.
 
 If you have time to do a quick browse, I'm looking to know:
 
 - does the POD make sense
 - does my coding writing style look ok (I still haven't found my style yet)
 - if my tests are ok
 
 With that said, I'd like to say:
 
 - forgive the dirty way that I munge the sym table. I'll be changing this
 - my tests were written hastily. I'm finding it hard to put tests into a
 test file and not into a 'throwaway' file.
 
 I do want feedback/advice. I especially want advice on writing tests.
 
 Please be harsh. Although it's sometimes hard to swallow, I learn best
 when comments are direct, accurate, and truthful (thanks Uri).
 

On http://acct.eagle.ca:8020/ISP/Error :


unless defined $error {
$error = ISP::Error-new;
$error-bad_api();
}


As far as I know, you cannot use unless without the parenthesis this way. You 
need:


unless (defined $error) {

}


Furthermore, I should not that using unless instead of if (! or if (not 
is less natural in many human languages. Whenever I (as a Hebrew speaker) see 
an unless, I keep have to think what it is. Also see:

http://www.shlomifish.org/humour/fortunes/shlomif.html#n-uple-negative


add_trace(BACK)

add_message(MESSAGE)

Etc.


I prefer to write something like:


add_trace($back)

add_message($message)



Possibly with a better Perl 5 data structure type.

You also seem to describe what the function does internally rather than why 
and how someone should use it. For example:


Pushes onto @{ $error-{ data }} the data that triggered the error process. 
This method acts as both a setter and a getter.


I don't care what how it does it. I want to know why should I call it and how 
I should use it.

Finally, perhaps your synopsis should be longer and more meaningful.

I hope I don't come up as too harsh.

Regards,

Shlomi Fish


 pmhttp://ipv6canada.com/Error.pm
 tests http://ipv6canada.com/Error.t
 pod   http://acct.eagle.ca:8020/ISP/Error
 
 Steve
 
 ps. ISP::Error was first up, due to alphabetical order. Feedback on this
 module will pave my way for future progress.
 
 pps. Thanks. If you've read this far, you've probably done review. I am
 ready to be broken, and brought back up.
 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Funny Anti-Terrorism Story - http://shlom.in/enemy

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: Burnt Camel Club (WAS: Charter of perl.beginners)

2009-09-21 Thread Shlomi Fish
On Monday 21 Sep 2009 20:17:12 Shawn H Corey wrote:
 Ian wrote:
  My first experience with this list is neatly summed up in the The Way We
  Were section of the article by Casey.
  But I did have the added bonus of  being called a liar.
 
  On Thu, Aug 20, 2009 at 5:12 PM, Randal L. Schwartz 
 
  mer...@stonehenge.com wrote:
  If you imply that you have a proven solution, you are lying to them.  I
  ask that you don't lie in that way.
 
 Welcome to the Burnt Camel Club.  Membership is exclusive to those who
 have been flamed by Randal.  It's his way of showing he cares.  (Most of
 the time he doesn't bother replying.)
 

As everyone knows, Randal is the Perl equivalent of the Spanish Inquisition. 
Starting from and continuing a little:

http://www.shlomifish.org/humour/fortunes/shlomif.html#sf-pm-perl-saints-
instead-of-heroes

(short and non-split URL - http://xrl.us/bfkgzn ).

Enjoy!

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Funny Anti-Terrorism Story - http://shlom.in/enemy

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: mbtomh in perl?

2009-09-23 Thread Shlomi Fish
Hi Alexey!

On Tuesday 22 Sep 2009 16:56:42 Mishustin Alexey wrote:
 Hello,
 
 Is there a perl tool for converting mbox files to MH directories?
 
 Google found only a tool on tcl [1] and a perl tool for converting mbox
 to Maildir [2].
 
 [1] - http://wiki.tcl.tk/15276
 [2] - http://batleth.sapienti-sat.org/projects/mb2md/
 
 If there isn't such a tool 'out of the box', evidently, I will need
 some help to rewrite the tcl script on perl...
 

Try the Mail::Box module:

http://search.cpan.org/dist/Mail-Box/

It seems to still be the best of breed in this regard from what some 
authoritative sources in the Perl Email Project told me. It is large and 
complicated, but gets the job done.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
My Aphorisms - http://www.shlomifish.org/humour.html

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: Using named params

2009-09-26 Thread Shlomi Fish
On Saturday 26 Sep 2009 03:18:35 Steve Bertrand wrote:
 Hi all,
 
 I've read a fair bit about named params, and have been hit by bugs by
 overlapping lists into hashes etc.
 
 Below is a method that essentially isn't truly a 'captcha', but is
 something I use to 'ensure' that the person clicking the submit button
 on a web gui isn't clicking by accident. This was to avoid having to
 write intermediary Confirm stages for potentially dangerous actions.
 (this is all for internal staff... if they fsck things up after this
 stage, they get to rewrite things themselves ;)
 
 Instead of re-writing the code continuously, I finally decided to just
 move it to the base class.
 
 I'm concerned about how I slurp in my params. For some reason, it
 'feels' very dangerous to me.
 
 Can someone recommend the reading I need to do to ensure that I've been
 over the possible ramifications? IOW, I'd like to spend more time
 learning about the type of params one should use, when they should be
 used, and when certain param types MUST be used (irt standard types, and
 refs).
 
 Just to include some code:
 

A few notes.

 sub captcha {
 
 my $self= shift;
 my %params  = @_;
 

My personal preference is to do something like:

{{{
my $params = shift;
}}}

And pass it as a


$self-my_method(
{
%hash,
}
)


This way it is faster and more robust than clobbering the hash into @_.

 if ( ! %params ) {
 
 my $captcha_length = $self-CAPTCHA_LENGTH();
 
 my $captcha;
 
 for ( 1 .. $captcha_length ) {
 $captcha .= int( rand( 10 ));
 }
 
 return $captcha;
 }
 
 my $captcha = $params{ -captcha };
 my $input   = $params{ -input };

You shouldn't use a leading - for the parameter keys. Just do:


my $captcha = $params{captcha};
my $input = $params{input};


- is a remnant from the olden days.

Now to answer your question - you may wish to look at Params::Validate and 
similar modules:

http://search.cpan.org/dist/Params-Validate/

Regards,

Shlomi Fish

 
 if ( ! $captcha || ! $input ) {
 return 1;
 }
 
 if ( $captcha eq $input ) {
 return $captcha;
 }
 
 return 0;
 }
 
 Steve
 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Why I Love Perl - http://shlom.in/joy-of-perl

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: Change character code 160 to 32

2009-10-04 Thread Shlomi Fish
On Sunday 04 Oct 2009 17:53:24 Mike Flannigan wrote:
 I want to change character code 160 to character
 code 32 throughout a bunch of text files.  I'm using
 this right now
 s/(.)/ord($1) == '160' ? chr(32) : $1 /eg;
 and it works, but I don't like it much.  If anybody
 has another way they like better, I'd appreciate
 seeing it.  It does not have to be a reg exp.
 
 Anybody know why this doesn't work?
 tr/\160/\32/d;
 Oddly it replaces 'p' (character code 80) with
 character code 26???
 

Well, Shawn gave you the correct answer, I'll just explain why it didn't work 
for you. The reason it doesn't is because \DDD uses octal digits - not decimal 
ones:

http://en.wikipedia.org/wiki/Octal

Regards,

Shlomi Fish

 I get the digest version, so may not respond
 right away.
 
 
 Mike Flannigan
 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Freecell Solver - http://fc-solve.berlios.de/

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: Tips and Tricks?

2009-10-04 Thread Shlomi Fish
Hi Slick!

On Sunday 04 Oct 2009 20:02:36 Slick wrote:
 I am new at this perl thing. I just want to know tips and simple scripting.
   I also use strawberry perl for my program.
 

Strawberry Perl is a very fine choice for Perl on Windows - probably better 
than ActivePerl by now.

For a comprehensive site with many links to beginner-friendly Perl resources 
see:

http://perl-begin.org/

(Note: I've originated this site and am still its primary maintainer).

We're currently working on integrating the good stuff from there and other 
sites into the various *.perl.org sites, but that is an ongoing process that 
will take some time.

Regards,

Shlomi Fish

 Thanks
 
  Jason H. Owens
 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Interview with Ben Collins-Sussman - http://shlom.in/sussman

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: Perl Questions

2009-10-05 Thread Shlomi Fish
On Monday 05 Oct 2009 07:01:47 Tim Bowden wrote:
 On Sun, 2009-10-04 at 15:03 -0700, Slick wrote:
  I have a couple of questions.
 
  What is a good starter perl book to learn perl.
 
 Best learning Perl book is 'Learning Perl'.  Also known as the Lama
 book.  There are other good texts also, but imho that is by far the
 best.

Just a nit pick - it's the Llama Book - not the Lama book:

* http://en.wikipedia.org/wiki/Llama

* http://en.wikipedia.org/wiki/Lama

* http://oreilly.com/catalog/9780596520113

Confusingly the Llama animal is spelled Lama in Dutch:

* http://nl.wikipedia.org/wiki/Lama_%28dier%29

And here's a funny video of the Dutch comedy group the de Lama's:

http://www.youtube.com/watch?v=63ymR74im40

(I don't speak Dutch, but it's still funny).

Regards,

Shlomi Fish

 
  Secondly, I am kinda having trouble assimilating all the perl
   information.  I want to know ways that you all remember the format of
   a script as well as the main items that are normally use.  I know
   about the Scalars (word for a word with $ used.  $a=2), Array (several
   items @b= (1, 2, 3).  I am just having problems figuring out when and
   where they would be used and to a point reading a script.
 
 I once read that Perl was written to be programmer friendly, not learner
 friendly, and that the best way to learn Perl is to use it every day for
 at least 20 mins.  Come to think of it, that advice may well have come
 from the Lama book.
 
  Hope you don't mind my questions.  Just trying to compliment my A+
   skills, trying to be a IT tech and that would help for system
   administration (how I don't know yet, cause I am still learning)
 
 No idea how much Perl is used in Windows admin, but I'd hate to admin a
 nix box without any Perl skills.
 
   Jason H. Owens
 
 Tim Bowden
 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
http://www.shlomifish.org/humour/ways_to_do_it.html

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: tabular printing

2009-10-05 Thread Shlomi Fish
On Monday 05 Oct 2009 11:27:23 Raymond Wan wrote:
 Hi Andreas,
 
 Andreas Moroder wrote:
  I want pro print to screen two strings. The problem ist that the length
  of the strings are variable, so I get a unreadable output. Even using \t
  does not help because the lenght can vary from 5 to 15 characters.
  Is there a simple way to expand the first columnt to a fixex size.
 
 I'm not sure if this will help (I've never used it before):
 
 http://perldoc.perl.org/perlform.html
 

As recommended in Perl Best Practices, one should use:

http://search.cpan.org/dist/Perl6-Form/

Instead of perlform which has many design anti-patterns.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
The Human Hacking Field Guide - http://shlom.in/hhfg

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: Array's

2009-10-05 Thread Shlomi Fish
On Monday 05 Oct 2009 22:49:47 Slick wrote:
 Just clarification.  At this time I have not written any of my code (dont'
  know where to begin yet, however the website that I am looking at
  perl.begin.org seems to have diffrent methods for one item.  I have seen
  @ for arrays written like this:   @myarray ,but I have also seen an array
  per the perl.begin.org writting like:$primes[$num_primes].  Are they
  both the same? Because it would be easier in my opinion to write:
 
 @myarray = 4;
  instead of writing this: 
 $primes[$num_primes] = 2; 
 

You probably mean : 

http://perl-begin.org/tutorials/perl-for-newbies/part1/#page--arrays--DIR

$primes[$num_primes] assigns to index No. $num_primes (where the array starts 
at index 0) of @primes.

Doing {{{ @myarray = 4 }}} won't do what you want (as opposed to PHP's 
{{{ $myarray[] = 4 }}}, but {{{ push @myarray, 4; }}} will probably do what 
you want. The = assignment overrides the entire variable.

Regards,

Shlomi Fish

 Am I mising something, or are these two things interchangable?
  Jason H. Owens
 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Funny Anti-Terrorism Story - http://shlom.in/enemy

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: yet another question

2009-10-07 Thread Shlomi Fish
On Wednesday 07 Oct 2009 02:11:38 Slick wrote:
 Sorry for all my questions.
 
 What do you guys do to practice? Do you practice one script over and over
  again? Do you read differnt scripts and figure out what is happening in
  each one? Do you think of ideas to do things, then make the script for
  that?

What I'm doing to practice is not primarily with scripts, but rather with 
distributions of Perl code (so-called CPAN modules or packages). See:

http://search.cpan.org/~shlomif/

Most of the scripts I put on CPAN are just very small wrappers for a more 
complete Perl .pm file with an API that processes the command line. Something 
like:


use strict;
use warnings;
use App::MyApp;

my $app = App::MyApp-new();
$app-run();


This facilitates testing and also allow writing something like 
{{{ perl -MApp::MyApp -e 'run()'; }}} which overcomes many problems.

I also read many Perl blogs, books, chat on IRC in Perl-related channels, etc. 
And I also read other people's code when I need to learn something about a 
CPAN module I'm using or have started working on. It's not always the best 
code possible, but as Joel on Software mentions here: 
http://www.joelonsoftware.com/articles/fog69.html 
It’s harder to read code than to write it. - so it's more challenging and 
brings more benefit.

Some people read other people's code for enlightenment or for fun:

http://tech.groups.yahoo.com/group/hackers-il/message/3576

Other people pointed you to http://perl-begin.org/ . 

I should note that most of my time is probably spent writing HTML, CSS, etc. 
using Website Meta Language ( http://thewml.org/ ), 
Latemp ( http://web-cpan.berlios.de/latemp/ ), DocBook/XML ( 
http://www.docbook.org/ ), and various XML grammars I've created. It's not 
that I don't enjoy writing Perl code (or code in other programming languages), 
just that I also love writing and blogging.

Regards,

Shlomi Fish

 
  Any tips here would be appriciated.  
  Jason H. Owens
 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Parody on The Fountainhead - http://shlom.in/towtf

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: for output from other unix commands

2009-10-08 Thread Shlomi Fish
Hi Harry!

On Thursday 08 Oct 2009 21:29:04 Harry Putnam wrote:
 I'm just looking for a push to get started... I do have some perl
 skills (pretty lowlevel to be sure) so can do basic formating with
 printf and such.
 
 But here... I expect my input to be pretty uniform actually already
 formatted ok. Except, 1 or 2 lines somewhere in the input that will be
 longer and make reading the output a bit of a chore.
 
 I want to catch those long lines and format them like one might format
 a news/mail message... wrapped at column 72 or so but also indented
 whatever spcs looks good.
 
 I looked at perldoc -f format but that says its about pictures and
 doesn't appear to be intended to format text.
 

Have you tried http://search.cpan.org/dist/Perl6-Form/ ? Or maybe:

http://search.cpan.org/dist/Text-Tabs+Wrap/

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
http://www.shlomifish.org/humour/ways_to_do_it.html

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: question

2009-10-12 Thread Shlomi Fish
Hi Jesus!

I'm BCCing this message to a fellow Perl programmer who also studies in 
lsu.edu , and whom I've met on the IRC. He would be free to respond to the 
list and/or to you and me in private.

On Monday 12 Oct 2009 23:40:51 Jesus Fernandez wrote:
 Hello friends,
 
 I wrote a program that can simulate coalescent times of gene copies in a
 single population of constant size with a N=10 000 and a k=25, now i want
  to make 5000 simulations, any help?
 
 #!jesusafernandez/bin/perl
 use warnings;
 

OK. You need use strict; and I think you need an absolute path like:


#!/home/jesusfernandez/bin/perl


I would also suggest picking up a shorter username , unless of course it's a 
shared computer, because you are likely to enter it a lot.

 $n = 1;
 $k = 25;
 while ($k=2){
 if ($k==1) {last;}
 $mean=(4*$n)/$k*($k-1);
 $time=(-log(rand)*$mean);
 push(@coalt, $time);
 $k=$k-1;
 }
 for ($time=0; $time24; $time++){
 print $coalt[$time]\n;
 }
 

I think you can change $n to 20_000 (_ can be used to separate digits in 
Perl) and get done with it. But you really should learn Perl better. This code 
is not particularly hard to understand and you can learn Perl from the various 
resources and links here:

http://perl-begin.org/

Alternatively, you may opt to hire someone to tweak that Perl code, but it 
seems likely that you'd be better off learning how to read such Perl code. 
Note that some Perl code would take a lot of time to read and understand (e.g: 
golfed Perl, obfuscated Perl), but most production Perl code, including the 
one you have given here is not that bad.

(It will take time for me to understand what the algorithm in your code is 
doing, but that would be common to all languages).

Regards,

Shlomi Fish


-- 
-
Shlomi Fish   http://www.shlomifish.org/
Why I Love Perl - http://shlom.in/joy-of-perl

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: pcregrep match groups

2009-10-19 Thread Shlomi Fish
Hi Chris!

On Friday 16 Oct 2009 22:55:04 Chris Allen wrote:
 I'm using pcregrep in a pipeline to match some information for a
 network monitoring system.  

PCRE is the not-so-Perl-compatible Regular Expression library. It's probably a 
pretty nice as a way to provide Perl-like (but different) regular expressions 
for programs written in C, C++ and other languages, but it's something that we 
Perl people may opt not to help you with because it's not written in Perl or 
is Perl-compatible.

GNU grep's -P flag is similar, and as much as I am fond of it, it again uses 
PCRE. Too bad, though, that it is often absent from /bin/grep (as is the case 
for Debian and Ubuntu) due to the fact that pcre belongs in /usr/bin.

You may wish to look at ack - http://betterthangrep.com/ - for a Perl-based 
implementation of an improved grep, that can act as a filter too, but has some 
other advantages (and possibly some cases where it will be less good).

 I'm having a bit of a problem doing this
 smoothly with the least amount of code.  One thing in particular is
 driving me crazy - I can't figure out how to output only the contents
 of my match groups with pcregrep.
 
 Here's what I'm doing:
 
   echo status dir | bconsole | pcregrep -M '^Sched.*:\n(.*\n)*?
 ^$'

You can try using 


perl -0777 -p -e 'print $1 if m{^Sched.*:\n(.*\n)*?^$}ms'


(Untested)

Instead.

 
 I only want pcregrep to write to stdout the data in match group 1, ie
 the stuff inside (.*\n)
 
 Is there a way to do this with pcregrep?
 

No idea, but there probably is with perl -e and similar 
http://perldoc.perl.org/perlrun.html flags.

Regards,

Shlomi Fish

-- 
Sent from an iPhone owned by an iLoser.

-
Shlomi Fish   http://www.shlomifish.org/
Optimising Code for Speed - http://shlom.in/optimise

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: Convert Site Name to Dotted IP Address

2009-10-22 Thread Shlomi Fish
Hi Anant!

Here's some review of your code:

On Thursday 22 Oct 2009 12:23:55 Anant Gupta wrote:
 I wrote
 
 #!usr/bin/perl
 use Socket;

1. You should add use strict; and use warnings; at the top of every file. 
Writing programs without them is dangerous. Probably the only instance where 
they may be omitted is in very simple perl -e scripts (see perldoc perlrun) 
and possibly some other short scripts where they get in the way.

Which book or tutorial have you been using to learn Perl? It's probably not 
very good. 

Please look at http://perl-begin.org/ for some recommendations. (Many of which 
are available online).

2. You should probably use IO::Socket and its friends or something. It hides 
the DNS nitty-gritty details for you. If you want to speak a protocol above 
TCP or UDP, then there are plenty of fine client and server modules on CPAN. 
Just go to http://search.cpan.org/ or http://kobesearch.cpan.org/ and search 
for the protocol (or ask us). No need to re-invent an ad-hoc and incomplete 
wheel, which will later have to be maintained and enhanced, and become a 
permanent part what we call the darkpan, which is all the Perl code that's 
not on the CPAN, or even in different open-source projects.

 use constant ADDR = 'www.google.com';
 my $name=shift || ADDR;

You probably want:


my $name = shift || ADDR;


And please separate paragraphs with blank lines. All use constants should be 
in their own paragraph or a few. Perl Best Practices (PBP) has some issues 
with use constant which I tend to agree with. It recommends using Readonly 
variables (see http://search.cpan.org/dist/Readonly/ ) but I prefer just doing 
something like:


my $default_addr = 'www.google.com';


Or:


our $default_addr = 'www.google.com';


and make them mutable but constant by discipline and convention variables. 

 $packed=gethostbyname($name);

Use my and again - surround a = by spaces.

 $dotted-inet_ntoa($packed);

This is a void expression. You probably want = instead of -.

 print DOtted Address is $packed;

You have a typo here - DOtted instead of Dotted. And you probably want a 
trailing \n to print a newline.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
The Case for File Swapping - http://shlom.in/file-swap

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: xml simple question

2009-10-23 Thread Shlomi Fish
On Friday 23 Oct 2009 15:16:15 Shawn H Corey wrote:
 getget wrote:
  The content of 2 files output.xml and input.xml are different. How can
  I create the output file its content the same with input.xml.
 
 Use a different parser than XML::Simple.  I suggest XML::Twig.
 
 XML::Simple does not distinguish between attributes and content.
 Because of this, it does not reproduce XML accurately.  It's good if all
 you want to do is read XML but if use want to write it, use something
 different.
 

I can second that. XML::Simple has inherent philosophical design problems and 
I never use it or waste my time to support people using it.

Risking making the use qmail instead syndrome (see:
http://www.shlomifish.org/philosophy/computers/web/use-qmail-instead/ ), I 
hereby tell you - don't use XML::Simple if you value your sanity. It does not 
truly handle XML and is anything but simple.

Regards,

Shlomi Fish, who now maintains XML-RSS which has many XML-Simple'isms, 
despite the fact that it doesn't use it, and that some people want even more 
XML-Simple'isms to support the various brain-damaged RSS extensions that one 
can find in the wild.

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Rethinking CPAN - http://shlom.in/rethinking-cpan

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: split n characters into n chunks

2009-10-25 Thread Shlomi Fish
On Sunday 25 Oct 2009 14:39:32 Shawn H Corey wrote:
 Michael Alipio wrote:
  Any idea how to do this? I'm thinking maybe I can just
  split the whole string and push each character into array,
  then loop through the array, getting 3 elements set in the
  proces..
 
 Split the string into an array, loop through it and use a slice to join
 the elements.
 

Why not use perldoc -f substr ( http://perldoc.perl.org/functions/substr.html 
) in a loop? Alternatively one can use unpack but I'm not sure how well it 
would handle Unicode characters.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
First stop for Perl beginners - http://perl-begin.org/

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: AW: perl document

2009-10-26 Thread Shlomi Fish
On Monday 26 Oct 2009 10:05:05 Thomas Bätzler wrote:
 mahesh bhasme mbha...@gmail.com asked:
  I am new to perl. From where I get the basic perl document
 
 Depends on your distribution, really. If you're on Windows and using the
  ActiveState Perl distribution, look for the html folder in your Perl
  installation directory.
 
 On Unix, you might want to try perldoc or man to get you started. Have a
  look at the perlsyn, perlop and perlrun documents (perldoc persyn etc)
  if you've got some programming experience.
 
 If you don't, you might be better off with supplementary documentation in
  book form like Learning Perl - please see http://books.perl.org/.
 
 HTH,
 Thomas
 

As Thomas notes, Mahesh's request is phrased ambiguously. I should note that 
other people and I have concentrated links to most of the important Perl 
online resources here:

http://perl-begin.org/

Any additions or corrections for it would be welcome.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
The Human Hacking Field Guide - http://shlom.in/hhfg

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: AW: compact my wordlist generator

2009-10-26 Thread Shlomi Fish
A bit of CS philosophy if you may...

On Monday 26 Oct 2009 18:41:23 Jim Gibson wrote:
 On 10/26/09 Mon  Oct 26, 2009  8:45 AM, Michael Alipio
 
 daem0n...@yahoo.com scribbled:
  Thanks for the advice. Forgive me if I sounded like someone who's
  frustrated, couldn't do his homework asking somebody else for help.
 
  When I was learning C programming, I read that learning those difficult
  algorithms such as bubble sort, quick sort, binary search, is something
  that only programming students have to deal with.
 
 Those are not difficult algorithms. They are algorithms that any programmer
 should know. If you are learning how to program, then you are a
  programming student. However, generating a complete set of permutations
  efficiently for any size set IS a difficult algorithm.
 
  I knew I needed a recursive function, I just didn't know how to start.
  What confused me more is that the code I found is a lot different from
  what I was initially thinking. He used the builtin function substr in the
  code in a way that I couldn't figure how it worked.
 
 You don't need a recursive function. Using a recursive function can
 sometimes be an elegant method for solving a difficult problem. However,
 alternate solutions not using recursive functions can always be found.
 

One thing I should note is that from my understanding of theoretical or 
pseudo-theoretical computer science, a function or routine that just uses its 
own stack to do tree-recursion, is still recursive, only it is not 
*procedurally-recursive*. Often, people use such techniques of doing a 
recursion without a procedure that calls itself directly or indirectly, when 
writing programs in hardware-design languages such as VHDL or Verilog (or so I 
was told - I have little serious experience with them myself), or in languages 
that do not support such recursion (such as COBOL or old versions of Fortran), 
but it is a useful in languages that do support such recursion too.

In one of my C libraries ( http://fc-solve.berlios.de/ to be specific) I ended 
up porting a procedurally recursive Depth-First Search ( 
http://en.wikipedia.org/wiki/Depth-first_search ) algorithm to one that used 
my own dedicated stack of items, in order to save on CPU stack space, which is 
limited, especially the Windows' default. It turned out to be beneficial 
because that way I could do a constant time ( O(1) ) suspend and resume of the 
algorithm without resorting to setjmp/longjmp games (which I naturally would 
prefer to avoid).

In some languages (most notably Scheme), proper tail recursion is implemented 
using an implicit goto. So the following Perl program when translated to 
Scheme:

sub print_loop
{
my ($i) = @_;

print I is now $i\n;

if ($i == 0)
{
return;
}
else
{
return print_loop($i-1);
}
}

Would be equivalent to:

sub print_loop
{
my ($max_i) = @_;

foreach my $i (reverse(0 .. $max_i))
{
print I is now $i\n;  
}

return;
}

You can achieve a similar effect in Perl explicitly using goto subname; but 
I wouldn't recommend it. From what I understood, the Perl's recursion stack 
(and all the other stacks used by the Perl back-end) are implemented on the 
process heap so they cannot overflow the process stack, unless one recursively 
uses binary Perl-XS routines with Perl callbacks (e.g: those in List::Util or 
List::MoreUtils).

Regards,

Shlomi Fish

  See below:
 
  my $result = '';
 
  perm(0,2);
 
  sub perm($$){
  my ($cur,$max) = @_;
 
  if ($cur=$max){
   print $result\n;
  return;
  }
 
  for(@word){
  substr($result,$cur,1)=$_;
  perm($cur+1,$max);
  }
  }
 
  What's the use of double ($$) after sub perm?? Does it have anything to
  do with process IDs (perldoc perlvar says so)?
 
 The ($$) is a function prototype indicating that the function accepts two
 scalars. See 'perldoc perlsub' and search for 'Prototypes'.
 
  This line is also confusing:
  substr($result,$cur,1)= $_;
 
  Substr returns a list, right? The first parameter is the expression, 2nd
  is the offset, and last is the length.
  The above line is too cryptic for me. What confused me more is that the
  return value of substr was assigned the $_.
 
 No, substr returns a scalar. It can also return an lvalue if its first
 argument is an lvalue, as is being done in this case. This allows you to
 assign to a subset of a string scalar the value appearing to the right of
 the equal sign ($_), thereby replacing part of the string. You can perform
 the same function by including the replacement part as a fourth argument to
 substr. See 'perldoc -f substr' for details.
 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
The Human Hacking Field Guide - http://shlom.in/hhfg

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

-- 
To unsubscribe, e-mail

Re: About the hash case insensitive ~~~

2009-10-27 Thread Shlomi Fish
On Tuesday 27 Oct 2009 13:50:16 Majian wrote:
 Hello,all:
 I had a question about the perl hash case insensitive .
 
 And I had  this script :
 ==
 #!/usr/bin/perl
 use warnings;

Just a note - you're missing the use strict; pragma which is a big no no in 
production code. See:

http://perl-begin.org/tutorials/perl-for-newbies/part2/#page--my--use_strict--
PAGE

(Sorry for the broken link - either paste the remaining part or search for 
use strict on the page.)

People may refuse to help you with such code because it may contain many 
subtle bugs.

Regards,

Shlomi Fish

[snipped]

-- 
-
Shlomi Fish   http://www.shlomifish.org/
What Makes Software Apps High Quality -  http://shlom.in/sw-quality

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: OOB and dispatch table

2009-10-31 Thread Shlomi Fish
On Saturday 31 Oct 2009 02:38:11 Steve Bertrand wrote:
 Steve Bertrand wrote:
  Hi all,
 
  Within a CGI environment, I'm trying to do a dispatch table test, but
  can't figure out how to call the coderef as a method. Here is the
  working code. I'll describe what doesn't work afterwards:
 
  sub perform_find {
 
  my $self= shift;
 
  my $find_this   = $self-query-param( 'find_this' );
  my $search_data = $self-query-param( 'search_data' );
 
  my %find_commands = (
 
  # call by local function
  plan_by_id  = \_find_plan_by_id,
  );
 
  # and pass in $self explicitly
  $find_commands{ $find_this }( $self, $search_data );
  }
 
  __END__
 
  Things progress properly using the above. What I don't understand, is
  why I have to pass in $self as a param to the dispatch table. What
  didn't work is this:
 
 
  sub perform_find {
 
  my $self= shift;
 
  my $find_this   = $self-query-param( 'find_this' );
  my $search_data = $self-query-param( 'search_data' );
 
  my %find_commands = (
 
  # I'm trying to call the method on myself
  plan_by_id  = \{ $self-_find_plan_by_id },
  );
 

This should probably be: (untested)


plan_by_id = sub { return $self-_find_plan_by_id(@_); },


See:

* http://perl-begin.org/tutorials/perl-for-newbies/part3/#page--
refs_to_funcs--DIR

(Sorry for the broken URL)

* http://www.shlomifish.org/lecture/Perl/Newbies/lecture3/refs_to_funcs/

(Same resource - only as multiple pages).

  # ...obj passed in implicitly as expected
  $find_commands{ $find_this }( $search_data );

This should be:

{{{
$find_commands{$find_this}-($search_data)
}}}

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
The Human Hacking Field Guide - http://shlom.in/hhfg

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: Simple XML to XLS format

2009-10-31 Thread Shlomi Fish
On Saturday 31 Oct 2009 06:38:20 Ganesh Babu N wrote:
 CPAN modules are meant for Linux. It is very easy to install CPAN
 modules on Linux.
 
 Please refer http://www.cpan.org/modules/INSTALL.html
 

First of all, CPAN modules are not meant for Linux in particular. Most CPAN 
modules work best under most modern and high-quality UNIX-like operating 
systems (e.g: Linux, the BSDs, Solaris and OpenSolaris, and to a lesser extent 
HP/UX, AIX, etc.), but many can also easily work on the Microsoft Windows NT-
based operating systems. Most Perl Authors don't wish to discriminate against 
MS-Windows users unless they really need to.

Some more links than yours are:

* http://sial.org/howto/perl/life-with-cpan/

* http://sial.org/howto/perl/life-with-cpan/non-root/

* http://perl-begin.org/topics/cpan/

* http://www.shadowcat.co.uk/blog/matt-s-trout/but-i-cant-use-cpan/

 It is not easy to install CPAN modules directly on Windows. For
 windows the famous distribution is ActiveState. Please read this for
 installation of modules http://cpan.uwinnipeg.ca/par/webstart.html
 

Actually, installing CPAN modules on Windows with Strawberry Perl or cygwin's 
perl is pretty easy. It's just that ActivePerl has been heavily under-
maintained and also is dependent on various proprietary tools (such as 
Microsoft Developer Studio), and it took some time for Adam Kennedy and his 
good friends to realise that they need to start the Vanilla Perl and 
Strawberry Perl efforts to create a community-maintained and free-as-in-speech 
distribution of perl for Windows.

If you can, please use Strawberry Perl instead of ActivePerl. See:

http://win32.perl.org/wiki/index.php?title=Main_Page

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Humanity - Parody of Modern Life - http://shlom.in/humanity

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: About kernel symlink

2009-10-31 Thread Shlomi Fish
Hi Harry!

On Saturday 31 Oct 2009 18:05:09 Harry Putnam wrote:
 Looking at the kernel upgrade pages at
   http://www.gentoo.org/doc/en/kernel-upgrade.xml
 
 Its a bit confusing about the symlink creation.  I've wondered about
 it a few times.
 

This question does not seem to be about Perl. Did you intend to send it to a 
Gentoo or Linux-specific mailing list? If so please resend this message there.

Regards,

Shlomi Fish

[snipped] 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Original Riddles - http://www.shlomifish.org/puzzles/

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: Learning Perl Student Workbook

2009-11-02 Thread Shlomi Fish
On Monday 02 Nov 2009 07:19:30 Uri Guttman wrote:
  RW == Raymond Wan r@aist.go.jp writes:
 
   RW Uri Guttman wrote:
mb == mahesh bhasme mbha...@gmail.com writes:
 
   mb Hi,
   mb below link might help to u
 
that is exactly what randal said he didn't want to see, a bootleg copy
of his book. you won't be getting any more help from him and probably
most of the experts here. that copy is illegal and takes income out of
randal's pocket. do you understand what that is?
 
   RW Perhaps the blame should be equally leveled at the web site and maybe
   RW it should be brought to the attention of O'Reilly?
 
 sure o'reilly should be notified but the poster is to be blamed since he
 must know about this. randal even mentioned it not too long ago.
 
   RW Not every book that is on-line is illegal and this might confuse some
   RW people.  (Two examples I can think of are the O'Reilly Mason book and
   RW the SVN book...at least, the last time I checked.)
 
 a few of their books are released for free on the net. not any of the
 perl books afaik.
 

Some O'Reilly Perl books (not on the core topics) are available online:

* http://books.perl.org/onlinebooks

In my opinion, this a relatively poor selection of books, though I'm aware of 
some other books besides those:

http://perl-begin.org/books/

I've written about why books should be made available online here:

http://www.shlomifish.org/philosophy/philosophy/closed-books-are-so-19th-
century/

(short URL - http://shlom.in/closed-books )

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
What does Zionism mean? - http://shlom.in/def-zionism

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: the classic which is the fastest way to sort question

2009-11-09 Thread Shlomi Fish
On Monday 09 Nov 2009 19:40:29 Uri Guttman wrote:
  MA == Michael Alipio daem0n...@yahoo.com writes:
 
   MA i'm planning to sort an input file (which was File::Slurp'ed, most
   MA likely megabyte-sized file) in various ways. I did some readings
   MA and learned several methods that people have come up with in
   MA recent years. So to summarize, the default sort is fast (uses
   MA quick sort), explicit (using sub) is a bit slower, other method
   MA that uses caching is faster. Then there's Schwartzian Transform
   MA and a packed version by Guttman. Seems like everything is
   MA clear. Guttman is the fastest, until I went to cpan. Found
   MA Sort::Key, which claims to be the fastest, even faster that ST,
   MA GRT. Now, before someone says, why not try each one and see for
   MA yourself (which doing such could be another subject for me to
   MA learn), my question is this: if such faster sorting algorithms
   MA exist, why don't they just replace the default sort function in
   MA Perl?
 
 you need to understand how those techniques work and some sort theory as
 well. perl's internal sort is a generic sort on strings (using the
 quicksort algorithm). 

Just a small correction. Starting from perl-5.8.x, Perl's sort operator is 
using the Merge sort algorithm, which was shown to perform somewhat better 
than Quicksort in the benchmarks that were conducted:

http://en.wikipedia.org/wiki/Merge_sort#Comparison_with_other_sort_algorithms

Here's a little theory:

1. Merge sort has a *worst-case* complexity of O(N*log(N)), but it was 
believed to be less performant than Quicksort.

2. Quick Sort has a worst-case complexity of O(N**2) and a provably average 
case complexity of O(N*log(N)) , and was usually believed to be more 
performant than Merge sort. The standard C library (libc, the Windows C RTL, 
etc.) contains a qsort() function that implements Quicksort, but suffers from 
several philosophical limitations. perl 5 (the Perl 5 implementation) used to 
use qsort() up to version 5.005 or so, when it was replaced with a custom 
function.

Some of the traditional Quick Sort's worst (O(N**2)) performance is when it is 
used to sort in-order or close-to-in-order data, though some of the variations 
of it can be avoided.

3. Merge sort can also be efficiently used for sorting linked-lists as opposed 
to random-access arrays.

4. Generally, with small data sets, it is a better idea to use a naïve O(N**2) 
sorting algorithm such as Insertion Sort (which is generally better than 
Bubble Sort and saner).

5. Given some known assumptions on the data, one can sometimes sort at a 
better asymptotic complexity than O(N*log(N)):

* http://en.wikipedia.org/wiki/Counting_sort

* http://en.wikipedia.org/wiki/Radix_sort

--

Oh and general sort on strings should be general sort on scalars, though I 
suppose that's what you meant. Using perl's || operator one can conviently 
sort based on several aspects. E.g:


my @sorted_records =
(sort 
{ 
($a-{'last_name'} cmp $b-{'last_names})
||
($a-{'first_name'} cmp $b-{'first_name'})
||
($a-{'age'} = $b-{'age'})
}
@records)


(Untested.)

Too bad the || operator is magical in Perl and cannot be easily extended in 
user-land, though you can do something similar with or(sub { ... }, sub { ... 
}, sub { ... }, sub { ... }).

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Original Riddles - http://www.shlomifish.org/puzzles/

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: about signal

2009-11-18 Thread Shlomi Fish
Hi gaochong!

I should first note that you've placed a one line separator between each two 
consecutive lines which makes your message harder to read.

On Wednesday 18 Nov 2009 09:24:44 gaochong wrote:
 #!/usr/bin/perl -w
 
 
 
 use strict;
 

use strict and warnings - that's good.

 
 
 $SIG{INT}=\stop;
 
 $|=1;
 
 my $count=3;
 
 while ($count) {
 
 print hello\n;
 
 sleep 1;
 
 }
 
 
 
 sub stop {
 
 $SIG{INT}=\stop;   -here  why set this
 ?  if no ,the result is same .
 

This is required for portability. From what I recall, on some operating 
systems, you need to reassign the signal every time it is called. So it's a 
good practice to include it.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Parody on The Fountainhead - http://shlom.in/towtf

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: the question of one program

2009-11-19 Thread Shlomi Fish
On Thursday 19 Nov 2009 16:54:00 gaochong wrote:
 Now I have see the following page ,but I have some question and need help .
 
 http://www.cpan.org/authors/id/S/SU/SUJAI/Process-Detail-0.1.pl
 

From a quick look, this script seems awful:

1. No use strict; and use warnings;.

2. uses Switch.pm.

3. Uses bareword file-handles.

4. No three-args open.

I would suggest to avoid using it because it's not modern perl.

 
 
 first,what is the meaning of  if($pcs =~ /(\d+)/  $pcs =~ /\./) ,I can’t
 understand the re /\./
 

. matches any character (except possibly newline, etc., but sometimes also 
that if you use m{...}s). \. inside a regex matches an actual . (period, 
dot, full stop etc. - http://en.wikipedia.org/wiki/Full_stop )


 
 
 sub hidden
 
 {
 
 print \n##Hidden processlist###\n\n;
 
 foreach $pcs (readdir(DIR))
 
 {
 
 if($pcs =~ /(\d+)/  $pcs =~ /\./)
 
 {
 
 detailedview($pcs);
 
 }
 
 }
 
 }
 
 
 
 the second , @array=split(/([A-Z]+(_|[A-Z])+\=.[^A-Z]+)/,$_);  
  also the re \=.[^A-Z]+ what’s it ?

\= is an actual =. A = would be fine here, too. . is any character 
except a newline. [^A-Z] is any character except the uppercase Latin ASCII 
letters (A, B, C...Z). + is one or more when applied to the 
suffix. You can see signs of ancient perl in this expression, because it 
uses several capturing parentheses ((...)) instead of clustering ones 
((?:...)).

http://www.shlomifish.org/lecture/Perl/Newbies/lecture2/regexps/next_step.html
 
 
 
 
 
 open(FILE,$envir);

This should better be:


open my $file, , $envir
or die $!;



This script is horrible. Avoid it.

Regards,

Shlomi Fish

 while(FILE)
 {
 @array=split(/([A-Z]+(_|[A-Z])+\=.[^A-Z]+)/,$_);
 
 thanks
 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
http://www.shlomifish.org/humour/ways_to_do_it.html

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: Perl - Read and Write Multi-Language text (Scandanavian,German)

2009-11-26 Thread Shlomi Fish
On Wednesday 25 Nov 2009 15:15:19 CM wrote:
 Deal all,
 
 INFO uname -a = Linux perlsrv 2.4.27 #1 Tue Sep 23 15:34:56 CEST
 2008 i686 GNU/Linux
 INFO perl -v = This is perl, v5.8.4 built for i386-linux-thread-
 multi

1. Linux Kernel 2.4.27 is incredibly old:

http://en.wikipedia.org/wiki/Linux_kernel#Timeline

There's already kernel 2.4.37 and kernel 2.6.31.6. Please upgrade, for your 
own good.

2. perl-5.8.4 is very old as well. There's already 5.8.9 and 5.10.1.

---

Which system is this? Is it RHEL / CentOS ?

I think both of these should not pose a problem in what I'm saying.

 
 I  am seeking advice on  how to  generate multi-language output in
 Perl.
 
 The task here is to generate a single page of HTML, PDF and  plain
 text files with each run of the Perl script.
 Each of the above has to be in the language  chosen by the user in a
 web-interface.
 The possible choices are : Danish, Finnish , Swedish
 Based on the language, I would like to read  text from a file
 containing language specific characters (like AE and umlaut ) and
 generate PDF,HTML and plain text output.
 
 
 
 My questions are:
 - How do I know if my OS supports printing of these languages

Look at your distribution's documentation. It should make use of CUPS ( 
http://www.cups.org/ , 
http://en.wikipedia.org/wiki/Common_Unix_Printing_System ) or something.

 - How I can type in text in a editor like  vi with Finnish/Danish/Swed
 characters

You can either use the compose key or use vim's (not vi's) Ctrl+K feature:

http://vimdoc.sourceforge.net/search.php?search=digraphsdocs=help

I have the following mapping for the compose key:


setxkbmap \
-option compose:ralt,grp:switch,grp:alt_shift_toggle,grp_led:scroll  \
-variant ,lyx \
'us,il'


Note that it also defines a hebrew keyboard which is less useful for you. You 
probably want only (untested):


setxkbmap -option compose 'us'


 - How do I enable Perl to understand that a file contains language
 specific characters.

See:

* http://perldoc.perl.org/perlunitut.html

 - And finally what should I do to ensure that the output produced by
 Perl : PDF, HTML  and plain text files dont mess up the  special
 characters
 

See above.

 
 Any advice on this is much appreciated. I know I can do  the file read/
 write operations and output generation parts with Perl with some
 effort but the language part seems quite  a challenge.
 
 I am in a situation where I do not know where to  start.
 

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Parody on The Fountainhead - http://shlom.in/towtf

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: Perl - Read and Write Multi-Language text (Scandanavian,German)

2009-11-26 Thread Shlomi Fish
Hi Chandramohan!

I'm CCing this list on this private reply. Next time please hit reply all or 
make it the default using the Google Labs interface.

On Thursday 26 Nov 2009 16:29:36 Chandramohan Neelakantan wrote:
 Hi Schlomi,
 

It's Shlomi (English spelling) - not Schlomi (German Spelling). Many 
people make this mistake.

 Many thanks for your reply.

You're welcome.

 
  1. Linux Kernel 2.4.27 is incredibly old:
  http://en.wikipedia.org/wiki/Linux_kernel#Timeline
  There's already kernel 2.4.37 and kernel 2.6.31.6. Please upgrade, for
  your own good. 2. perl-5.8.4 is very old as well. There's already 5.8.9
  and 5.10.1. ---
 
 I  do not have an option here to change/upgrade the OS.
 

I see. We may not be able to help you with problems you encounter.

  Which system is this? Is it RHEL / CentOS ?
  I think both of these should not pose a problem in what I'm saying.
 
 Debian.
 

Really? What was the last Debian that shipped with these versions of Perl and 
the Linux kernel?

What does cat /etc/debian_version say?

This seems likely that it would be an old and un-maintained version. See:

http://community.livejournal.com/shlomif_tech/36125.html

  See:
  * http://perldoc.perl.org/perlunitut.html
 
 I  have been  going through the documentation for the last few days now.
 Unfortunately I am in a unique position.
 The  text for me comes various sources : which means  that
 standardization of everything is also not an option as there are many
 many parties here.
 (For example, I would have a non-Danish speaker to write Danish  text
 and  send it to me).
 
 I hit on an idea that each text file coming from different sources will
 have the Unicode UTF8 hex string of all the special characters.
 See here. http://lwp.interglacial.com/appf_01.htm
 
 For example the Danish A-ring ( A with a ring on top ) in the text file
 will be written as : 0xc30x85. This was found to be acceptable by all
 parties.
 
 Now the question is,  I will have a text file with lots of English
 langauge alphabets along with the special characters written as above.
 Using File i/o, I will have to  dynamically identify the special
 characters and print the equiavalent characters in PDF,HTML files.
 
 Any ideas?
 

You can use regexes to match specific characters. But generally your converter 
(e.g: of a http://en.wikipedia.org/wiki/Lightweight_markup_language ) wil ldo 
that for you. Do you need to guess the language of the document? I still don't 
understand exactly what you want to do.

Regards,

Shlomi Fish

 Your help much appreciated.
 
 Thanks  regards
 CM
 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
The Human Hacking Field Guide - http://shlom.in/hhfg

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: Perl - Read and Write Multi-Language text (Scandanavian,German)

2009-11-27 Thread Shlomi Fish
Hi CM!

On Thursday 26 Nov 2009 18:42:30 CM wrote:
  It's Shlomi (English spelling) - not Schlomi (German Spelling). Many
  people make this mistake.
 
 My apologies.
 
  What does cat /etc/debian_version say?
 
 4.0
 
   I hit on an idea that each text file coming from different sources will
   have the Unicode UTF8 hex string of all the special characters.
   See here.http://lwp.interglacial.com/appf_01.htm
  
   For example the Danish A-ring ( A with a ring on top ) in the text file
   will be written as : 0xc30x85. This was found to be acceptable by all
   parties.
  
   Now the question is,  I will have a text file with lots of English
 
  You can use regexes to match specific characters. But generally your
  converter (e.g: of
  ahttp://en.wikipedia.org/wiki/Lightweight_markup_language) wil ldo that
  for you. Do you need to guess the language of the document? I still don't
  understand exactly what you want to do.
 
 Lets say a line contains this text in a file.
 
 This is a line of text containing  0xc30x86n exotic character.
 
 How can I read this line from a file and evaluate this on the fly to:
 
 This is a line of text containing  AEn exotic character.( AE here is
 the fused AE in Danish)
 

If I understand you correctly, then you can use the chr() built-in function:

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

Possibly with some regular expressions' patterns match.

Regards,

Shlomi Fish

 
 Hope this explanation was clear!
 Chandra
 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Original Riddles - http://www.shlomifish.org/puzzles/

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: dcc chat example

2009-11-27 Thread Shlomi Fish
On Friday 27 Nov 2009 12:49:28 Rob Coops wrote:
 On Fri, Nov 27, 2009 at 11:26 AM, Kammen van, Marco, Springer SBM NL 
 
 marco.vankam...@springer.com wrote:
  Absolutely no'one with a example or hint in the right direction???
 
  :-(
 
  -
  Marco van Kammen
  Springer Science+Business Media
  System Manager  Postmaster
  -
  van Godewijckstraat 30 | 3311 GX
  Office Number: 05E21
  Dordrecht | The Netherlands
  -
  tel
   +31(78)6576446
  fax
   +31(78)6576302
 
  -
  www.springeronline.com
  www.springer.com
  -
 
 
 
  -Original Message-
  From: Kammen van, Marco, Springer SBM NL [mailto:
  marco.vankam...@springer.com]
  Sent: Monday, November 23, 2009 2:18 PM
  To: beginners@perl.org
  Subject: dcc chat example
 
  Hi All,
 
 
 
  I've been looking at this for ages.
 
  Does anyone have a working script or example of how to use a dcc chat
  while already connected to a irc server.
 
  Without the use of additional modules like Net::IRC.
 
 
 
  I guess I need to use either IO::Multiplex or IO::Select but I can't get
  it to work.
 
  As soon as I connect the second socket and read/write to it the first
  socket (the one with the irc server session) blocks
 
 
 
  I will e-mail the code on request..
 
 
 
  Thanks  Regards,
 
 
 
  -
 
  Marco van Kammen
  Springer Science+Business Media
  System Manager  Postmaster
 
  -
 
  van Godewijckstraat 30 | 3311 GX
  Office Number: 05E21
  Dordrecht | The Netherlands
 
  -
 
  tel
 
   +31(78)6576446
 
  fax
 
   +31(78)6576302
 
  -
 
  www.springeronline.com http://www.springeronline.com
  www.springer.com http://www.springer.com/
 
  -
 
 
 
 
 
 
  --
  To unsubscribe, e-mail: beginners-unsubscr...@perl.org
  For additional commands, e-mail: beginners-h...@perl.org
  http://learn.perl.org/
 
 Hi Marco,
 
[snip]
 Anyway, if you are looking for example code why not have a look at the
 Net::IRC::DCC module which most likely will provide you exactly with the
 information you are looking for.
 

I should note that using Net::IRC is no longer recommended:

http://search.cpan.org/dist/Net-IRC/

Reading from there:


NAME ^

Net::IRC - DEPRECATED Perl interface to the Internet Relay Chat protocol
USE THESE INSTEAD ^

This module has been abandoned and is no longer developed. This release serves 
only to warn current and future users about this and to direct them to 
supported and actively-developed libraries for connecting Perl to IRC. Most 
new users will want to use Bot::BasicBot, whereas more advanced users will 
appreciate the flexibility offered by POE::Component::IRC. We understand that 
porting code to a new framework can be difficult. Please stop by #perl on 
irc.freenode.net and we'll be happy to help you out with bringing your bots 
into the modern era.


Regards,

Shlomi Fish


 Regards,
 
 Rob
 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
What does Zionism mean? - http://shlom.in/def-zionism

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: Separating DB operations out of program code

2009-11-28 Thread Shlomi Fish
Hi Dermot!

On Saturday 28 Nov 2009 13:53:45 Dermot wrote:
 2009/11/27 Steve Bertrand st...@ibctech.ca:
  Dermot wrote:
  2009/11/26 Scott Pham scott.p...@gmail.com:
  Have you looked at DBIx::Class?
 
  I'd 2nd that. DBIx is the way forward. You should be looking to stop
  writing SQL statements and moving towards ORM. Try the example at
  http://search.cpan.org/~frew/DBIx-Class-0.08114/lib/DBIx/Class/Manual/Ex
 ample.pod
 
  I want to thank those who responded on list, and off-list.
 
 ...
 
  Thanks for the recommendations, and if there are any contributors to
  this project or its derivatives on the list, cheers!
 
  Only a single business day of learning the basic in and outs, and I can
  see already how I've wasted thousands of man hours doing it the 'old'
  way in the past :)
 
 I see you truly hooked. I haven't seen a maintainer for DBIx on this
 list. They have a pretty active mailing list[1] and a IRC[2]. I,
 personally, find other lists less friendly than beginners. Your
 expected to know your stuff but if you have issues with DBIx that's
 the place to go.
 
 
 1) http://lists.scsys.co.uk/mailman/listinfo/dbix-class/
 2) irc.perl.org#dbix-class
 

Just a note - DBIx-Class should not be called DBIx alone. DBIx is the top-
level-namespace for DBI extensions, and it also includes such things as:

* http://search.cpan.org/dist/DBIx-Simple/

* http://search.cpan.org/dist/DBIx-Log4perl/

* http://search.cpan.org/dist/DBIx-Chart/

Calling DBIx-Class DBIx  does injustice to them all and is incorrect. DBIx-
Class however, may be abbreviated as DBIC.

Regards,

Shlomi Fish

 Dp.
 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
The Case for File Swapping - http://shlom.in/file-swap

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: REGEX first occurence

2009-12-02 Thread Shlomi Fish
On Wednesday 02 Dec 2009 16:03:53 Jackie Jackie wrote:
 I have a repeated occurrence of a word that I want to replace by another
  word.
 
 _Data_
 fish
 fish
 fish
 fish
 
 output
 fish/red fish
 fish/blue fish
 fish/yellow fish
 fish/red fish
 
 I did not find a solution. Please help me.
 

If I understand you correctly, you can use s/// with the /e flag. A tested 
example is:


#!/usr/bin/perl

use strict;
use warnings;

my $data = 'EOF';
fish
fish
fish
fish
EOF

my @prefixes = (qw(red blue yellow));

my $curr_idx = 0;
sub get_new_word
{
my $word = shift;

return $word/ . $prefixes[($curr_idx++)%3].  $word;
}

my $new_data = $data;

$new_data =~ s/(fish)/get_new_word($1)/ge;

print $new_data;


 
   __
 The new Internet Explorer® 8 - Faster, safer, easier.  Optimized for Yahoo!
   Get it Now for Free! at http://downloads.yahoo.com/ca/internetexplorer/
 

And the obligatory http://getfirefox.com/ . ;-)

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Freecell Solver - http://fc-solve.berlios.de/

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: I LOVE HASH(ES)!!! *:-D

2009-12-03 Thread Shlomi Fish
On Thursday 03 Dec 2009 06:10:46 Anant Gupta wrote:
 I second Aimee.
 Hashes are awesome.
 

I should note that we have a page about hashes on the Perl Beginners' Site:

http://perl-begin.org/topics/hashes/

It contains a presentation by Jerusalem Perl Monger about hashes that 
enumerates their main usage patterns.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Interview with Ben Collins-Sussman - http://shlom.in/sussman

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: speed test

2009-12-03 Thread Shlomi Fish
Hi matt!

On Wednesday 02 Dec 2009 18:29:53 matt wrote:
 On Dec 1, 8:58 pm, practicalp...@gmail.com wrote:
  Hello,
 
  Maybe it's not so suitable to ask this here.
  But is there a good way (code sample?) to implement a speed test
  between Perl and C?
  For a project which handles lots of data we want to know how slower
  perl is than C.
 
  Thanks.
 
 To perform the test, I'd just use 'time':
 
 test.cc:
 int main()
 {
 int a = 1 + 1;
 }
 
 test.pl:
 #!/sw/bin/perl
 $a = 1 + 1;
 

Just a few notes:

In both of these cases, the 1+1 expression should be evaluated at compile-
time by the compilers, because it contains nothing but constants. Furthermore, 
g++ may be smart enough to see that you're not doing anything with a and to 
do nothing in this case.

A more representative example would be one that inputs two integrarl arguments 
(from argv/@ARGV or STDIN) and adds them in run-time.

If you're looking for something a bit more larger in scope, see:

http://github.com/shlomif/Project-Euler-Problem-10-Comparison

I've written similar programs in C, Haskell, and Perl to compare Problem #10 
in Project Euler. The results were:


# This was ran on:
# * A Pentium 4 2.4 GHz machine with 2.5 GB of RAM
# * Running Mandriva Linux Cooker (as of 28-November-2009)
# * On top of XFCE from Cooker and very few things running in the background.
Benchmark: timing 500 iterations of c_mine, c_mine_half, c_mine_micro_opt...
c_mine: 15 wallclock secs ( 0.02 usr 0.13 sys + 12.20 cusr 2.37 csys = 
14.72 CPU) @ 33.97/s (n=500)
c_mine_half: 10 wallclock secs ( 0.02 usr 0.13 sys + 6.75 cusr 2.30 csys = 
9.20 CPU) @ 54.35/s (n=500)
c_mine_micro_opt: 15 wallclock secs ( 0.02 usr 0.13 sys + 11.34 cusr 2.36 csys 
= 13.85 CPU) @ 36.10/s (n=500)
Benchmark: timing 20 iterations of haskell_mine, haskell_zeroth, perl-10, 
perl-10_half...
haskell_mine: 135 wallclock secs ( 0.00 usr 0.00 sys + 134.71 cusr 0.70 csys = 
135.41 CPU) @ 0.15/s (n=20)
haskell_zeroth: 310 wallclock secs ( 0.00 usr 0.01 sys + 307.61 cusr 1.15 csys 
= 308.77 CPU) @ 0.06/s (n=20)
   perl-10: 95 wallclock secs ( 0.00 usr 0.01 sys + 94.14 cusr 0.30 csys = 
94.45 CPU) @ 0.21/s (n=20)
perl-10_half: 73 wallclock secs ( 0.00 usr 0.00 sys + 71.34 cusr 0.36 csys = 
71.70 CPU) @ 0.28/s (n=20)


So the Perl Benchmark.pm module (with some overhead) executed the fastest C 
program 54.35 times per second, and the fastest Perl program at 0.28 times per 
second - roughly 194.1 times faster. The Haskell program was even worse at 
0.15 times per second. I should note that the Haskell program used a different 
algorithm, but that both algorithm are functionally equivalent, and that the 
algorithm I used for C and Perl used an array / vector of bits and as a result 
would likely perform much poorly in Haskell.

 # time bash -c 'for x in {1..100}; do ./a.out; done'
 
 real0m0.167s
 user0m0.029s
 sys 0m0.138s
 
 # time bash -c 'for x in {1..100}; do ./test2.pl; done'
 
 real0m0.435s
 user0m0.154s
 sys 0m0.247s
 
 So...I've proved that in my specific environment, C is (~3x) faster
 than Perl at adding 1+1...Now as far as what tests you want to
 implement, that's up to you and your specific needs.
 

One should note that there's also the overhead of the bash loop here.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Optimising Code for Speed - http://shlom.in/optimise

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: speed test

2009-12-03 Thread Shlomi Fish
Hi Xiao!

On Thursday 03 Dec 2009 14:19:10 Orchid Fairy (兰花仙子) wrote:
 Thanks all.
 How about the files parsing with huge size (about 1T of each day)?
 
 The basic logic is:
 
 reach each line of every file (many files, each is gziped)
 look for special info (like IP, request url, session_id, datetime etc).
 count for them and write the result into a database
 generate the daily report and monthly report
 
 I'm afraid perl can't finish the daily job so I want to know the speed
 difference between perl and C for this case.
 

OK, I assume you've tested the Perl code. If not - try it, because writing it 
in Perl would take much less time than writing it in C and would also serve as 
a useful prototype.

I can imagine that Perl would be unable to handle such load. However, with 1 
TB of gzipped data, it's very possible your problem is bound by the I/O and 
gunzip-ing constraints. If so, you may need to throw better iron at the 
problem. I know many insurance companies / banks / etc. are still using IBM 
mainframe machines (zSeries, iSeries, etc.) because they have really good I/O 
which can not be easily worked around using commodity PC hardware. (I'm not 
suggesting you buy something in that excess, but you may have to buy better 
hardware of a similar form.)

That put aside, if you still want to try writing the C or C++ program, then I 
suggest looking at some of the following abstraction libraries:

http://www.shlomifish.org/open-source/portability-libs/

They are helpful and provides similar APIs to the Perl built-ins and also some 
CPAN APIs, and allow you to write Perl-like code in C, without having to 
implement the lower-level details yourself (while still being more wordy, 
verbose and with a less idiomatic syntax than with Perl, but that is expected 
of C and C++). Due to the fact they are generic and written from a general 
purpose in mind, they may incur a small run-time overhead, but I doubt it will 
break you in most cases.

Regards,

Shlomi Fish

 // Xiao lan
 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Best Introductory Programming Language - http://shlom.in/intro-lang

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: conditional index of arrays

2009-12-04 Thread Shlomi Fish
 as  scalar(@_) 

   $index[$j]=$merged;
   $i++;
   }

You should use an array of array refs instead of one big array of concatenated 
fixed-length arrays.

 
   return @index;
 
 } #end defindex
 

You should return the @index as a reference. It's faster and cleaner. Don't 
clobber the return values.

I'll try to comment on the rest of your code later on.

 [SNIP]

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
http://www.shlomifish.org/humour/ways_to_do_it.html

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: Need to process Excel sheet through Perl

2009-12-04 Thread Shlomi Fish
On Friday 04 Dec 2009 12:15:58 Rene Schickbauer wrote:
 Xiao Lan (小兰) wrote:
  On Fri, Dec 4, 2009 at 3:40 PM, Parag Kalra paragka...@gmail.com wrote:
  Hello All,
 
  I am looking for some good Perl modules to process excel sheets.
 
  Hi,
 
  If you just want a module, take a look at this one (I once used it):
 
  http://search.cpan.org/~jmcnamara/Spreadsheet-ParseExcel-0.55/lib/Spreads
 heet/ParseExcel.pm
 
 Depending on the Excel version used to generate the files and the actual
 filetype saved (OOXML anyone?), this might or might not work.
 
 If in doubt, you could use Win32::OLE (on a windows machine) to convert
 the file to a CSV-File (comma seperated values) first, take a look here:
 
 http://www.ngbdigital.com/perl_ole_excel.html
 
 Then you could use a number of CPAN modules to process the CSV. One of
 the more exotic one is DBD::CSV, where use can use the file like a
 database table ;-)
 

And another option that may work better than the Spreadsheet-ParseExcel one 
but probably not as well as the OLE solution would be to utilise 
OpenOffice.org to read the file and then save it in an easier-to-digest format 
(such as CSV or OpenDocument). It's possible OpenOffice.org may be able to 
handle more diverse Excel files than the CPAN module.

Regarding using OLE - if you're not running Windows, you can still make use of 
it to convert the XML into shape by running a network service of some sort on 
top of a different Windows machine or a virtual machine (see 
http://www.virtualbox.org/ for example).

Regards,

Shlomi Fish

 LG
 rene
 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Freecell Solver - http://fc-solve.berlios.de/

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: REGEX first occurence

2009-12-04 Thread Shlomi Fish
On Thursday 03 Dec 2009 16:10:56 Jackie Jackie wrote:
 Thanks for your help.
 
 You solve the problem with concatenate the qw (red etc) with fish. How to
  solve the problem by search and replace.
 
 
 fish/red bird
 fish/brown bear
 fish/lion
 red fish/animal
 

I don't understand. s/// is search and replace.

Regards,

Shlomi Fish

 
 
 
 
 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Rethinking CPAN - http://shlom.in/rethinking-cpan

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.

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




Re: How much time my Perl script is taking

2009-12-05 Thread Shlomi Fish
On Saturday 05 Dec 2009 17:13:31 Parag Kalra wrote:
 Hello All,
 
 I am looking for a simple way to determine the time taken by any Perl
 script.
 
 A specific module to determine the time of execution will also do.
 
 After the Perl script gets executed, at the end it should print the time it
 took to for the execution.
 
 So just like we execute SQL queries on MySQL and get the time in which the
 results were fetched, I am looking for something similar in Perl.
 
 One simple approach would be to store the system at the start and again get
 the time at the end. Subtract former from later. Do some calculations,
 formatting and get the time of execution.
 
 But is there a simpler way than this?
 

Well, on UNIXes you have the time command:

http://en.wikipedia.org/wiki/Time_%28Unix%29

If you can't use it, then I would follow your approach. Note that you can 
encapsulate it into a module which you load using use or the -M flag at 
the beginning, so you can re-use it any time. See the so-called phasers like 
BEGIN, END, etc. Just make sure you use Time::HiRes, which is core:

http://search.cpan.org/dist/Time-HiRes/

Regards,

Shlomi Fish

 Cheers,
 Parag
 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
First stop for Perl beginners - http://perl-begin.org/

Bzr is slower than Subversion in combination with Sourceforge. 
( By: http://dazjorz.com/ )

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




Re: basic issue - XSLT processing

2009-12-05 Thread Shlomi Fish
On Saturday 05 Dec 2009 19:30:59 Jakub Jezek wrote:
 I' ve written my own XSLT and I need to process it. And get output from it.
 I'm using this simple code for beginning:
 ===
 # !/usr/bin/perl
 

You should add use strict;, use warnings; and possibly also use 
diagnostics;.

 # import required modules
 # use XML::Parser;
 # use XML::XPath;
 # use XML::XPath::XMLParser;
 use XML::XSLT;

I think you should use XML::LibXSLT instead of XML::XSLT. At least that's what 
I'm using. XML::XSLT is slower and I believe it is also incomplete.

Otherwise, there are more suitable mailing lists for getting help with XSLT:

http://listserv.activestate.com/mailman/listinfo/perl-xml

http://www.google.com/search?q=xslt%20mailing%20list

I'm not saying it's off-topic here, just that you are more likely to get help 
this way.

Regards,

Shlomi Fish

[Snipped Long code]

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Freecell Solver - http://fc-solve.berlios.de/

Bzr is slower than Subversion in combination with Sourceforge. 
( By: http://dazjorz.com/ )

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




Re: Can I design a website using Perl

2009-12-06 Thread Shlomi Fish
On Sunday 06 Dec 2009 11:41:01 Parag Kalra wrote:
  Question to the OP: Why have you decided to try things out in Perl? If
  it is because you've heard something like Perl is better than PHP
  then stop and try to find out *why* and *in what situations* is Perl
  better than PHP. In the situation of a simple webpage with a simple DB
  lookup halfway down, I think PHP is probably simpler and easier to use
  than Perl. Perl becomes better than PHP in more complex situations,
  with larger websites, more complex databases and so on. Situations in
  which web development frameworks such as Catalyst become appropriate.
 
 I have picked Perl recently and have started enjoying it. So thought of
 using it instead of PHP just for educational purpose.
 
 But any-ways thanks to all for sharing and making me aware with all the
 available frameworks.
 
 Hey BTW what does OP stand for ? :). My name is Parag... :)
 

OP stands for original poster. It's Internet slang.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Original Riddles - http://www.shlomifish.org/puzzles/

Bzr is slower than Subversion in combination with Sourceforge. 
( By: http://dazjorz.com/ )

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




Re: learning perl scripting

2009-12-06 Thread Shlomi Fish
Hi Agnello!

On Sunday 06 Dec 2009 11:51:10 Agnello George wrote:
 Hi
 
 i am basically a  a system administrator, and i have just joined this new
 company where my entire team are a group pf developers + system admins and
  i am the only system admin with out programming knowledge . i know a
  little of shell scripting from my previous company and i thought shell
  scripting was king ... but having joined this company every one is using a
  lot of persl to do a lot of log parsing ... DB interaction and lot of cool
  hashes related stuff ... but last one year i am trying to learn this
  language but dont seem to get a hold of it . sometimes i fell
  shell-scripting a is a lot more better and easier .. but my aim is to
  learn perl scripting ... i mean how does one get a real hold of this
  language ... !!

We've concentrated resources for Perl beginners here:

http://perl-begin.org/

It contains links to many online resources and books.

That put aside, you really should work on writing your English text better. 
While one can understand it, the style (punctuation, capitalisation, spelling, 
etc.) is horrible.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
The Human Hacking Field Guide - http://shlom.in/hhfg

Bzr is slower than Subversion in combination with Sourceforge. 
( By: http://dazjorz.com/ )

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




Re: learning perl scripting

2009-12-06 Thread Shlomi Fish
On Sunday 06 Dec 2009 13:10:58 Erez Schatz wrote:
 2009/12/6 Shlomi Fish shlo...@iglu.org.il:
  Hi Agnello!
 
  That put aside, you really should work on writing your English text
  better. While one can understand it, the style (punctuation,
  capitalisation, spelling, etc.) is horrible.
 
 Not as horrible as the tone of this comment. In Perl we accept that
 different level of programmers speak in different dialects of Perl.
 I suggest you apply the same criteria to people who are native to
 other languages than English.
 

I'm sorry if I sounded bad and I apologise for that. 

I agree that people are allowed to speak and write in sub-optimal or not 
perfectly native English. However, Agnello's text had many anti-patterns that 
illustrated that they (he?) didn't take the time to write it properly:

1. It lacked all capitalisation - including many lowercase i's instead of 
I's.

2. It used many ellipses (dot-dot-dot - ...) and two dots - .. instead 
of full stops - ..

3. It wasn't separated into paragraphs where appropriate.

4. The punctuation was random and erratic.

Such proper negligence is unacceptable in any language, regardless of your 
level. People who read this would be more tempted (both consciously and sub-
consciously) to dismiss the writer as an idiot, and would be more inclined not 
to take them seriously.

I realise that there's what chromatic calls Baby Perl:

http://www.modernperlbooks.com/mt/2009/03/turning-baby-perl-into-grownup-
perl.html

(short URL - http://xrl.us/bgfks2 ).

However, this is bad English writing with some conscious mistakes that should 
and can be avoided. I apologise about the tone, but sloppy writing usually 
indicates sloppy programming:

* http://www.joelonsoftware.com/articles/CollegeAdvice.html

* http://catb.org/~esr/faqs/hacker-howto.html#skills4

* http://tech.groups.yahoo.com/group/hackers-il/message/817

Regards,

Shlomi Fish


-- 
-
Shlomi Fish   http://www.shlomifish.org/
Star Trek: We, the Living Dead - http://shlom.in/st-wtld

Bzr is slower than Subversion in combination with Sourceforge. 
( By: http://dazjorz.com/ )

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




Re: how to tr this?

2009-12-07 Thread Shlomi Fish
Hi Xiaolan!

On Monday 07 Dec 2009 12:20:45 Xiao Lan (小兰) wrote:
 Hello,
 
 
 I have a text whose content is like:
 
 aaaa
 bbbbaa
 aaxxxbb
 bb776yhghhaa
 
 
 I want to switch all aa and bb.
  I can handle this use regex:
 
 s/aa|bb/$ eq 'aa'?'bb':'aa'/ge;
 
 
 But how to use 'tr' doing that?
 

The short answer is that you cannot. The tr/// operator operates only on 
characters. so tr/ab/ba/ will also change ac to bc and ab to ba, etc. 
I once contemplated writing something called strtr to convert entire strings 
into different ones, but then thought it would be too much trouble for too 
little gain and that s/// can do all that and more.

Your s/// solution is OK, though you should:

1. Avoid using $ because it makes things slower globally. See the warning on 
perldoc perlvar:

http://perldoc.perl.org/perlvar.html

Instead, do:

s/(aa|bb)/$1 eq 'aa' ? 'bb' : 'aa'/ge;

2. You may opt to use a hash for more complicated substitutions.

Regards,

Shlomi Fish

 Thanks.
 
 //Xiao lan
 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Humanity - Parody of Modern Life - http://shlom.in/humanity

Bzr is slower than Subversion in combination with Sourceforge. 
( By: http://dazjorz.com/ )

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




Re: could not execute psexec

2009-12-07 Thread Shlomi Fish
On Monday 07 Dec 2009 14:29:28 perl pra wrote:
 Hi All,
 
 I need to execute *psexec.exe* which is in C:\Windows\system32 through
 perl scirpt.
 .I am getting  the error *'psexec' is not recognized as an internal or
 external command,operable program or batch file*
 
 Below is the perl script.
 

OK, a few notes on the script.

 --- SNIP
 #!/usr/bin/perl -w
 use strict;
 use warnings;

It's good that you are using strict and warnings. You don't need -w if 
you are using warnings. 

 use File::Copy;
 use File::Find;
 
  $ENV{path}= $ENV{path} . ';' .  'C:\\Windows\\System32';

It's $ENV{PATH} - not $ENV{path} - though it may not matter on Win32.

This can better be written as:

$ENV{'PATH'} .= ;C:\\Windows\\System32;

And consider using Env::Path:

http://search.cpan.org/dist/Env-Path/

 my  $cmd='psexec' .   . '' . 10.1.1.121 . ' -u ' .  Adminuser  . '
 -p ' . adminpassword . ' -w ' .  C:\\commands\\AutoIT\\ .  
 \C:\\commands\\AutoIT\\sch.bat\;
 system($cmd) or die $!;

It seems like you can use the list syntax of perldoc -f system here, which 
will save you a lot of problems. This whole code is very unreadable. 

Regards,

Shlomi Fish

 --SNIP.
 
 
 PS: If i directly run the command on dos promt it gets executed, I am
 getting error if I run the command through perl script only.
 Please help me with the below.
 
 Thanks,
 Siva
 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Star Trek: We, the Living Dead - http://shlom.in/st-wtld

Bzr is slower than Subversion in combination with Sourceforge. 
( By: http://dazjorz.com/ )

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




Re: Eval scoping question

2009-12-08 Thread Shlomi Fish
On Tuesday 08 Dec 2009 11:03:44 Anders Hartman wrote:
 Jeff Pang skrev:
  Anders Hartman:
  Hello,
 
  I which to use eval to execute subroutines dynamically.
 
  The following code snippet fails:
 
 
  #!/usr/bin/perl
 
  use strict;
  use warnings;
 
  sub asub {
our $abc;
print $abc;
  }
 
  my $abc = abc\n;
  eval asub;
  exit 0;
 
  I don't think you want an eval here.
 
  use strict;
  use warnings;
 
  our $abc = abc\n;
 
  sub asub {
print $abc;
  }
 
  asub;
 
 
  Also you may want to know something about Perl's variable scope, see:
  http://perl.plover.com/FAQs/Namespaces.html.en
 
 Thanks for the link above.
 However, I DO need to use eval because the names of the functions to call
 are determined dynamically at runtime.
 A solution has been found: If I change the line
 
 my $abc = abc\n;
 
 in the main program to
 
 our $abc = abc\n;
 
 everything works. I don't quite see why though ;-)
 

That's because our is a package-scope variable and your previous my is a 
lexical variable that just happens to live in the global scope. See:

http://perl.plover.com/FAQs/Namespaces.html

Regarding using string eval  - you can do the same using UNIVERSAL::can, 
which would be safer in this case:


__PACKAGE__-can(asub)-(@params);


Perl is a symbolic language. :-)

eval  has some legitimate uses, though, but you should be very cautious with 
it.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
My Aphorisms - http://www.shlomifish.org/humour.html

Bzr is slower than Subversion in combination with Sourceforge. 
( By: http://dazjorz.com/ )

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




Re: Eval scoping question

2009-12-08 Thread Shlomi Fish
On Tuesday 08 Dec 2009 11:46:59 Jeff Pang wrote:
 Shlomi Fish:
  Regarding using string eval  - you can do the same using
  UNIVERSAL::can, which would be safer in this case:
 
  
  __PACKAGE__-can(asub)-(@params);
 
 or define a package and use AUTOLOAD method?
 

How will the AUTOLOAD method help you here? And AUTOLOAD is almost always not 
a good idea.

Regards,

SHlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Freecell Solver - http://fc-solve.berlios.de/

Bzr is slower than Subversion in combination with Sourceforge. 
( By: http://dazjorz.com/ )

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




Re: Eval scoping question

2009-12-08 Thread Shlomi Fish
On Tuesday 08 Dec 2009 12:18:10 Jeff Pang wrote:
 Shlomi Fish:
  On Tuesday 08 Dec 2009 11:46:59 Jeff Pang wrote:
  Shlomi Fish:
  Regarding using string eval  - you can do the same using
  UNIVERSAL::can, which would be safer in this case:
 
  
  __PACKAGE__-can(asub)-(@params);
 
  or define a package and use AUTOLOAD method?
 
  How will the AUTOLOAD method help you here?
 
 sub AUTOLOAD {
  our $AUTOLOAD;
  print I see $AUTOLOAD(@_)\n;
 }
 
 asub(abc);  # prints: I see main::asub(abc)
 

And how will this help? The OP wanted to call a method by the name of asub 
by having it in a separate method. In the AUTOLOAD function you'll have a 
gigantic dispatch statement again.

   And AUTOLOAD is almost always not
   a good idea.
 
 Why?
 

See Perl Best Practices:

http://oreilly.com/catalog/9780596001735

Namely, AUTOLOAD slows down the method lookup considerably, and can cause many 
subtle bugs in the mis-spelling of methods and other subroutines.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Interview with Ben Collins-Sussman - http://shlom.in/sussman

Bzr is slower than Subversion in combination with Sourceforge. 
( By: http://dazjorz.com/ )

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




Re: Perl script to Diff 2 Excel sheets

2009-12-12 Thread Shlomi Fish
Hi Parag!

On Saturday 12 Dec 2009 07:05:02 Parag Kalra wrote:
 Hello All,
 
 I am planning to write a small Perl script to diff 2 excel sheets
 (workbooks) using the module - Spreadsheet::ParseExcel.
 
 I am planning to implement following algorithm.
 
 What we can do is to pick up a worksheet at time (inside a loop) from each
 of the 2 workbooks and compare the cell values.
 
 1. I would start with storing the cell values inside 2 hashes (1 hash for
 each worksheet).
 
 2. So for first worksheet, its hash would have keys like A1, A2, A3 ... B1,
 B2, B3 ... C1, C2, C3 ... etc and values of these keys would be contents of
 the corresponding cells.
 
 3. Similarly I would create another hash for corresponding worksheet of
 second workbook and it would have the same data structure as the first
  hash.
 
 4. Then I would pick corresponding keys from each hash and compare the
 contents of the related cells using 'eq' operator.
 
 And again repeat the steps from 1 to 4 for the other corresponding
 worksheets of the 2 workbooks.
 
 So what I actually want to know is that - do we already have a module that
 will do the above steps or shall I go ahead with my algorithm.
 

You might wish to look at: http://search.cpan.org/dist/Test-Differences/ and 
or some of its dependencies.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Optimising Code for Speed - http://shlom.in/optimise

Bzr is slower than Subversion in combination with Sourceforge. 
( By: http://dazjorz.com/ )

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




Re: capture error - the better way?

2009-12-15 Thread Shlomi Fish
On Tuesday 15 Dec 2009 09:50:27 Xiao Lan (小兰) wrote:
 Hello,
 
 It seems in ruby and python we have a good exception capturing way.
 The ruby's:
 
 irb(main):042:0 begin
 irb(main):043:1*   x=12/0
 irb(main):044:1 rescue
 irb(main):045:1   puts 0 div error
 irb(main):046:1 end
 0 div error
 
 The python's:
  try:
 
 ...   x=12/0
 ... except:
 ...   print 0 div error
 ...
 0 div error
 
 
 
 But in Perl I have to use an eval:
 
 # perl -e '
 eval $x=12/0;
 if ($@) { print 0 div error }'
 0 div error
 
 
 
 So what's the equivalent of perl's exception handling like python/ruby?

You can use block eval {} instead of string eval :


#!/usr/bin/perl

use strict;
use warnings;

my $x;

eval
{
$x=12/0;
};

if ($@)
{ 
print 0 div error\n;
}


One problem with that is that Perl 5's exception handling is not inherently 
object-oriented. If you'd like that (and you likely would), look at the 
following CPAN modules:

* http://search.cpan.org/dist/Exception-Class/

* http://search.cpan.org/dist/TryCatch/ (never used it though).

* http://search.cpan.org/dist/Try-Tiny/ (likewise).

There's also http://search.cpan.org/dist/Error/ , which I've used, and have 
been co-maintaining, but cannot really recommend because it is Black Magick 
and quirky.

Regards,

Shlomi Fish

 
 Thanks in advance.
 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Stop Using MSIE - http://www.shlomifish.org/no-ie/

Bzr is slower than Subversion in combination with Sourceforge. 
( By: http://dazjorz.com/ )

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




Re: capture error - the better way?

2009-12-15 Thread Shlomi Fish
On Tuesday 15 Dec 2009 14:25:28 Xiao Lan (小兰) wrote:
 On Tue, Dec 15, 2009 at 7:50 PM, Xiao Lan (小兰) practicalp...@gmail.com 
wrote:
  I did have tried that, but this will get a runtime error.
 
 Sorry this is exactly a compile-time error.
 
 # cat except.pl
 
 eval { $x=12/0 };
 print 0 div error if $@;
 
 # perl -c except.pl
 Illegal division by zero at except.pl line 2.
 
 So, can't we capture it at runtime when meeting such error?
 

No, you cannot capture compile-time errors at runtime. You'll need to make 
sure your code compiles before you run it. Note that you can capture such 
errors if you do perldoc -f require, perldoc -f do (for a filename), string 
eval , etc. at run-time, in which case perl 5 invokes its compiler to 
compile some code at run-time.

But for run-time exceptions block eval { ... } should work just as well.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Star Trek: We, the Living Dead - http://shlom.in/st-wtld

Bzr is slower than Subversion in combination with Sourceforge. 
( By: http://dazjorz.com/ )

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




Re: capture error - the better way?

2009-12-15 Thread Shlomi Fish
On Tuesday 15 Dec 2009 15:53:28 Philip Potter wrote:
 2009/12/15 Shlomi Fish shlo...@iglu.org.il:
  On Tuesday 15 Dec 2009 14:25:28 Xiao Lan (小兰) wrote:
  On Tue, Dec 15, 2009 at 7:50 PM, Xiao Lan (小兰) practicalp...@gmail.com
 
  wrote:
   I did have tried that, but this will get a runtime error.
 
  Sorry this is exactly a compile-time error.
 
  # cat except.pl
 
  eval { $x=12/0 };
  print 0 div error if $@;
 
  # perl -c except.pl
  Illegal division by zero at except.pl line 2.
 
  So, can't we capture it at runtime when meeting such error?
 
  No, you cannot capture compile-time errors at runtime. You'll need to
  make sure your code compiles before you run it. Note that you can capture
  such errors if you do perldoc -f require, perldoc -f do (for a filename),
  string eval , etc. at run-time, in which case perl 5 invokes its
  compiler to compile some code at run-time.
 
 How can Illegal division by zero be a compile-time error? It seems
 clear to me that it's a run-time error, which the optimizer has
 (wrongly) decided to raise at compile-time.
 

Well, the Perl compiler tends to collapse constants. So if it sees something 
like:


... ( CONSTANT_EXPR() / 0 ) ...


it will try to find the value of CONSTANT_EXPR() / 0 so it can optimise it 
as a constant for the interpreter, and then get a fault there. It's a standard 
optimisation technique that also exists in other compilers such as gcc that 
are collapsing such constant expressions. So it does get evaluated at compile-
time and as such should be avoided.

Regards,

Shlomi Fish

 Phil
 

-- 
-
Shlomi Fish   http://www.shlomifish.org/
The Case for File Swapping - http://shlom.in/file-swap

Bzr is slower than Subversion in combination with Sourceforge. 
( By: http://dazjorz.com/ )

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




Re: capture error - the better way?

2009-12-16 Thread Shlomi Fish
On Tuesday 15 Dec 2009 17:14:25 Philip Potter wrote:
 2009/12/15 Shlomi Fish shlo...@iglu.org.il:
  On Tuesday 15 Dec 2009 15:53:28 Philip Potter wrote:
  How can Illegal division by zero be a compile-time error? It seems
  clear to me that it's a run-time error, which the optimizer has
  (wrongly) decided to raise at compile-time.
 
  Well, the Perl compiler tends to collapse constants. So if it sees
  something like:
 
  
  ... ( CONSTANT_EXPR() / 0 ) ...
 
 
  it will try to find the value of CONSTANT_EXPR() / 0 so it can optimise
  it as a constant for the interpreter, and then get a fault there. It's a
  standard optimisation technique that also exists in other compilers such
  as gcc that are collapsing such constant expressions. So it does get
  evaluated at compile- time and as such should be avoided.
 
 I'm well aware of constant folding, and yes it is a standard
 technique. But your description of it is incorrect.

Why?

 
 If evaluating a constant expression results in a runtime exception,
 that runtime exception must happen at runtime, and not at compile
 time. In general, it is the duty of an optimizer never to change
 program behaviour, only performance.
 

But this is a case where the compiler evaluates a constant expression and it 
results in an exception. So it cannot store it as a folded constant on the 
side for the run-time place. As a result, it throws a compile-time error.

 Therefore an optimizer which tries to fold a constant expression at
 compile time only to find a divide by zero exception should write code
 which raises a divide by zero exception at runtime. Raising a divide
 by zero exception at compile time is not what the original program
 did, and so it's not what the optimizer should do either.

Why?

 
 If an optimizer *were* allowed to move runtime errors to compile time,
 it wouldn't just prevent use of 1/0. The following reasonable (if
 unrealistic) example would not be guaranteed to compile:
 
 # Check if a division will emit any sort of exception (divide by zero,
 overflow, underflow, NaN, whatever)
 sub check_division {
 my ($n, $d) = @_;
 eval { $n/$d};
 return Invalid division if $@;
 return Valid division;
 }
 
 # and elsewhere...
 
 check_division(1,0);
 
 Why? Because if a sufficiently clever optimizer saw that somewhere in
 your code you call check_division(1,0), it could decide to inline the
 function there. And once it's done that, it can propagate the
 constants 1 and 0 into the local versions of the variables $n and $d,
 producing the constant expression 1/0 within the eval block. Now it
 merrily decides to calculate this expression's value at compile time,
 only to emit a compile-time error. If this error had happened at
 runtime, the program would have caught it and functioned entirely
 correctly; but by moving the exception to compile time -- and out of
 the eval block which was supposed to catch any exceptions -- the
 program won't even compile.

Well, Perl's optimizer is not that smart. It does not inline such functions 
because it doesn't know how many places they will get called. So you're spared 
in this case.

 
 If I am supposed to defend against such an overzealous optimizer, how
 would I write code that uses any block eval to catch exceptions? A
 sufficiently advanced optimizer could always use some method like that
 described above to precalculate the results of the eval, triggering an
 exception at compile time instead of runtime. Therefore block eval
 could never be guaranteed to catch runtime exceptions!

Well, a program can always have user-input (from files, STDIN, @ARGV, etc.) 
which no compiler or optimiser can predict. Sometimes this input will trigger 
certain exceptions which cannot be folded.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Original Riddles - http://www.shlomifish.org/puzzles/

Bzr is slower than Subversion in combination with Sourceforge. 
( By: http://dazjorz.com/ )

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




Re: parsing template

2009-12-16 Thread Shlomi Fish
On Wednesday 16 Dec 2009 10:10:24 Avani wrote:
 Hi all,
 
 I am very new to perl. I have to parse template in perl.
 
 do anybody have any reference code to do it?
 
 currently I am using regular expression. Right now, i m only able to
 replace variables. HOw to do it for for loop and if conditions ?
 
 pls help me.


There are already several high-quality templating systems for Perl - please 
don't create your own custom one:

* http://search.cpan.org/dist/Text-Template/ - basically just embedded Perl.

* http://search.cpan.org/dist/HTML-Template/ - more powerful than T-T but 
quite quirky.

* http://template-toolkit.org/ - very powerful and my personal favourite.

There are many others, but these are the most popular ones. Please use one of 
those. Also see:

http://www.shlomifish.org/humour/fortunes/sharp-perl.html#many-types-of-wheels

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Best Introductory Programming Language - http://shlom.in/intro-lang

Bzr is slower than Subversion in combination with Sourceforge. 
( By: http://dazjorz.com/ )

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




Re: characters encode

2009-12-16 Thread Shlomi Fish
On Wednesday 16 Dec 2009 13:49:19 Xiao Lan (小兰) wrote:
 Hello,
 
 What's the standard way to encode a whole document to utf8 (or other
 encoding mode)?
 
 For example, I want to encode a document which is gb2312 encoded
 originally to utf8, I could do:
 
 perl -MEncode -ne 'print encode(utf8,decode(gb2312,$_))' 1.txt  2.txt
 
 (here 1.txt is the gb2312 one, 2.txt is utf8 one.)
 

This is fine.

 But is there a better or more standard way to do it?
 

Not in Perl. The Encode module also gives you a from_to wrapper, but what 
you've done would be equivalent to using it.

 Thanks for this and for all the before of your helps.
 
 // Xiao-Lan
 

Regards,

Shlomi Fish


-- 
-
Shlomi Fish   http://www.shlomifish.org/
The Case for File Swapping - http://shlom.in/file-swap

Bzr is slower than Subversion in combination with Sourceforge. 
( By: http://dazjorz.com/ )

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




Re: being smart about script structure

2009-12-16 Thread Shlomi Fish
On Wednesday 16 Dec 2009 16:57:01 Bryan R Harris wrote:
 [stuff cut out]
 
  For example, if I'm populating a complex variable @d with
  lots of pointers,
  hashes, arrays, etc. within, if I populate that within a
  subroutine, how do
  I get it back out conveniently without it making a whole
  nother copy of it
  outside?  If it's 500 MB, isn't that horribly inefficient?
  Plus, I have to
  keep track of it.
 
  You pass as a refernce as ni
  called_sub(\...@d);
  Now when you update, you are updating @d and not a copy.
 
   If you have any questions and/or problems, please let me know.
   Thanks.
 
  Wags ;)
  David R. Wagner
 
 So let's say I pass a reference to an array:
 
my @d = (1,2,3);
called_sub(\...@d);
 
 ... but then in called_sub, accessing that gets a lot noisier, right?
 
sub called_sub {
my $d = shift;
push @{$d}, 2;  # I'd rather be able to use @var instead of @{$var}
}
 
 Is there any way to make a new variable, @something, that is just another
 name for the array that was passed in by reference?  Since I'm building a
 complex data structure, having to include all those @{}'s can get annoying.

First of all, often just @$d instead of @{$d} will work too. This will 
make things a little less noisy. Otherwise, you can try using perltie 
(possibly not very recommended) to tie a regular variable into the reference. 
Alternatively, you can use this module:

http://search.cpan.org/dist/Lexical-Alias/

Or another option I can think of is to create an object to wrap the operations 
around the reference, and use methods on it:


my $d = MyArrayHandle-($d_param);

$d-push(@other_array);


TIMTOWTDY. And in Perl 6 one will be able to pass arrays as first-order 
parameters to the subroutine.

 
 Also, if called_sub modifies that array that was passed in by reference,
 does it stay changed outside the subroutine?  Or do I have to return
 something from the subroutine and capture it on the outside?

It stays changed outside the subroutine:


#!/usr/bin/perl

use strict;
use warnings;

sub change_array_ref
{
my $a_ref = shift;

$a_ref-[5] = 5_000;

return;
}

my @array = (1 .. 10);

change_array_ref(\...@array);

print join(, , @array), \n;


prints:


1, 2, 3, 4, 5, 5000, 7, 8, 9, 10


That's part of the point of references. If you're interested in having a 
temporary variable, you can use a shallow copy ([ @{$array_ref} ]) or a deep 
copy - see perldoc Storable.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Star Trek: We, the Living Dead - http://shlom.in/st-wtld

Bzr is slower than Subversion in combination with Sourceforge. 
( By: http://dazjorz.com/ )

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




Re: Can you please Help perl readdir multiple folders and files with pre same name

2009-12-17 Thread Shlomi Fish
On Thursday 17 Dec 2009 17:07:19 Simphiwe Mkhize wrote:
 Please Help
 
 I have multiple folders want to read trough each folder and search for
  certian file. I have code which is working fine but does not do what I
  want. I dont want to hard code path as it read different folder within

You can input it from the command-line using @ARGV:


my ($directory_to_search) = @ARGV;

# Do something with $directory_to_search


Now a few comments on your code:

1. You should add use strict; and use warnings; at the top and fix all 
problems that they report.

 
 sub get_phone_log {
 #--
  
 $p_dir=D:/43895 ;

Use my here.

  print  $p_dir;

You probably want:


print $p_dir, \n;
L

here instead.

 opendir(DIR, $p_dir) or die cant open directory: $!\n;
 

Use lexical dir-handles. Kudos for the or die.

 while(defined($folder = readdir(DIR))) {
   if (length $folder  5)
   {
 print $folder;

Again \n;

   }
if (substr($folder,0,8) eq 'PHONELOG') {
 print_out_contents;
 }
 }

This is more idiomatically written as:

if ($folder =~ /\APHONELOG/)
{
}

And please don't use leading ampersands in subroutine calls:

http://www.perlfoundation.org/perl5/index.cgi?subroutines_called_with_the_ampersand

If it's an OS with case-insensitive filenames, you should use the /i flag:

 ... =~ /\Aphonelog/i

 
 closedir(DIR) ;
 
 #--
  }
 
 sub print_out_contents {
 #--
  
 my $phonelog = $p_dir/$folder;

Please don't use such #--- comments before and after the 
beginning of the block. They make the code mcuh harder to follow.

 
 open  (P1FILE, $phonelog) or die can't open $phonelog: $!;

Use lexical filehandles, and three args open:

http://stackoverflow.com/questions/1479741/

 $phonelog  is probably better written as just  $phonelog .

 
 flock (P1FILE, LOCK_SH) or die can't lock $phonelog: $!;
 
 while (P1FILE)

It's better to do:


while (my $line = $p1file)
{


instead and use $line instead. $_ can be destroyed way too easily.

 {
 chomp;
 @linex = split(/\|/);
 plfields;
 
  build_days;

@linex is a package variable - it should be a lexical - declared with my. 
Either pass it to the functions by reference or declare them after its 
declarations.

And don't use call-with-ampersand

 }
 
 close   (P1FILE);
 
 #--
  }
 
 
 #--
  sub plfields {
 #--
 
 
 $plcallername= $linex[0];
 $plcallerphone   = $linex[1];
 $plcalleremail   = $linex[2];

This is better done as:


my ($plcallername, $plcallerphone, $plcalleremail) = @lines;


That way it is easier to insert a variable in between.

You should also use underscores, because several words concatenated like that 
are hard to read. 

 
 $plsentdate  = $linex[3];
 $plsentdate_ccyy = substr($plsentdate,0,4) ;
 $plsentdate_yy   = substr($plsentdate,2,2) ;
 $plsentdate_mm   = substr($plsentdate,4,2) ;
 $plsentdate_dd   = substr($plsentdate,6,2) ;

This is better done using a regex with {4} , {2}, etc.

 
 $pltime  = $linex[4];
 $plfilebase  = $linex[5];
 $pltext  = $linex[6];
 

Again, use the list form.

And make these variables lexicals - using my.

 ($plfilebase_type,$plfilebase_num,$plfilebase_name) = split (/\_/,
  $plfilebase);
 

Why are you using /\_/ instead of /_/, or /\\_/? 

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
The Case for File Swapping - http://shlom.in/file-swap

Bzr is slower than Subversion in combination with Sourceforge. 
( By: http://dazjorz.com/ )

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




  1   2   3   4   5   6   7   8   9   10   >