Sponsored Content
Full Discussion: ~and s in perl
Top Forums Shell Programming and Scripting ~and s in perl Post 302852243 by balajesuri on Wednesday 11th of September 2013 03:24:20 AM
Old 09-11-2013
Quote:
Originally Posted by ptappeta
what does these lines mean "~ s/.*\/// " ,"~ s/[^\/]*$// " ?
This is a substitute command similar to sed on the unix shell.
s/.*\/// --> delete all the characters in $Program variable from the beginning till the last occurrence of '/' (rather it substitutes the characters from the beginning till the last occurrence of '/' with nothing)

s/[^\/]*$// --> delete all the characters in $Mydir from the last occurrence of '/' till the end (substitute the characters from the last occurrence of '/' till the end with nothing).

To give a better picture these two 's' commands work similar to "basename" and "dirname" utilities in unix.

Quote:
Code:
use DBI;
use DBD::Oracle qw(:ora_types);
use File::Copy;

what does above lines refer to ?
You're asking the perl compiler to use these modules (load these modules) so that the sub-routines in these modules can be used in your current program. You may want to read more about modules in perl.

Quote:
Code:
 
if ( defined ( $opt_v ) )

what does this mean?
This is plain English: If $opt_v is defined, then do this...

Sometimes $opt_v may not be defined or defined with "undef", in that case, this condition will fail.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Perl] Accessing array elements within a sed command in Perl script

I am trying to use a script to replace the header of each file, whose filename are stored within the array $test, using the sed command within a Perl script as follows: $count = 0; while ( $count < $#test ) { `sed -e 's/BIOGRF 321/BIOGRF 332/g' ${test} > 0`; `cat 0 >... (2 Replies)
Discussion started by: userix
2 Replies

2. Shell Programming and Scripting

Passing date formats in Perl: i.e. Jul/10/2007 -> 20070710 (yyyymmdd) - Perl

Hi , This script working for fine if pass script-name.sh Jul/10/2007 ,I want to pass 20070710(yyyymmdd) .Please any help it should be appereciated. use Time::Local; my $d = $ARGV; my $t = $ARGV; my $m = ""; @d = split /\//, $d; @t = split /:/, $t; if ( $d eq "Jan" ) { $m = 0 }... (7 Replies)
Discussion started by: akil
7 Replies

3. Shell Programming and Scripting

perl/unix: script in command line works but not in perl

so in unix this command works works and shows me a list of directories find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt but when i try running a perl script to run this command my $query = 'find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt';... (2 Replies)
Discussion started by: kpddong
2 Replies

4. Shell Programming and Scripting

Perl :How to print the o/p of a Perl script on console and redirecting same in log file @ same time.

How can i print the output of a perl script on a unix console and redirect the same in a log file under same directory simultaneously ? Like in Shell script, we use tee, is there anything in Perl or any other option ? (2 Replies)
Discussion started by: butterfly20
2 Replies

5. Shell Programming and Scripting

Hidden Characters in Regular Expression Matching Perl - Perl Newbie

I am completely new to perl programming. My father is helping me learn said programming language. However, I am stuck on one of the assignments he has given me, and I can't find very much help with it via google, either because I have a tiny attention span, or because I can be very very dense. ... (4 Replies)
Discussion started by: kittyluva2
4 Replies

6. Shell Programming and Scripting

HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

Hi all, Not sure if this should be in the programming forum, but I believe it will get more response under the Shell Programming and Scripting FORUM. Am trying to write a customized df script in Perl and need some help with regards to using arrays and file handlers. At the moment am... (3 Replies)
Discussion started by: newbie_01
3 Replies

7. UNIX for Advanced & Expert Users

perl and HP-UX : instmodsh in combination with software depot : update inventory for installed Perl

we create a HP-UX software depot with a new perl-modul. after installation of the software depot, the perl module i can't find with instmodsh in the inventory for installed Perl modules. - i have learned of using instmodsh command : i find out what modules are already installed on my system. ... (0 Replies)
Discussion started by: bora99
0 Replies

8. Shell Programming and Scripting

Perl :: reading values from Data Dumper reference in Perl

Hi all, I have written a perl code and stored the data into Data structure using Data::Dumper module. But not sure how to retreive the data from the Data::Dumper. Eg. Based on the key value( Here CRYPTO-6-IKMP_MODE_FAILURE I should be able to access the internal hash elements(keys) ... (1 Reply)
Discussion started by: scriptscript
1 Replies

9. Programming

Perl: restrict perl from automaticaly creating a hash branches on check

My issue is that the perl script (as I have done it so far) created empty branches when I try to check some branches on existence. I am using multydimentional hashes: found it as the best way for information that I need to handle. Saing multidimentional I means hash of hashes ... So, I have ... (2 Replies)
Discussion started by: alex_5161
2 Replies

10. Programming

PERL: In a perl-scripttTrying to execute another perl-script that SETS SOME VARIABLES !

I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open()) I would like to run another PERL-script from first one, not... (1 Reply)
Discussion started by: alex_5161
1 Replies
Term::ReadLine::Zoid::ViCommand(3pm)			User Contributed Perl Documentation		      Term::ReadLine::Zoid::ViCommand(3pm)

NAME
Term::ReadLine::Zoid::ViCommand - a readline command mode SYNOPSIS
This class is used as a mode under Term::ReadLine::Zoid, see there for usage details. DESCRIPTION
This mode provides a "vi command mode" as specified by the posix spec for the sh(1) utility. It intends to include at least all key-bind- ings mentioned by the posix spec for the vi mode in sh(1). It also contains some extensions borrowed from vim(1) and some private exten- sions. This mode has a "kill buffer" that stores the last killed text so it can be yanked again. This buffer has only one value, it isn't a "kill ring". KEY MAPPING
Since ViCommand inherits from MultiLine, which in turn inherits from Term::ReadLine::Zoid, key bindings are also inherited unless explic- itly overloaded. Control-d is ignored in this mode. escape Reset the command mode. return ^J Return the current edit line to the application for execution. ^Z Send a SIGSTOP to the process of the application. Might not work when the application ignores those, which is something shells tend to do. i Switch back to insert mode. I Switch back to insert mode at the begin of the edit line. a Enter insert mode after the current cursor position. A Enter insert mode at the end of the edit line. m Switch to multiline insert mode, see Term::ReadLine::Zoid::MultiLine. (private extension) M Switch to multiline insert mode at the end of the edit buffer. (private extension) R Enter insert mode with replace toggled on. (vim extension) # Makes current edit line a comment that will be listed in the history, but won't be executed. Only works if the 'comment_begin' option is set. = Display possible shell word completions, does not modify the edit line. Do pathname completion (using File::Glob) and insert the largest matching part in the edit line. * Do pathname completion but inserts all matches. [count] @ char Regard the contents of the alias _char as a macro with editing commands. This seems a rather obfuscated feature of the posix spec to me. See also below for the alias command. Note that the count argument is not posix compliant, but it seems silly not to use it. [count] ~ Reverse case for count characters. [count] . Repeat the last non-motion command. If no count is specified the original count of the command is used. v Edit the buffer with the editor specified by the "EDITOR" environment variable or the editor option, defaults to 'vi'. This function requires the File::Temp module from cpan, which in turn needs File::Spec and other packages. If these are not available this functions is disabled. [count] l [count] space Move the cursor to the right. [count] h Move the cursor to the left. [count] w [count] W Move the cursor to the begin of the next word or bigword. (A bigword exists of non-whitespace chars, while a word exists of alphanumeric chars only.) [count] e [count] E Move the cursor to the end of the current word or bigword. [count] b [count] B Move the cursor to the begin of the current word or bigword. ^ Move the cursor to the first non-whitespace on the edit line. $ Move the cursor to the end of the edit line. 0 Move the cursor to the begin of the edit line. [count] | Set the cursor to position count (1-based). [count] f char Set cursor to count'th occurrence of char to the right. The cursor is placed on char. [count] F char Set cursor to count'th occurrence of char to the left. The cursor is placed on char. [count] t char Set cursor to count'th occurrence of char to the right. The cursor is placed before char. [count] T char Set cursor to count'th occurrence of char to the left. The cursor is placed after char. [count] ; Repeat the last 'f', 'F', 't', or 'T' command. Count of last command is ignored. [count] , Like ';' but with direction reversed. [count] c motion Delete characters between the current position and the position after the motion, count applies to motion. After the deletion enter insert mode. The "motion" 'c' deletes the current edit line. C Delete from cursor to end of line and enter insert mode. S Delete current line and enter insert mode. [count] r char Replace the character under the cursor (and the count characters next to it) with char. [count] _ Insert a white space followed by the last (or count'th) bigword from the previous history entry ans enter insert mode. Quotes are not respected by this function. [count] x Delete count characters and place them in the save buffer. [count] X Delete count characters before the cursor position and place them in the save buffer. ('x' is like 'delete', 'X' like backspace) [count] d motion Delete from the current cursor position to the position resulting from count times motion. The deleted part will be placed in the save buffer. The "motion" 'd' deletes the current line. D Delete from the cursor position until the end of the line and put the deleted part in the save buffer. [count] y motion Yank (copy) characters from the current cursor position to the position resulting from count times motion to the save buffer. the "motion" 'y' yanks the current line. Y Like y but from cursor till end of line. [count] p Insert count copies of the the save buffer after the cursor. [count] P Insert count copies of the the save buffer before the cursor. u Undo the last command that changed the edit line. U Undo all changes. TODO all changes since when ? since entering the command mode ? [count] k [count] - Go count lines backward in history. [count] j [count] + Go count lines forward in history. [number] G Go to history entry number number, or to the first history entry. n Repeat the last history search by either the '/' or '?' minibuffers or the incremental search mode. N Repeat the last history search in the oposite direction. : Opens a command mini buffer. This is a very minimalistic execution environment that can for instance be used to modify options if the application doesn't provide a method to do so. Also it is used for quick hacks ;) The execution of this buffer happens entirely without returning to the application. (This is a vim extension) / Opens a mini buffer where you can type a pattern to search backward through the history. The search patterns are not globs (as posix would have them), but are evaluated as perl regexes. An empty pattern repeats the previous search. ? Like '/' but searches in the forward direction. ^A If cursor is on a number, increment it. (This is a vim extension) FIXME bit buggy ^X If cursor is on a number, decrement it. (This is a vim extension) FIXME bit buggy COMMANDS
These can be used from the ":" mini buffer. Some commands are borrowed from vim, but no guarantee what so ever. quit Return undef to the application (like '^D' in insert mode). set [+o|-o] [option=value] Set a key-value pair in the options hash When the arg '+o' is given (or the option is preceded by 'no') the option is deleted. Can be used to change the ReadLine behaviour independent from the application. ascii Output ascii values for the char in the edit line on the cursor position. testchr Wait for a character input and output ascii values for it. bindchr chr=keyname Map a char (or char sequence) to a key name. bindkey chr=sub { code } Map a char (or char sequence) to a key name. !, shell shellcode Eval a system command. The '%' character in this string will be replace with the name of a tmp file containing the edit buffer. After execution this tmp file will be read back into the edit buffer. Of course you can use an backslash to escape a literal '%'. Note that this tmp file feature only works if you have File::Temp installed. eval perlcode Eval some perlcode for the most evil instant hacks. The ReadLine object can be called as $self. alias char=macro Define a macro in an alias with a one character name. These can be executed with the '@' command. Non alphanumeric keys like " " and "e" can be inserted with the standard perl escape sequences. You need to use "\" for a literal ''. ATTRIBS
These can be accessed through the "Attribs" method (defined by the parent class). aliases This option is refers to a hash with aliases, used for the key binding for '@'. Note that all aliases have a one character name pre- fixed with a "_", this is due to historic implementations where the same hash is used for system aliases. We don't support aliases for the shell command, to have that you should define your own shell subroutine (see below). editor Editor command used for the 'v' binding. The string is run by the shell command. This option defaults to the EDITOR enviroment vari- able or to "vi %". shell The value can be set to a CODE ref to handle the shell command from the mini-buffer and the 'v' key binding. It should return the exit status of the command (like the perlfunc "system()"). AUTHOR
Jaap Karssenberg || Pardus [Larus] <pardus@cpan.org> Copyright (c) 2004 Jaap G Karssenberg. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
Term::ReadLine::Zoid perl v5.8.7 2005-08-07 Term::ReadLine::Zoid::ViCommand(3pm)
All times are GMT -4. The time now is 08:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy