Sponsored Content
Top Forums Shell Programming and Scripting What's going on in my scripts? Post 302188361 by tpltp on Wednesday 23rd of April 2008 08:59:30 AM
Old 04-23-2008
It makes a bit more clear to me. Thank you for your detailed explanation... I can seek for some real and good scripts, and study from the basic.

Thank you again...
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Help with scripts

script that ask for "enter a file name" and removes that file and asks for confirmation before deletion if executed the output might look as enter the filename you intent to deleted remover file? Y file deleterd I knwo the comand I would use find . -name *.* -ok rm {}\; I guess... can... (1 Reply)
Discussion started by: LiTo
1 Replies

2. Shell Programming and Scripting

Calling expect scripts from other expect scripts

Hi, First, let me explain the issue I am trying to solve. We have a lot of expect scripts with the duplicated send/expect commands. So, I'd like to be able to extract the duplicated code into the common scripts that can be used by other scripts. Below is my test where I am trying to call... (0 Replies)
Discussion started by: seva
0 Replies

3. UNIX for Dummies Questions & Answers

Profile scripts versus rc scripts....

what is the difference between login and profile scripts versus the rc scripts? (1 Reply)
Discussion started by: rookie22
1 Replies

4. Shell Programming and Scripting

Help with Script using rsh and scripts within scripts

Hi, I've written a script that runs on a Database server. It has to shutdown the Application server, do an Oracle Dump and then restart the Application server. Its been a long time since I wrote any shells scripts. Can you tell me if the scripts that I execute within my script will be executed... (3 Replies)
Discussion started by: brockwile1
3 Replies

5. Shell Programming and Scripting

Running scripts within scripts from cron

Hi all, I have set up a cron job which calls another shell script shell script which in turn calls a Java process. The cron tab looks so. 0,30 7-18 * * 1-5 /u01/home/weblogic/brp/bin/checkstatus.sh >> /u01/home/weblogic/logs/checkstatus.log The checkstatus.sh scripts looks like this. ... (4 Replies)
Discussion started by: sirbrian
4 Replies

6. Shell Programming and Scripting

Changing the Bash Scripts to Bourne Scripts:URGENT

Hi, I have to write a program to compute the checksums of files ./script.sh I wrote the program using bash and it took me forever since I am a beginner but it works very well. I'm getting so close to the deadline and I realised today that actually I have to use normal Bourne shell... (3 Replies)
Discussion started by: pgarg1989
3 Replies

7. Shell Programming and Scripting

KSH - How to call different scripts from master scripts based on a column in an Oracle table

Dear Members, I have a table REQUESTS in Oracle which has an attribute REQUEST_ACTION. The entries in REQUEST_ACTION are like, ME, MD, ND, NE etc. I would like to create a script which will will call other scripts based on the request action. Can we directly read from the REQUEST_ACTION... (2 Replies)
Discussion started by: Yoodit
2 Replies

8. Shell Programming and Scripting

Calling scripts from with scripts

Hi all, I'm wondering if you could give me some advice. I am new to scripting and am getting rather frustrated that i can get my script to call another script if certain criteria is met, via command line, but I cannot get the same script to work thru the cron jobs. My first script monitors... (8 Replies)
Discussion started by: echoes
8 Replies

9. Shell Programming and Scripting

Calling multiple scripts from another scripts

Dear all, I am working on script which call other shell scripts in a loop but problem is from second script am not able to come out. Here is the snippet:- #!/bin/bash HSFILE=/root/Test/Components.txt LOGFile=/opt/domain/AdminDomain/application/logs... (3 Replies)
Discussion started by: sharsour
3 Replies
Moose::Cookbook::Basics::Point_AttributesAndSubclassing(User Contributed Perl DocumentMoose::Cookbook::Basics::Point_AttributesAndSubclassing(3pm)

NAME
Moose::Cookbook::Basics::Point_AttributesAndSubclassing - Point and Point3D classes, showing basic attributes and subclassing. VERSION
version 2.0603 SYNOPSIS
package Point; use Moose; has 'x' => (isa => 'Int', is => 'rw', required => 1); has 'y' => (isa => 'Int', is => 'rw', required => 1); sub clear { my $self = shift; $self->x(0); $self->y(0); } package Point3D; use Moose; extends 'Point'; has 'z' => (isa => 'Int', is => 'rw', required => 1); after 'clear' => sub { my $self = shift; $self->z(0); }; package main; # hash or hashrefs are ok for the constructor my $point1 = Point->new(x => 5, y => 7); my $point2 = Point->new({x => 5, y => 7}); my $point3d = Point3D->new(x => 5, y => 42, z => -5); DESCRIPTION
This is the classic Point example. It is taken directly from the Perl 6 Apocalypse 12 document, and is similar to the example found in the classic K&R C book as well. As with all Perl 5 classes, a Moose class is defined in a package. Moose handles turning on "strict" and "warnings" for us, so all we need to do is say "use Moose", and no kittens will die. When Moose is loaded, it exports a set of sugar functions into our package. This means that we import some functions which serve as Moose "keywords". These aren't real language keywords, they're just Perl functions exported into our package. Moose automatically makes our package a subclass of Moose::Object. The Moose::Object class provides us with a constructor that respects our attributes, as well other features. See Moose::Object for details. Now, onto the keywords. The first one we see here is "has", which defines an instance attribute in our class: has 'x' => (isa => 'Int', is => 'rw', required => 1); This will create an attribute named "x". The "isa" parameter says that we expect the value stored in this attribute to pass the type constraint for "Int" (1). The accessor generated for this attribute will be read-write. The "required => 1" parameter means that this attribute must be provided when a new object is created. A point object without coordinates doesn't make much sense, so we don't allow it. We have defined our attributes; next we define our methods. In Moose, as with regular Perl 5 OO, a method is just a subroutine defined within the package: sub clear { my $self = shift; $self->x(0); $self->y(0); } That concludes the Point class. Next we have a subclass of Point, Point3D. To declare our superclass, we use the Moose keyword "extends": extends 'Point'; The "extends" keyword works much like "use base". First, it will attempt to load your class if needed. However, unlike "base", the "extends" keyword will overwrite any previous values in your package's @ISA, where "use base" will "push" values onto the package's @ISA. It is my opinion that the behavior of "extends" is more intuitive.(2). Next we create a new attribute for Point3D called "z". has 'z' => (isa => 'Int', is => 'rw', required => 1); This attribute is just like Point's "x" and "y" attributes. The "after" keyword demonstrates a Moose feature called "method modifiers" (or "advice" for the AOP inclined): after 'clear' => sub { my $self = shift; $self->z(0); }; When "clear" is called on a Point3D object, our modifier method gets called as well. Unsurprisingly, the modifier is called after the real method. In this case, the real "clear" method is inherited from Point. Our modifier method receives the same arguments as those passed to the modified method (just $self here). Of course, using the "after" modifier is not the only way to accomplish this. This is Perl, right? You can get the same results with this code: sub clear { my $self = shift; $self->SUPER::clear(); $self->z(0); } You could also use another Moose method modifier, "override": override 'clear' => sub { my $self = shift; super(); $self->z(0); }; The "override" modifier allows you to use the "super" keyword to dispatch to the superclass's method in a very Ruby-ish style. The choice of whether to use a method modifier, and which one to use, is often a question of style as much as functionality. Since Point inherits from Moose::Object, it will also inherit the default Moose::Object constructor: my $point1 = Point->new(x => 5, y => 7); my $point2 = Point->new({x => 5, y => 7}); my $point3d = Point3D->new(x => 5, y => 42, z => -5); The "new" constructor accepts a named argument pair for each attribute defined by the class, which you can provide as a hash or hash reference. In this particular example, the attributes are required, and calling "new" without them will throw an error. my $point = Point->new( x => 5 ); # no y, kaboom! From here on, we can use $point and $point3d just as you would any other Perl 5 object. For a more detailed example of what can be done, you can refer to the t/recipes/moose_cookbook_basics_point_attributesandsubclassing.t test file. Moose Objects are Just Hashrefs While this all may appear rather magical, it's important to realize that Moose objects are just hash references under the hood(3). For example, you could pass $self to "Data::Dumper" and you'd get exactly what you'd expect. You could even poke around inside the object's data structure, but that is strongly discouraged. The fact that Moose objects are hashrefs means it is easy to use Moose to extend non-Moose classes, as long as they too are hash references. If you want to extend a non-hashref class, check out "MooseX::InsideOut". CONCLUSION
This recipe demonstrates some basic Moose concepts, attributes, subclassing, and a simple method modifier. FOOTNOTES(1) Moose provides a number of builtin type constraints, of which "Int" is one. For more information on the type constraint system, see Moose::Util::TypeConstraints.(2) The "extends" keyword supports multiple inheritance. Simply pass all of your superclasses to "extends" as a list: extends 'Foo', 'Bar', 'Baz'; (3) Moose supports using instance structures other than blessed hash references (such as glob references - see MooseX::GlobRef). SEE ALSO
Method Modifiers The concept of method modifiers is directly ripped off from CLOS. A great explanation of them can be found by following this link. http://www.gigamonkeys.com/book/object-reorientation-generic-functions.html <http://www.gigamonkeys.com/book/object-reorientation- generic-functions.html> AUTHOR
Moose is maintained by the Moose Cabal, along with the help of many contributors. See "CABAL" in Moose and "CONTRIBUTORS" in Moose for details. COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Infinity Interactive, Inc.. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.14.2 2012-06-28 Moose::Cookbook::Basics::Point_AttributesAndSubclassing(3pm)
All times are GMT -4. The time now is 10:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy