Re: yet another question
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: yet another question
From: Slick 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? It sounds to me like you are looking at Perl as a solution, but you haven't recognized a problem for it to solve. I suspect most of us have done it the other way around. My job is solving problems. For a long time the primary problem was lack of equipment to exercise servers, or the lack of space for that equipment. For example, I have written scripts that emulate a variety of cash registers and credit card terminals. These scripts open socket connections via TCP/IP and send messages that appear to be from real terminals. I can vary the frequency of messages, the number of terminals, the payment selection and a variety of other parameters. This allows me to do a wide range of functional tests, compatibility tests, performance tests, etc. all with a set of Perl scripts. I have also written emulations for devices that don't yet exist. By working from the protocol and message specifications I can test the interface to our transaction processors before the terminals can even be shipped by the vendors. My latest project is to use Test::Harness to drive Selenium Remote Control as it does functional and regression tests on web sites. The Selenium IDE captures the manual test as a macro and exports it to Perl. I then add additional validations, input some variables from the environment and put it into a test directory to add to the growing suite of tests. What problems do you need to solve? Bob McConnell -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Fw: yet another question
Slick wrote: Got another question that I have been trying to wrap my mind around. About @argv. Now it says from I understand and read it access information from the command prompt. How exactly does it work? Is it it's own database? Or am I mistake, I know this may be a crazy question to ask. When you start a program, either via a system() call or via a shell, you can provide arguments to that program. For example, on Windows XP: C:\Documents and Settings\dpchristecho one two three one two three When I typed the first line (echo one two three) and pressed the Enter key, Command Prompt parsed my input, decided that echo was a command, decided that one, two, and three were arguments, and invoked a system() API call to start the requested program with the provided arguments. Inside echo, the arguments were made available according to the conventions of the programming language that echo was written in. The program was free to use the arguments as desired. In this case, echo output the arguments to the console as the second line (one two three). Inside a Perl script, arguments are made available as the contents of the @ARGV array. Your script is free to read the size and contents of the @ARGV array using all the capabilities of the Perl programming language, but attempting to change the size and/ or contents of @ARGV will cause problems; @ARGV should be treated as read-only. (The above explanations are simplified for clarity.) HTH, David -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
yet another question
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? Any tips here would be appriciated. Jason H. Owens
Re: yet another question
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? I really suggest you go here and type out and run all the examples as a starter. http://perl-begin.org/ You will learn all the mistakes you can make typing up programs and at the same time learn the syntax Then after a while, you might want to look at your access log if you are running servers and write a program as to who is trying to infect your machine, or trying to break in. Just try it, just do it, every one has their own preferred way of doing things -- Owen -- 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
Slick wrote: 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? As they say: Necessity is the mother of invention. I write Perl scripts because I need to get something done with my computers. Monotonous, repetitive tasks are good candidates. For example, copying file trees to a backup drive, making a tar / gzip archive of some files with a date/ time stamp in the archive name, and shutting down a network of computers in the proper order. In fact, I've written and re-written those scripts dozens of times (as my needs change/ expectations increase and as I learn more about Perl). I then write one script to rule them all, so at the end of the day I can launch one script, turn off the monitor, and go to bed. :-) The steps are: 1. Get an idea -- e.g. Hey, I bet I could write a Perl script to do this... (need). 2. Research in exact detail what it takes to make this happen -- e.g. data, algorithms, sequence of steps, command syntax, reference information, etc. (analysis). 3. Figure out how to accomplish this in Perl (design and implementation): a. One approach is to break down the overall process into smaller steps and solve them one at a time (procedural or structured programming). This is the traditional approach, and how I learned to program. b. Another approach is to model the system as objects that contain both data and the operations that act upon that data (object-oriented programming). This is a newer approach, and makes it easier to solve larger and more complex problems. I prefer books for learning and for reference, and found Learning Perl, Programming Perl, and especially The Perl Cookbook to be invaluable when it came time to start writing Perl code. I still refer to the later two often. When you're ready for libraries (modules), object-oriented Perl, automated testing, etc., get Intermediate Perl. Another aspect to #3 is learning to leverage all the free Perl scripts and modules that are available on the Comprehensive Perl Archive Network: http://www.cpan.org/ Data::Dumper is one such module. It is included in the base Perl distribution, so you don't have to worry about downloading/ installing it. I find it invaluable for debugging (the old-fashioned way, with print statements): 2009-10-06 20:56:25 dpchr...@p43400e ~ $ cat foo #! /usr/bin/perl -w use strict; use warnings; use Data::Dumper; my $debug = 1; print join( , __FILE__, __LINE__, Data::Dumper-Dump([...@argv], [qw(*ARGV)]) ) if $debug; 2009-10-06 20:56:29 dpchr...@p43400e ~ $ ./foo -x -y 'hello, world!' 123 ./foo 8 @ARGV = ( '-x', '-y', 'hello, world!', '123' ); HTH, David -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Fw: yet another question
Thanks David. Got another question that I have been trying to wrap my mind around. About @argv. Now it says from I understand and read it access information from the command prompt. How exactly does it work? Is it it's own database? Or am I mistake, I know this may be a crazy question to ask. Jason H. Owens - Forwarded Message From: David Christensen dpchr...@holgerdanske.com To: Slick jho251...@yahoo.com Cc: beginners@perl.org Sent: Tue, October 6, 2009 11:01:08 PM Subject: Re: yet another question Slick wrote: 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? As they say: Necessity is the mother of invention. I write Perl scripts because I need to get something done with my computers. Monotonous, repetitive tasks are good candidates. For example, copying file trees to a backup drive, making a tar / gzip archive of some files with a date/ time stamp in the archive name, and shutting down a network of computers in the proper order. In fact, I've written and re-written those scripts dozens of times (as my needs change/ expectations increase and as I learn more about Perl). I then write one script to rule them all, so at the end of the day I can launch one script, turn off the monitor, and go to bed. :-) The steps are: 1. Get an idea -- e.g. Hey, I bet I could write a Perl script to do this... (need). 2. Research in exact detail what it takes to make this happen -- e.g. data, algorithms, sequence of steps, command syntax, reference information, etc. (analysis). 3. Figure out how to accomplish this in Perl (design and implementation): a. One approach is to break down the overall process into smaller steps and solve them one at a time (procedural or structured programming). This is the traditional approach, and how I learned to program. b. Another approach is to model the system as objects that contain both data and the operations that act upon that data (object-oriented programming). This is a newer approach, and makes it easier to solve larger and more complex problems. I prefer books for learning and for reference, and found Learning Perl, Programming Perl, and especially The Perl Cookbook to be invaluable when it came time to start writing Perl code. I still refer to the later two often. When you're ready for libraries (modules), object-oriented Perl, automated testing, etc., get Intermediate Perl. Another aspect to #3 is learning to leverage all the free Perl scripts and modules that are available on the Comprehensive Perl Archive Network: http://www.cpan.org/ Data::Dumper is one such module. It is included in the base Perl distribution, so you don't have to worry about downloading/ installing it. I find it invaluable for debugging (the old-fashioned way, with print statements): 2009-10-06 20:56:25 dpchr...@p43400e ~ $ cat foo #! /usr/bin/perl -w use strict; use warnings; use Data::Dumper; my $debug = 1; print join( , __FILE__, __LINE__, Data::Dumper-Dump([...@argv], [qw(*ARGV)]) ) if $debug; 2009-10-06 20:56:29 dpchr...@p43400e ~ $ ./foo -x -y 'hello, world!' 123 ./foo 8 @ARGV = ( '-x', '-y', 'hello, world!', '123' ); HTH, David -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Fw: yet another question
At 9:10 PM -0700 10/6/09, Slick wrote: Thanks David. Got another question that I have been trying to wrap my mind around. About @argv. Now it says from I understand and read it access information from the command prompt. How exactly does it work? Is it it's own database? Or am I mistake, I know this may be a crazy question to ask. The @ARGV array (case matters) contains the command-line arguments with which the program was called. For example, if you have a Perl program myprog.pl and execute it this way from a command prompt: perl myprog.pl command line arguments then the @ARGV array contains three elements, just as if you had the line @ARGV = ( 'command', 'line', 'arguments' ); at the beginning of your program. There is no database involved. The @ARGV array is a normal, global array in the main package and can be accessed in your program like any other array. You can read about @ARGV and many other special Perl variables in the 'perlvar' section of the built-in Perl documentation, available from a shell with perldoc perlvar -- Jim Gibson j...@gibson.org -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Yet another question on perl modules
Hello everyone, Most modules I run across have a BEGIN block containing some variable declarations, module loaders etc. Although I understand what BEGIN is (code being evaluated immediately after it is parsed), I miss the point of the excercise. For example: package csv_generator; use Text::CSV_XS; our $ERROR; sub new { my $class = shift; return (bless {}, $class); } sub add_line { my $self = shift; push @{$self-{pending}}, [EMAIL PROTECTED]; return 1; } sub wrap_csv { my $self = shift; my $csv = Text::CSV_XS-new; my @result; foreach my $line @{$self-{pending}} { $csv-combine (@{$line}); push @result, $csv-string(); } return (join (\n, @result)); } Where would BEGIN come to play? P.S. I know the above code is messy, without any error checking, and I might even have a typo somewhere. It is just for illustration purposes. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Yet another question on perl modules
On Thu, Jul 07, 2005 at 02:22:34AM -0400, Casey West wrote: This is a confusing question, but I think the answer is that a BEGIN block would come into play before any of these things are executed. -- Casey West Sorry :) Question is: why would I want to use a BEGIN block in the above script skeleton. What advantages would BEGIN give me that I can not have otherwise, and why most modules bear one (some more than one). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Yet another question on perl modules
On Jul 7, 2005, at 8:16, Peter Rabbitson wrote: Hello everyone, Most modules I run across have a BEGIN block containing some variable declarations, module loaders etc. Although I understand what BEGIN is (code being evaluated immediately after it is parsed), I miss the point of the excercise. It is very simple: BEGIN is appropriate when you need something to be executed at compilation time. That's it. If your code does not need anything to be executed there, then you don't need a BEGIN block. You seem to assume that the lack of BEGIN blocks in your programs is suspicious, as if you were missing something. Well, probably you don't, BEGIN blocks are not that common in everyday programming, I need them just occasionally. -- fxn -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Yet another question...
Hello Again Everyone, I do apologize for all the newbie questions but I really have to get this program written today and this list is my only live resource besides Google. I'll try to keep my questions to a minimum. But here is one more if you don't mind. 1. How do I ignore case in my program so that if the filename is named 'SUPER.GIF' yet it's called as 'super.gif' in my program I can match it? Thanks in advance, Anthony
RE: Yet another question...
From what you are asking, it sounds like you are using a regex, then add a i to the end of the regex. If not a regex, then you could either uc ( upper case ) or lc ( lower case ) the inputted value and check accordingly. uc($filename) eq 'SUPER.GIF' or lc($filename) eq 'super.gif' if ( $filename =~ /super\.gif/i ) { # hit }else { # no hit } Wags ;) -Original Message- From: Anthony Saffer [mailto:[EMAIL PROTECTED]] Sent: Tuesday, September 17, 2002 09:11 To: Perl Beginners List Subject: Yet another question... Hello Again Everyone, I do apologize for all the newbie questions but I really have to get this program written today and this list is my only live resource besides Google. I'll try to keep my questions to a minimum. But here is one more if you don't mind. 1. How do I ignore case in my program so that if the filename is named 'SUPER.GIF' yet it's called as 'super.gif' in my program I can match it? Thanks in advance, Anthony ** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]