Sponsored Content
Operating Systems Linux Problem with my loop and awk script Post 302913703 by vuvuzelo on Tuesday 19th of August 2014 12:23:23 PM
Old 08-19-2014
Thanks RudiC, that's amazing. I seem to always over complicate it.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Script loop problem

I am writing a shell script that simulates the `wc -w` command without actually using wc itself. My problem is that the script will only read the first line of the file and just keep looping through it. I have tried both while and for loops and got the same result. Can anyone help? ... (1 Reply)
Discussion started by: MaxMouse
1 Replies

2. Shell Programming and Scripting

awk and loop problem

Good morning, Sir's i would like to ask for help regarding to my awk and loop problem, a script that will check my files a and b then if it will see there was a time below 3am it will echo the file that contains below 3am file, for this example it will redirect the file a to an output. $ cat a... (3 Replies)
Discussion started by: invinzin21
3 Replies

3. Shell Programming and Scripting

problem in while loop in a script

i have a script that will read each line and then grep a particular pattern and do some_stuff. Below the script while read j do q1=0 q1=`$j | grep 'INFO - LPBatch:' | wc -l` if then $j | tr -s " " | cut -d " " -f8,42,43 >> nav1.txt fi q2=0 q2=`$j | grep 'INFO - Number of Intervals... (12 Replies)
Discussion started by: ali560045
12 Replies

4. Shell Programming and Scripting

Problem with while loop in shell script

Hi All, How to read a file upto last line(End Of Line) I wrote below program: cat R2_20060719.610.txt | while read LINE do echo "$LINE" done above code reading all lines from a file and skipping last line...... is there anything wrong in my code. Please help me out from this... (20 Replies)
Discussion started by: rkrgarlapati
20 Replies

5. Shell Programming and Scripting

while loop problem in c shell script

Hi all, i write a script c shell set i = 1 while ( $i <= $#array ) echo "$array" @ i++ end i want to set it to i = i +2 in that statement . Can anybody help me? ---------- Post updated at 02:46 PM ---------- Previous update was at 02:35 PM ---------- anybody not how to solve it??? (2 Replies)
Discussion started by: proghack
2 Replies

6. UNIX for Dummies Questions & Answers

simple script with while loop getting problem

Hello forum memebers. can you correct the simple while program. #! /bin/ksh count=10 while do echo $count count='expr$count-1' done I think it will print 10 to 1 numbers but it running for indefinite times. (2 Replies)
Discussion started by: rajkumar_g
2 Replies

7. Shell Programming and Scripting

Problem passing a search pattern to AWK inside a script loop

Learning, stumbling! My progress in shell scripting is slow. Now I have this doubt: I have the following file (users.txt): AU0909,on AU0309,off AU0209,on AU0109,off And this file (userson.txt) AU0909 AU0209 AU0109 AU0309 I just want to set those users on userson.txt to "off" in... (14 Replies)
Discussion started by: quinestor
14 Replies

8. Shell Programming and Scripting

Problem Using If & For loop in AWK Command

I am parsing file for the fields using awk command, first i check 26th field for two characters using substr function if it matches then using for loop on array i search 184th field for 4 chars if it matches then i print the required fields but on execution i get the error, please help...... (5 Replies)
Discussion started by: siramitsharma
5 Replies

9. Shell Programming and Scripting

PERL script loop problem

I have written the below PERL script to reprocess messages from a failure queue. It basically browses all the messages in the failure queue to individual files in a directory and then scans those files to determine the originating queue. The script will then move each message in turn from the... (0 Replies)
Discussion started by: chris01010
0 Replies

10. UNIX for Dummies Questions & Answers

Awk: problem for loop through variable

Hi, input: AAA|1 my script (the function is just an example): gawk 'BEGIN{FS=OFS="|"} function repeat(str, n, rep, i){ for(i=1; i<=n; i++) rep=rep str return rep } { variable_1=repeat($1,$2) variable_2=repeat($1,$2+1) variable_3=repeat($1,$2+3) ... (5 Replies)
Discussion started by: beca123456
5 Replies
Moose::Cookbook::Meta::Recipe7(3)			User Contributed Perl Documentation			 Moose::Cookbook::Meta::Recipe7(3)

NAME
Moose::Cookbook::Meta::Recipe7 - Creating a glob reference meta-instance class VERSION
version 2.0205 SYNOPSIS
package My::Meta::Instance; use Scalar::Util qw( weaken ); use Symbol qw( gensym ); use Moose; extends 'Moose::Meta::Instance'; sub create_instance { my $self = shift; my $sym = gensym(); bless $sym, $self->_class_name; } sub clone_instance { my ( $self, $instance ) = @_; my $new_sym = gensym(); %{*$new_sym} = %{*$instance}; bless $new_sym, $self->_class_name; } sub get_slot_value { my ( $self, $instance, $slot_name ) = @_; return *$instance->{$slot_name}; } sub set_slot_value { my ( $self, $instance, $slot_name, $value ) = @_; *$instance->{$slot_name} = $value; } sub deinitialize_slot { my ( $self, $instance, $slot_name ) = @_; delete *$instance->{$slot_name};; } sub is_slot_initialized { my ( $self, $instance, $slot_name, $value ) = @_; exists *$instance->{$slot_name};; } sub weaken_slot_value { my ( $self, $instance, $slot_name ) = @_; weaken *$instance->{$slot_name};; } sub inline_create_instance { my ( $self, $class_variable ) = @_; return 'do { my $sym = Symbol::gensym(); bless $sym, ' . $class_variable . ' }'; } sub inline_slot_access { my ( $self, $instance, $slot_name ) = @_; return '*{' . $instance . '}->{' . $slot_name . '}'; } package MyApp::User; use metaclass 'Moose::Meta::Class' => ( instance_metaclass => 'My::Meta::Instance' ); use Moose; has 'name' => ( is => 'rw', isa => 'Str', ); has 'email' => ( is => 'rw', isa => 'Str', ); DESCRIPTION
This recipe shows how to build your own meta-instance. The meta instance is the metaclass that creates object instances and helps manages access to attribute slots. In this example, we're creating a meta-instance that is based on a glob reference rather than a hash reference. This example is largely based on the Piotr Roszatycki's MooseX::GlobRef module. Our class is a subclass of Moose::Meta::Instance, which creates hash reference based objects. We need to override all the methods which make assumptions about the object's data structure. The first method we override is "create_instance": sub create_instance { my $self = shift; my $sym = gensym(); bless $sym, $self->_class_name; } This returns an glob reference which has been blessed into our meta-instance's associated class. We also override "clone_instance" to create a new array reference: sub clone_instance { my ( $self, $instance ) = @_; my $new_sym = gensym(); %{*$new_sym} = %{*$instance}; bless $new_sym, $self->_class_name; } After that, we have a series of methods which mediate access to the object's slots (attributes are stored in "slots"). In the default instance class, these expect the object to be a hash reference, but we need to change this to expect a glob reference instead. sub get_slot_value { my ( $self, $instance, $slot_name ) = @_; *$instance->{$slot_name};; } This level of indirection probably makes our instance class slower than the default. However, when attribute access is inlined, this lookup will be cached: sub inline_create_instance { my ( $self, $class_variable ) = @_; return 'do { my $sym = Symbol::gensym(); bless $sym, ' . $class_variable . ' }'; } The code snippet that the "inline_slot_access" method returns will get "eval"'d once per attribute. Finally, we use this meta-instance in our "MyApp::User" class: use metaclass 'Moose::Meta::Class' => ( instance_metaclass => 'My::Meta::Instance' ); We actually don't recommend the use of metaclass in most cases. However, the other ways of using alternate metaclasses are more complex, and would complicate our example code unnecessarily. CONCLUSION
This recipe shows how to create your own meta-instance class. It's unlikely that you'll need to do this yourself, but it's interesting to take a peek at how Moose works under the hood. SEE ALSO
There are a few meta-instance class extensions on CPAN: o MooseX::Singleton This module extends the instance class in order to ensure that the object is a singleton. The instance it uses is still a blessed hash reference. o MooseX::GlobRef This module makes the instance a blessed glob reference. This lets you use a handle as an object instance. AUTHOR
Stevan Little <stevan@iinteractive.com> COPYRIGHT AND LICENSE
This software is copyright (c) 2011 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.12.5 2011-09-06 Moose::Cookbook::Meta::Recipe7(3)
All times are GMT -4. The time now is 12:49 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy