Sponsored Content
Full Discussion: Case inside While read File
Top Forums UNIX for Beginners Questions & Answers Case inside While read File Post 303008274 by bakunin on Wednesday 29th of November 2017 02:03:51 PM
Old 11-29-2017
Quote:
Originally Posted by drl
Apologies to jump in here with such a lengthy post.
You always have something interesting to contribute, so: you're welome!

Quote:
Originally Posted by drl
However, that 700-page tome might not be the best place for a shell scripting practices.
You noted some very good books and, yes, if we are talking shell programming they might be better places to look at compared to the Stevens. On the other hand - and this was my implicit point - I think there is something about how "good" programs are written which is absolutely independent of the programming language employed. Regardless of writing in assembler or the most high-level programming language there are some practices, some dos and don'ts which should be known by everybody before s/he even attempts "hello world". This is what Stevens talks about.

It might be easier to first read Eric Raymonds TAOUP, but - without wanting to take away from Erics achievement - at its very essence IMHO it rehashes what W. R. Stevens already laid down in his book. This is because the principles, the "rules" of our art are eternal and cast in stone.

bakunin
These 3 Users Gave Thanks to bakunin For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

case command inside awk/nawk

well I found lot of topics about awk..about if command in awk.. but I had to implement this: nawk -F"|" ' $47 ~ /0R0011/ { print > ("/home/user/M/MC.tmp" )} $47 ~ /0R0012/ { print > ("/home/user/M/DuSI.tmp" )} $47 ~ /0R0014/ { print > ("/home/user/M/FF.tmp" )} $47 ~ /0R0018/ { print >... (9 Replies)
Discussion started by: abdulaziz
9 Replies

2. Shell Programming and Scripting

Case inside case?

Im new to unix and shell scripting. I am required to write a program and im in the process of creating a menu system. I have my main menu but i want to be able to select an option that takes me onto another menu. I have tried doing this with the case statement with no luck so far. Wondering if it... (3 Replies)
Discussion started by: RAFC_99
3 Replies

3. UNIX for Advanced & Expert Users

how to grep/read a file inside compressed tgz without extract?

Hi all, I would like to ask whether in Unix shell/perl have any functions or command to allow grep/cat/read a file inside compressed .tgz without extract it? I know we can tar tvf a compressed tgz but this only allow we read the path/filename contained inside the tarball. If we want to read... (3 Replies)
Discussion started by: mayshy
3 Replies

4. Shell Programming and Scripting

multiple lines inside a case statement

echo "please enter ur choice.. 1. Make a file. 2. Display contents 3. Copy the file 4. Rename the file 5. Delete the file 6. Exit" read choice case $choice in 1 ) echo enter the file name read fname if then echo... (2 Replies)
Discussion started by: gotam
2 Replies

5. UNIX for Advanced & Expert Users

how to read a file inside jar

how to read the text file inside the jar without extracting jar. (3 Replies)
Discussion started by: karthikn
3 Replies

6. Shell Programming and Scripting

Call function inside CASE

i have a case statement which branches to different sections based on an input. Each branch needs to call a function. below is the code. FOr some reason, the code inside the function is not getting executed. the code is below for reference. in the below code echo "Function 1" which is there... (2 Replies)
Discussion started by: cvsanthosh
2 Replies

7. Shell Programming and Scripting

Nested case inside awk

please let me know if the below code could be written efficiently inside single awk case "$INP" in ksh) cat catalog | awk 'BEGIN {FS=",";} { print $2 } END {}' ;; pset) cat catalog | awk 'BEGIN {FS=",";} { print $3 } END {}' ;; dml) cat catalog | awk 'BEGIN {FS=",";} {... (2 Replies)
Discussion started by: cvsanthosh
2 Replies

8. Homework & Coursework Questions

How to read user keyboard input inside the case?

I need to Write a shell script that allows some system-administration tasks to be preformed automatically from a menu-driven interface. with automated following tasks: Copy directory tree Delete files or directories Output Information (this part is done ) *Copy directory tree The “Copy... (2 Replies)
Discussion started by: femchi
2 Replies

9. Shell Programming and Scripting

Update file record inside read loop

Hi, I am reading file records inside a while loop, and want to update the record when certain condition is met. How can I update a file while being read? I want to avoid using temporary files, copy, rename, ... while IFS=',' read -r f1 f2 do function(f1,f2) if then <add... (1 Reply)
Discussion started by: ysrini
1 Replies

10. Shell Programming and Scripting

Use sqlplus statement inside case sentence

Hello, I have a problem. I want to launch a different sql queries for different shell parameter values, something like this. #/bin/bash case $1 in "A") sqlplus -s user/pass << SQL query A; SQL "B") sqlplus -s user/pass << SQL2 ... (3 Replies)
Discussion started by: Vares
3 Replies
Moose::Manual::BestPractices(3pm)			User Contributed Perl Documentation			 Moose::Manual::BestPractices(3pm)

NAME
Moose::Manual::BestPractices - Get the most out of Moose VERSION
version 2.0603 RECOMMENDATIONS
Moose has a lot of features, and there's definitely more than one way to do it. However, we think that picking a subset of these features and using them consistently makes everyone's life easier. Of course, as with any list of "best practices", these are really just opinions. Feel free to ignore us. "namespace::autoclean" and immutabilize We recommend that you remove the Moose sugar and end your Moose class definitions by making your class immutable. package Person; use Moose; use namespace::autoclean; # extends, roles, attributes, etc. # methods __PACKAGE__->meta->make_immutable; 1; The "use namespace::autoclean" bit is simply good code hygiene, as it removes imported symbols from your class's namespace at the end of your package's compile cycle, including Moose keywords. Once the class has been built, these keywords are not needed. (This is preferred to placing "no Moose" at the end of your package). The "make_immutable" call allows Moose to speed up a lot of things, most notably object construction. The trade-off is that you can no longer change the class definition. Never override "new" Overriding "new" is a very bad practice. Instead, you should use a "BUILD" or "BUILDARGS" methods to do the same thing. When you override "new", Moose can no longer inline a constructor when your class is immutabilized. There are two good reasons to override "new". One, you are writing a MooseX extension that provides its own Moose::Object subclass and a subclass of Moose::Meta::Method::Constructor to inline the constructor. Two, you are subclassing a non-Moose parent. If you know how to do that, you know when to ignore this best practice ;) Always call the original/parent "BUILDARGS" If you "override" the "BUILDARGS" method in your class, make sure to play nice and call "super()" to handle cases you're not checking for explicitly. The default "BUILDARGS" method in Moose::Object handles both a list and hashref of named parameters correctly, and also checks for a non- hashref single argument. Provide defaults whenever possible, otherwise use "required" When your class provides defaults, this makes constructing new objects simpler. If you cannot provide a default, consider making the attribute "required". If you don't do either, an attribute can simply be left unset, increasing the complexity of your object, because it has more possible states that you or the user of your class must account for. Use "builder" instead of "default" most of the time Builders can be inherited, they have explicit names, and they're just plain cleaner. However, do use a default when the default is a non-reference, or when the default is simply an empty reference of some sort. Also, keep your builder methods private. Be "lazy" Lazy is good, and often solves initialization ordering problems. It's also good for deferring work that may never have to be done. Make your attributes "lazy" unless they're "required" or have trivial defaults. Consider keeping clearers and predicates private Does everyone really need to be able to clear an attribute? Probably not. Don't expose this functionality outside your class by default. Predicates are less problematic, but there's no reason to make your public API bigger than it has to be. Avoid "lazy_build" As described above, you rarely actually need a clearer or a predicate. "lazy_build" adds both to your public API, which exposes you to use cases that you must now test for. It's much better to avoid adding them until you really need them - use explicit "lazy" and "builder" options instead. Default to read-only, and consider keeping writers private Making attributes mutable just means more complexity to account for in your program. The alternative to mutable state is to encourage users of your class to simply make new objects as needed. If you must make an attribute read-write, consider making the writer a separate private method. Narrower APIs are easy to maintain, and mutable state is trouble. In order to declare such attributes, provide a private "writer" parameter: has pizza => ( is => 'ro', isa => 'Pizza', writer => '_pizza', ); Think twice before changing an attribute's type in a subclass Down this path lies great confusion. If the attribute is an object itself, at least make sure that it has the same interface as the type of object in the parent class. Don't use the "initializer" feature Don't know what we're talking about? That's fine. Use Moose::Meta::Attribute::Native traits instead of "auto_deref" The "auto_deref" feature is a bit troublesome. Directly exposing a complex attribute is ugly. Instead, consider using Moose::Meta::Attribute::Native traits to define an API that only exposes the necessary pieces of functionality. Always call "inner" in the most specific subclass When using "augment" and "inner", we recommend that you call "inner" in the most specific subclass of your hierarchy. This makes it possible to subclass further and extend the hierarchy without changing the parents. Namespace your types Use some sort of namespacing convention for type names. We recommend something like "MyApp::Type::Foo". We also recommend considering MooseX::Types. Do not coerce Moose built-ins directly If you define a coercion for a Moose built-in like "ArrayRef", this will affect every application in the Perl interpreter that uses this type. # very naughty! coerce 'ArrayRef' => from Str => via { [ split /,/ ] }; Instead, create a subtype and coerce that: subtype 'My::ArrayRef' => as 'ArrayRef'; coerce 'My::ArrayRef' => from 'Str' => via { [ split /,/ ] }; Do not coerce class names directly Just as with Moose built-in types, a class type is global for the entire interpreter. If you add a coercion for that class name, it can have magical side effects elsewhere: # also very naughty! coerce 'HTTP::Headers' => from 'HashRef' => via { HTTP::Headers->new( %{$_} ) }; Instead, we can create an "empty" subtype for the coercion: subtype 'My::HTTP::Headers' => as class_type('HTTP::Headers'); coerce 'My::HTTP::Headers' => from 'HashRef' => via { HTTP::Headers->new( %{$_} ) }; Use coercion instead of unions Consider using a type coercion instead of a type union. This was covered in Moose::Manual::Types. Define all your types in one module Define all your types and coercions in one module. This was also covered in Moose::Manual::Types. BENEFITS OF BEST PRACTICES
Following these practices has a number of benefits. It helps ensure that your code will play nice with others, making it more reusable and easier to extend. Following an accepted set of idioms will make maintenance easier, especially when someone else has to maintain your code. It will also make it easier to get support from other Moose users, since your code will be easier to digest quickly. Some of these practices are designed to help Moose do the right thing, especially when it comes to immutabilization. This means your code will be faster when immutabilized. Many of these practices also help get the most out of meta programming. If you used an overridden "new" to do type coercion by hand, rather than defining a real coercion, there is no introspectable metadata. This sort of thing is particularly problematic for MooseX extensions which rely on introspection to do the right thing. 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::Manual::BestPractices(3pm)
All times are GMT -4. The time now is 04:45 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy