Skip to main content

Perl Newbie

More
19 years 6 months ago #8379 by UHSsncmrm
Perl Newbie was created by UHSsncmrm
Please forgive me if things here sound abnormal, I don't know Perl at all. I DO know that it is a very valuable tool for automating routine tasks such as logging into routers and making changes (password management, certain stat collecting network-wide ie. IOS version info/ errors, et al.)

1. Are there any Perl scripts available for download. 2. Is there a good reference website for Perl beginners? 3. Is there a version of Perl that runs on Windows?

Thanks Folks!

A scapegoat is often as welcome as a solution...never memorize what you can look up.
More
19 years 6 months ago #8382 by DaLight
Replied by DaLight on topic Re: Perl Newbie
Yes to all of the above.

1. www.cpan.org/scripts/ for perl scripts
2. learn.perl.org/ for beginners.
3. www.activestate.com/Store/ - look for the "ActivePerl" download link. That's the free version.
More
19 years 6 months ago #8419 by TheBishop
Replied by TheBishop on topic Perl
Perl is great for network admins, you can do almost anything with it. If you have specific questions/projects then post them up so we can all have a chew on them for you.
If you are just getting started I suggest you build up a personal library of little routines. For example, write one to ping a node and set a flag if it responds. Then produce one to map a network drive, release a network drive, open and maintain a log file and so on. These will give you lots of hands-on practice while still producing something more useful than "hello world". And when you have a 'real' project to do you can re-use them
More
19 years 5 months ago #8768 by Cortes
Replied by Cortes on topic Re: Perl Newbie
Hello Everyone!

I am also new to perl and am currently doing some self teaching. One thing I am currently working on is I am trying to create a script that will examine a txt file ( in this case the job details a ciscoworks job) to find the word failed and print the line containing that word. Any thoughts? Thanks in advance.

--Cortes
More
19 years 5 months ago #8771 by nske
Replied by nske on topic Re: Perl Newbie
Well, that's simple, you just need to do the following in your script:

- have the details (filename) of the file you want to open "hardcoded" or provide a way for the user to input them at the runtime.
- loop through the text line by line, checking if your specific string "failed" is contained in each line. The full content of each line will be kept temporarilly in variable $line. You can also increment an $n integer variable to keep count of the line processed.
- in case your string-checking function returns true for a line, print whatever you want, i.e. the value of the $n and the value of $line.
- close the file
- add "sauce goodies", like colorizing your output, or adding any additional features you can think of.

That's the logical part, that should always be your fist step, as it will save you time. You do not need to plan ahead the "sauce goodies" or the additional features, unless they are major and for some reason affect the basic features. But for the first step, only design the basic features of your program too keep track easier, and the rest will fit in later.

The coding part is an other story, a bit frustrating, but only at first. It requires you to find and experiment with a number of language specific constructs (loops, statements, functions, variables, operators, etc), untill you get familiar with them and their syntax -in this particular case i.e., learn how to struct a "for" loop and an "if" statement, explore and experiment with several string and file related functions till you find the ones that suit your purpose, also see how to use variables to store various types of data and how to use operators to perform mathematical operations, like the +1 increment to the $n variable.

Each time make sure you are capable of combining what you have learned in different ways, and imagine how they could be applied for different uses, before you proceed in learning more complicate things. The best way is to always look for things as soon as you find them ahead of you, this way you remember them easier and comprehend them in practice. Finally, even if you don't understand fully a script, it can be helpful in many cases to just look at it's structure to get many quick answers. ;)
Time to create page: 0.136 seconds