Sponsored Content
Full Discussion: Shell/Perl logic for loop
Top Forums Shell Programming and Scripting Shell/Perl logic for loop Post 302639169 by clx on Friday 11th of May 2012 09:34:14 AM
Old 05-11-2012
Are you looking for something like this?

Code:
$ awk -F, 'BEGIN {while (( getline < "2" ) > 0 ){a[$1]=$2}} NR==FNR {b[$1]=$2FS$3;next} {print $1,$2,a[$2],b[a[$2]]}' OFS=, 3 1
name1,11,sub1,sc1,c1
name2,22,sub1,sc1,c1
name3,33,sub3,sc3,c3

Code:
$ cat 1
name1,11
name2,22
name3,33
$ cat 2
11,sub1
22,sub1
33,sub3
$ cat 3
sub1,sc1,c1
sub2,sc2,c2
sub3,sc3,c3

This User Gave Thanks to clx For This Post:
 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell or PERL Logic

Hello All, Currently i am working on a logic in PERL scripting ... But i am sort of stuck up, can any one please help. Here goes. 1. Search for a pattern in a file 2. If the pattern matched lets say 10 lines 2.1 Reterive the first line and check for another pattern 2.1.1 if... (1 Reply)
Discussion started by: maxmave
1 Replies

2. Shell Programming and Scripting

While Loop Logic

I would need to with making while loop logic working in shell program when I am new into the shell programing 1) I would need to try to get the file from the remote side ----need to try 15 mins apart for 4 times and terminate the program if file is not available.... I would need to know how I... (4 Replies)
Discussion started by: sambakamba
4 Replies

3. Shell Programming and Scripting

for loop logic with multiple parameters

hi, unix wizards, i have a question about the logic of my inner for loop below. first, what i am trying to do is to write a script called create_account that automatically creates mysql accounts. the user can provide a user_name or a group_id as an argument (and the script can take multiple... (1 Reply)
Discussion started by: ankimo
1 Replies

4. Shell Programming and Scripting

loop logic inside of an inline redirect?

i need to log the feedback from the ftp server as i'm performing some deletes. the only way i know of to do this is with the inline redirect << EOF ... but from there to the closing EOF, it's like i'm at the ftp command prompt, so I don't know how to have ksh script logic in there I have an... (3 Replies)
Discussion started by: tlavoie
3 Replies

5. Shell Programming and Scripting

Perl - pass shell-vars into perl for input loop

I need to process a file line-by-line using some value from a shell variable Something like:perl -p -e 's/$shell_srch/$shell_replace/g' input.txt I can't make the '-s' work in the '-p' or '-n' input loop (or couldn't find a syntaxis.) I have searched and found... (4 Replies)
Discussion started by: alex_5161
4 Replies

6. UNIX for Dummies Questions & Answers

if then else logic with while loop problem

Hi Friends, I have to do write a shell file based on one flag.If that flag value is 'N' then process look in $DATA are and the normal process continue.If vaule is 'P' then it check for the files in different location $CONV and move those file in $DATA area and rest of the process... (2 Replies)
Discussion started by: Param0073
2 Replies

7. Shell Programming and Scripting

while loop logic

Hi, Here I am trying to query database and check a value, if the value not matches then I wants to re-query the database.Once the value matches, I want to email the reqidstatus_log.txt file. Database query produces a file reqidstatus_log.txt which contains result. But the query not working as... (3 Replies)
Discussion started by: rajsp217
3 Replies

8. Shell Programming and Scripting

Shell or Perl Loop Screenshot URLs

I am trying to capture screenshots from a huge list of URLs. I am able to manually capture images of individual pages; that is, I simply run the following command to get a screenshot of Foo.com $ python /path/to/screencapture.sh http://www.foo.com I want to modify the script so that instead of... (2 Replies)
Discussion started by: chipperuga
2 Replies
Class::Trigger(3pm)					User Contributed Perl Documentation				       Class::Trigger(3pm)

NAME
Class::Trigger - Mixin to add / call inheritable triggers SYNOPSIS
package Foo; use Class::Trigger; sub foo { my $self = shift; $self->call_trigger('before_foo'); # some code ... $self->call_trigger('middle_of_foo'); # some code ... $self->call_trigger('after_foo'); } package main; Foo->add_trigger(before_foo => &sub1); Foo->add_trigger(after_foo => &sub2); my $foo = Foo->new; $foo->foo; # then sub1, sub2 called # triggers are inheritable package Bar; use base qw(Foo); Bar->add_trigger(before_foo => &sub); # triggers can be object based $foo->add_trigger(after_foo => &sub3); $foo->foo; # sub3 would appply only to this object DESCRIPTION
Class::Trigger is a mixin class to add / call triggers (or hooks) that get called at some points you specify. METHODS
By using this module, your class is capable of following methods. add_trigger Foo->add_trigger($triggerpoint => $sub); $foo->add_trigger($triggerpoint => $sub); Foo->add_trigger( name => $triggerpoint, callback => sub {return undef}, abortable => 1); # no further triggers will be called. Undef will be returned. Adds triggers for trigger point. You can have any number of triggers for each point. Each coderef will be passed a reference to the calling object, as well as arguments passed in via call_trigger. Return values will be captured in list context. If add_trigger is called with named parameters and the "abortable" parameter is passed a true value, a false return value from trigger code will stop processing of this trigger point and return a "false" value to the calling code. If "add_trigger" is called without the "abortable" flag, return values will be captured by call_trigger, but failures will be ignored. If "add_trigger" is called as object method, whole current trigger table will be copied onto the object and the new trigger added to that. (The object must be implemented as hash.) my $foo = Foo->new; # this trigger ($sub_foo) would apply only to $foo object $foo->add_trigger($triggerpoint => $sub_foo); $foo->foo; # And not to another $bar object my $bar = Foo->new; $bar->foo; call_trigger $foo->call_trigger($triggerpoint, @args); Calls triggers for trigger point, which were added via "add_trigger" method. Each triggers will be passed a copy of the object as the first argument. Remaining arguments passed to "call_trigger" will be passed on to each trigger. Triggers are invoked in the same order they were defined. If there are no "abortable" triggers or no "abortable" trigger point returns a false value, "call_trigger" will return the number of triggers processed. If an "abortable" trigger returns a false value, call trigger will stop execution of the trigger point and return undef. last_trigger_results my @results = @{ $foo->last_trigger_results }; Returns a reference to an array of the return values of all triggers called for the last trigger point. Results are ordered in the same order the triggers were run. TRIGGER POINTS
By default you can make any number of trigger points, but if you want to declare names of trigger points explicitly, you can do it via "import". package Foo; use Class::Trigger qw(foo bar baz); package main; Foo->add_trigger(foo => &sub1); # okay Foo->add_trigger(hoge => &sub2); # exception FAQ
Acknowledgement: Thanks to everyone at POOP mailing-list (http://poop.sourceforge.net/). Q. This module lets me add subs to be run before/after a specific subroutine is run. Yes? A. You put various call_trigger() method in your class. Then your class users can call add_trigger() method to add subs to be run in points just you specify (exactly where you put call_trigger()). Q. Are you aware of the perl-aspects project and the Aspect module? Very similar to Class::Trigger by the look of it, but its not nearly as explicit. Its not necessary for foo() to actually say "triggers go *here*", you just add them. A. Yep ;) But the difference with Aspect would be that Class::Trigger is so simple that it's easy to learn, and doesn't require 5.6 or over. Q. How does this compare to Sub::Versive, or Hook::LexWrap? A. Very similar. But the difference with Class::Trigger would be the explicitness of trigger points. In addition, you can put hooks in any point, rather than pre or post of a method. Q. It looks interesting, but I just can't think of a practical example of its use... A. (by Tony Bowden) I originally added code like this to Class::DBI to cope with one particular case: auto-upkeep of full-text search indices. So I added functionality in Class::DBI to be able to trigger an arbitary subroutine every time something happened - then it was a simple matter of setting up triggers on INSERT and UPDATE to reindex that row, and on DELETE to remove that index row. See Class::DBI::mysql::FullTextSearch and its source code to see it in action. AUTHORS
Original idea by Tony Bowden <tony@kasei.com> in Class::DBI. Code by Tatsuhiko Miyagawa <miyagawa@bulknews.net>. Jesse Vincent added a code to get return values from triggers and abortable flag. LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
Class::DBI perl v5.10.1 2009-10-11 Class::Trigger(3pm)
All times are GMT -4. The time now is 05:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy