Sponsored Content
Top Forums Shell Programming and Scripting Perl : Perl equivalent to the ksh | and ; Post 302875325 by popeye on Tuesday 19th of November 2013 08:48:30 AM
Old 11-19-2013
Many thanks to Mr. Bean.

With his help/code I came up with this that provides the result that I was looking for.

Code:
#!/usr/bin/perl
#
use strict; use warnings; use Data::Dumper;
open my $in,'<',"codecs";
open my $out,'>',"File2.txt";
while(<$in>){
 if(/^primary$/ .. /\*Slot\s/) {
   if(/\*Slot\s/) { print "$_"; next; }
   s/[\r\n]/ /g;
   print unless /Factory/ ;
 } elsif  (/^left$/ .. /\*Slot\s/) {
    if(/\*Slot\s/) { print "$_"; next; }
    s/[\r\n]/ /g;
    print unless /Factory/ ;
 } elsif (/^right$/ .. /\*Slot\s/) {
    if(/\*Slot\s/) { print "$_"; next; }
    s/[\r\n]/ /g;
    print unless /Factory/ ;
 }
}

Which coincidentally doesnt read as well for me anyway as

Code:
clear
echo "Parse show version"
echo "------------------"
p=`sed -n '/^primary$/,/\*Slot /p' codecs | sed '/Factory/d' | tr '\012' ' '| awk '{print $1" "$5}'`
l=`sed -n '/^left$/,/\*Slot /p' codecs | sed '/Factory/d' | tr '\012' ' '| awk '{print $1" "$5}'`
r=`sed -n '/^right$/,/\*Slot /p' codecs | sed '/Factory/d' | tr '\012' ' '| awk '{print $1" "$5}'`
echo "$p : $l : $r" 
echo " "

But Ill force myself to learn perl if it kills me... and it probably will Smilie

thanks again to all ...

---------- Post updated at 08:48 AM ---------- Previous update was at 08:46 AM ----------

Sorry .. one other thing. A resource Im using, Impatient Perl, refers to Capturing and Clustering. I think that answers the real question and where I need to focus some attention.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl equivalent of ksh if / echo statement

Is there an equivalent perl statement for the following ksh statement ? example if then ... else ... fi (2 Replies)
Discussion started by: gefa
2 Replies

2. Shell Programming and Scripting

export equivalent command in PERL

Hi I need an equivalent command in PERL for the following. export LC_ALL=C; I hope this is the command. Please confirm this and correct me if i am wrong $ENV{LC_ALL}="C"; Thanks and Regards Ammu (1 Reply)
Discussion started by: ammu
1 Replies

3. Shell Programming and Scripting

perl equivalent to grep -c

Guess the subject lines says it all. What is the perl equivalent to grep -c -c, --count Suppress normal output; instead print a count of match- ing lines for each input file. With the -v, --invert- match option (see below), count non-matching lines. ... (6 Replies)
Discussion started by: popeye
6 Replies

4. Shell Programming and Scripting

strtok equivalent in perl

Hi All, Is their any equivalent for strtok (in c) to use in perl script. Thanks in advance. JS (1 Reply)
Discussion started by: jisha
1 Replies

5. Shell Programming and Scripting

Bash equivalent of perl's pack function ?

Is there an equivalent of perl's pack function in bash ? Or in other words, how can I achieve the same thing in bash ? Much appreciated. (1 Reply)
Discussion started by: NewDeb
1 Replies

6. Shell Programming and Scripting

Regular expression matching in BASH (equivalent of =~ in Perl)

In Perl I can write a condition that evaluates a match expression like this: if ($foo =~ /^bar/) { do blah blah blah } How do I write this in shell? What I need to know is what operator do I use? The '=~' doesn't seem to fit. I've tried different operators, I browsed the man page for... (3 Replies)
Discussion started by: indiana_tas
3 Replies

7. Shell Programming and Scripting

need perl equivalent

Dear All, Good day, can any of you help me in the following problem: I need to find the perl equivalent for the following commandline grep characters |awk '{print \$2}'Expecting your reply and thanks in advance. Warm regards Fredrick. (4 Replies)
Discussion started by: Fredrick
4 Replies

8. Shell Programming and Scripting

grep -v equivalent in perl

I have to do grep -v in a perl script. I want to exclude blank lines and lines having visitor. #grep -v visitor abc.txt |grep '.' file:abc.txt 1340 not booked 16D:D9 tourist 8 1341 not booked 16C:D4 tourist 25 1342 not booked 16D:C4 visitor 7 1343 not booked 01C:D9 visitor 6 1344... (4 Replies)
Discussion started by: dynamax
4 Replies

9. Shell Programming and Scripting

What is the equivalent of NR (awk) in perl?

Hello, I searched online; it seems that perl use $NR as NR in awk; however it does not work for me. For example, how to re-write the following awk using perl: awk '{ print NR}' inputfile---------- Post updated at 01:55 PM ---------- Previous update was at 12:49 PM ---------- I found... (2 Replies)
Discussion started by: littlewenwen
2 Replies

10. Shell Programming and Scripting

Perl equivalent substitution

hi Geeks, my input file contains data like => 53 - Deewana Kar Raha Hai.mp3 54 - Hale Dil.mp3 55 - Ishq Sufiyana.mp3 56 - Abhi Kuch Dino Se.mp3 57 - Pee Loon Hoto Ki Sargam.mp3 I had used sed command to remove the prefix from the file name like sed 's/^\ it gives me the perfect... (4 Replies)
Discussion started by: lohith.dutta
4 Replies
MixinFactory(3pm)					User Contributed Perl Documentation					 MixinFactory(3pm)

NAME
Class::MixinFactory - Class Factory with Selection of Mixins SYNOPSIS
package MyClass; use Class::MixinFactory -hasafactory; sub new { ... } sub foo { return "Foo Bar" } package MyClass::Logging; sub foo { warn "Calling foo"; (shift)->NEXT('foo', @_) } package MyClass::UpperCase; sub foo { uc( (shift)->NEXT('foo', @_) ) } package main; my $class = MyClass->class( 'Logging', 'UpperCase' ); print $class->new()->foo(); # Calls MyClass::Logging::foo, MyClass::UpperCase::foo, MyClass::foo DESCRIPTION
This distribution facilitates the run-time generation of classes which inherit from a base class and some optional selection of mixin classes. A factory is provided to generate the mixed classes with multiple inheritance. A NEXT method allows method redispatch up the inheritance chain. USAGE
The Class::MixinFactory package is just a facade that loads the necessary classes and provides a few import options for compile-time convenience. Factory Interface To generate an object with some combination of mixins, you first pass the names of the mixin classes to a class factory which will generate a mixed class. (Or return the name of the already generated class, if there has been a previous request with the same combination of mixins.) You can add a factory method to your base class, create a separate factory object, or inherit to produce a factory class. Factory Method To add a factory method to a base class, inherit from the Class::MixinFactory::HasAFactory class, or use the "-hasafactory" import option: package MyClass; use Class::MixinFactory -hasafactory; package main; my $class = MyClass->class( 'Logging', 'UpperCase' ); print $class->new()->foo(); Factory Class To create a new class which will act as a factory for another base class, inherit from the Class::MixinFactory::Factory class, or use the "-isafactory" import option: package MyClass::Factory; use Class::MixinFactory -isafactory; MyClass::Factory->base_class( "MyClass" ); package main; my $class = MyClass::Factory->class( 'Logging', 'UpperCase' ); print $class->new()->foo(); Factory Object To create an object which will act as a factory, create a Class::MixinFactory::Factory instance by calling the new() method: use Class::MixinFactory; my $factory = Class::MixinFactory->new(); $factory->base_class( "MyClass" ); my $class = $factory->class( 'Logging', 'UpperCase' ); print $class->new()->foo(); Inheriting from a Mixed Class Inheriting with a Factory Method or Factory Object A subclass can inherit from a mixed class: package MyClass::CustomWidget; @ISA = MyClass->class( 'Logging', 'UpperCase' ); sub foo { local $_ = (shift)->NEXT('foo', @_); tr[a-z][z-a]; $_ } package main; print MyClass::CustomWidget->new()->foo(); Inheriting with a Factory Class A subclass can use a factory class to define its own inheritance: package MyClass::CustomWidget; use Class::MixinFactory -isasubclass, MyClass::Factory => 'Logging', 'UpperCase'; sub foo { local $_ = (shift)->NEXT('foo', @_); tr[a-z][z-a]; $_ } package main; print MyClass::CustomWidget->new()->foo(); Configuring a Factory Factories support methods that control which classes they will use. The base class will be inherited from by all mixed classes. $factory->base_class( "HelloWorld" ); The mixin prefix is prepended to the mixin names passed to the class() method. Mixin names that contain a "::" are assumed to be fully qualified and are not changed. If empty, the base_class is used. $factory->mixin_prefix( 'HelloFeature' ); The mixed prefix is at the start of all generated class names. If empty, the base_class is used, or the factory's class name. $factory->mixed_prefix( 'HelloClass' ); Writing a Mixin Class Writing a mixin class is almost the same as writing a subclass, except where methods need to redispatch to the base-class implementation. (The SUPER::method syntax will only search for classes that the mixin itself inherits from; to search back up the inheritance tree and explore other branches, another redispatch mechanism is needed.) A method named NEXT is provided to continue the search through to the next class which provides a given method. The order in which mixins are stacked is significant, so the caller should understand how their behaviors interact. (See Class::MixinFactory::NEXT.) SEE ALSO
For distribution, installation, support, copyright and license information, see Class::MixinFactory::ReadMe. perl v5.10.1 2009-12-10 MixinFactory(3pm)
All times are GMT -4. The time now is 05:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy