Sponsored Content
Full Discussion: Help with vi editor
Top Forums UNIX for Dummies Questions & Answers Help with vi editor Post 302758319 by gonchusirsa on Friday 18th of January 2013 11:41:55 PM
Old 01-19-2013
[Solved] Help with vi editor

Hi,

In vi editor for search and replace , I used to use :%s/'thing-to-be-searched'/'replace-thing'/.

Now i came across this line :%s/^/##hello#/

Can someone help me decipher this line.

Thanks in advance.
Cheers
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Vi editor ?

Hello everybody, My question is: how to add /tmp/work at the end of line in vi editor. my file looks like: cp file1 cp file2 cp file3 **** I need to add " /tmp/work" at the end of each line. I tried this :%s/$/" /tmp/work" and this :%s/$/\ /tmp/work\/ but it does not work. (2 Replies)
Discussion started by: billy5
2 Replies

2. HP-UX

instead VI editor - which one?

I'd like to find some editor for HP-UX, something like notepad, but not VI editor. Can someone have some ideas which one? thx (6 Replies)
Discussion started by: diamond
6 Replies

3. UNIX for Advanced & Expert Users

vi editor

Hi, how can I add at the begining and at the end of all of the lines of my text file in VI editor ? Many thanks before. for exemple if in my file i have line 1 line 2 I want to have : start line 1 end start line 2 end (3 Replies)
Discussion started by: alain123456
3 Replies

4. HP-UX

vi editor

I am new in hp ux and I want work with vi editor, but in hp ux vi editor the backspaes and del keys doesn't work. how can I enable them. thanks (3 Replies)
Discussion started by: hkoolivand
3 Replies

5. UNIX for Dummies Questions & Answers

Pasting text in VI editor from a different editor

Hi, I knw its a silly question, but am a newbie to 'vi' editor. I'm forced to use this, hence kindly help me with this question. How can i paste a chunk 'copied from' a different editor(gedit) in 'vi editor'? As i see, p & P options does work only within 'vi'. (10 Replies)
Discussion started by: harishmitty
10 Replies

6. Shell Programming and Scripting

set EDITOR=vi -> default editor not setting for cron tab

Hi All, I am running a script , working very fine on cmd prompt. The problem is that when I open do crontab -e even after setting editor to vi by set EDITOR=vi it does not open a vi editor , rather it do as below..... ///////////////////////////////////////////////////// $ set... (6 Replies)
Discussion started by: aarora_98
6 Replies

7. Solaris

Epic Editor was not able to obtain a license for your use. Feature Epic Editor :Licen

Epic Editor was not able to obtain a license for your use. Feature Epic Editor :License server is down (1 Reply)
Discussion started by: durgaprasadr13
1 Replies

8. Shell Programming and Scripting

About vi editor

How can ` character be printed on vi editor ? empl_id=`echo $line | awk ' { print $1; } '` (2 Replies)
Discussion started by: senem
2 Replies

9. Shell Programming and Scripting

Not able to use @ in VI editor

Hello All, Need one Help for one issue. I am using a French Keyboard, so @ sign is on key 0 and i have to use right Alt + 0 to print it. It is working everywhere but not inside Vi editor. I can type @ in shell, in notepad. But inside Vi editor it is not working, another problem is that if... (2 Replies)
Discussion started by: yadavricky
2 Replies

10. Open Source

What editor does everyone use?

I was looking through the topics and I wasn't sure if this was the best place to post this question: I was wondering, out of curiosity, which software everyone was using to code their scripts in. I do mostly sh/ksh and my favorite has always been EditPlus because it is small, fast, yet powerful.... (409 Replies)
Discussion started by: yongho
409 Replies
Sub::Override(3pm)					User Contributed Perl Documentation					Sub::Override(3pm)

NAME
Sub::Override - Perl extension for easily overriding subroutines SYNOPSIS
use Sub::Override; sub foo { 'original sub' }; print foo(); # prints 'original sub' my $override = Sub::Override->new( foo => sub { 'overridden sub' } ); print foo(); # prints 'overridden sub' $override->restore; print foo(); # prints 'original sub' DESCRIPTION
The Problem Sometimes subroutines need to be overridden. In fact, your author does this constantly for tests. Particularly when testing, using a Mock Object can be overkill when all you want to do is override one tiny, little function. Overriding a subroutine is often done with syntax similar to the following. { local *Some::sub = sub {'some behavior'}; # do something } # original subroutine behavior restored This has a few problems. { local *Get::some_feild = { 'some behavior' }; # do something } In the above example, not only have we probably misspelled the subroutine name, but even if their had been a subroutine with that name, we haven't overridden it. These two bugs can be subtle to detect. Further, if we're attempting to localize the effect by placing this code in a block, the entire construct is cumbersome. Hook::LexWrap also allows us to override sub behavior, but I can never remember the exact syntax. An easier way to replace subroutines Instead, "Sub::Override" allows the programmer to simply name the sub to replace and to supply a sub to replace it with. my $override = Sub::Override->new('Some::sub', sub {'new data'}); # which is equivalent to: my $override = Sub::Override->new; $override->replace('Some::sub', sub { 'new data' }); You can replace multiple subroutines, if needed: $override->replace('Some::sub1', sub { 'new data1' }); $override->replace('Some::sub2', sub { 'new data2' }); $override->replace('Some::sub3', sub { 'new data3' }); If replacing the subroutine succeeds, the object is returned. This allows the programmer to chain the calls, if this style of programming is preferred: $override->replace('Some::sub1', sub { 'new data1' }) ->replace('Some::sub2', sub { 'new data2' }) ->replace('Some::sub3', sub { 'new data3' }); A subroutine may be replaced as many times as desired. This is most useful when testing how code behaves with multiple conditions. $override->replace('Some::thing', sub { 0 }); is($object->foo, 'wibble', 'wibble is returned if Some::thing is false'); $override->replace('Some::thing', sub { 1 }); is($object->foo, 'puppies', 'puppies are returned if Some::thing is true'); Restoring subroutines If the object falls out of scope, the original subs are restored. However, if you need to restore a subroutine early, just use the restore method: my $override = Sub::Override->new('Some::sub', sub {'new data'}); # do stuff $override->restore; Which is somewhat equivalent to: { my $override = Sub::Override->new('Some::sub', sub {'new data'}); # do stuff } If you have override more than one subroutine with an override object, you will have to explicitly name the subroutine you wish to restore: $override->restore('This::sub'); Note "restore()" will always restore the original behavior of the subroutine no matter how many times you have overridden it. Which package is the subroutine in? Ordinarily, you want to fully qualify the subroutine by including the package name. However, failure to fully qualify the subroutine name will assume the current package. package Foo; use Sub::Override; sub foo { 23 }; my $override = Sub::Override->new( foo => sub { 42 } ); # assumes Foo::foo print foo(); # prints 42 $override->restore; print foo(); # prints 23 METHODS
new my $sub = Sub::Override->new; my $sub = Sub::Override->new($sub_name, $sub_ref); Creates a new "Sub::Override" instance. Optionally, you may override a subroutine while creating a new object. replace $sub->replace($sub_name, $sub_body); Temporarily replaces a subroutine with another subroutine. Returns the instance, so chaining the method is allowed: $sub->replace($sub_name, $sub_body) ->replace($another_sub, $another_body); This method will "croak" is the subroutine to be replaced does not exist. override my $sub = Sub::Override->new; $sub->override($sub_name, $sub_body); "override" is an alternate name for "replace". They are the same method. restore $sub->restore($sub_name); Restores the previous behavior of the subroutine. This will happen automatically if the "Sub::Override" object falls out of scope. EXPORT
None by default. BUGS
Probably. Tell me about 'em. SEE ALSO
o Hook::LexWrap -- can also override subs, but with different capabilities o Test::MockObject -- use this if you need to alter an entire class AUTHOR
Curtis "Ovid" Poe, "<ovid [at] cpan [dot] org>" Reverse the name to email me. COPYRIGHT AND LICENSE
Copyright (C) 2004-2005 by Curtis "Ovid" Poe This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.2 or, at your option, any later version of Perl 5 you may have available. perl v5.10.1 2010-04-01 Sub::Override(3pm)
All times are GMT -4. The time now is 09:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy