Sponsored Content
Top Forums Shell Programming and Scripting How to define two variable in foreach command?? Post 26435 by geoquest on Sunday 18th of August 2002 08:15:20 AM
Old 08-18-2002
Question How to define two variable in foreach command??

Hello,

I just want to know how If it's possiple to define 2 variable using foreach command ???

I have directory inside that directory around 1000 file, I want to rename all of this files to something I have it in a list. Example :-

------This is what in my directory----------
d1
d2
d3
d4
d5
------------------------------------------------------

I have a LIST which containe the new naming "more new_name" and I have this

omd1
omd2
omd3
omd4
omd5

I tried to do crazy way to done it :-

# ls mydirectory >> old_name
# foreach file (`more old_name`) file2 (`more new_name`)
mv $file $file2
end

I know this is crazy but I don't know how to do it Smilie

Please do help me Smilie
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Using Grep to Define a Variable

I am using korn shell unix. I have a script that I am working with to do a check for me using a text file. #finds "Time" from the text file and cuts the second field from the #line A= grep Time test.txt | cut -f2 # the "#Missing" is being pulled from the second field of the text... (1 Reply)
Discussion started by: cspcspcsp
1 Replies

2. UNIX for Dummies Questions & Answers

define length of variable

I have a variable with a value of "05". When I add one to that variable, using the command: CURR_YY=`expr $CURR_YY + 1`, I get the value of "6", losing the leading zero (which is needed for passing to another script). How do I keep the leading zero? Thank you! (10 Replies)
Discussion started by: cbarker
10 Replies

3. Shell Programming and Scripting

How to define a variable with variable definition is stored in a variable?

Hi all, I have a variable say var1 (output from somewhere, which I can't change)which store something like this: echo $var1 name=fred age=25 address="123 abc" password=pass1234 how can I make the variable $name, $age, $address and $password contain the info? I mean do this in a... (1 Reply)
Discussion started by: freddy1228
1 Replies

4. Shell Programming and Scripting

foreach variable used in awk (please help!!)

I have a list of markers, say marker.txt: rs913257 rs1018390 rs764180 and I need to know which ROW that each marker appears in another map file, say map.txt: a rs12354060 b rs913257 c rs6650104 d rs2185539 e rs6681105 f rs1018390 g rs764180 h rs12564807 i rs3094315 The result... (4 Replies)
Discussion started by: Zoho
4 Replies

5. Shell Programming and Scripting

bash - define a variable

Hello, I would like to define a variable based on another variable: a=5 b$a=100 This does not work. What is the right way to do it? Thanks ---------- Post updated at 07:37 PM ---------- Previous update was at 07:33 PM ---------- Found my answer with the search function (did not... (0 Replies)
Discussion started by: jolecanard
0 Replies

6. Shell Programming and Scripting

question about define variable.

Hi, Unix Gurus, In our existing file, there is a script like #!/bin/sh step=${1:-0} cur_step=10 if ... My question is what's "${1:-0}" mean? I know it defines a variable but I don't know what's (1:-0) mean? :wall: Thanks in advance. (2 Replies)
Discussion started by: ken002
2 Replies

7. Shell Programming and Scripting

In Perl can i define a hash with value as variable?

Hi, Is it possible in perl to have a hash defined with variables as theirs key values, like: %account = ('username' => 'boy', 'password' => $password); Thanks (1 Reply)
Discussion started by: zing_foru
1 Replies

8. Shell Programming and Scripting

Define variable from file.

HI I have file A.txt _1A _2A _3A _4A I want define all as different variable. $1A=_1A $2B=_2A $3C=_3A $4D=_4A Now i can use any variable in my script. (3 Replies)
Discussion started by: pareshkp
3 Replies

9. UNIX for Dummies Questions & Answers

How to prompt user to define a variable?

Hi everyone, Is it possible to define blank vaianbles and prompt user to fill them during the script execution? A very simple example: INPUT= OUTPUT= cut -f1-4 $INPUT | sed 's/hello/goodbye/g' | sort -uV > $OUTPUTThank you in advance! Best wishes (2 Replies)
Discussion started by: lsantome
2 Replies
Refactor(3pm)						User Contributed Perl Documentation					     Refactor(3pm)

NAME
Devel::Refactor - Perl extension for refactoring Perl code. VERSION
$Revision: $ This is the CVS revision number. SYNOPSIS
use Devel::Refactor; my $refactory = Devel::Refactor->new; my ($new_sub_call,$new_sub_code) = $refactory->extract_subroutine($sub_name, $code_snippet); my $files_to_change = $refactory->rename_subroutine('./path/to/dir', 'oldSubName','newSubName'); # $files_to_change is a hashref where keys are file names, and values are # arrays of hashes with line_number => new_text ABSTRACT
Perl module that facilitates refactoring Perl code. DESCRIPTION
The Devel::Refactor module is for code refactoring. While Devel::Refactor may be used from Perl programs, it is also designed to be used with the EPIC plug-in for the eclipse integrated development environment. CLASS METHODS
Just the constructor for now. new Returns a new Devel::Refactor object. PUBLIC OBJECT METHODS
Call on a object returned by new(). extract_subroutine($new_name,$old_code [,$syntax_check]) Pass it a snippet of Perl code that belongs in its own subroutine as well as a name for that sub. It figures out which variables need to be passed into the sub, and which variables might be passed back. It then produces the sub along with a call to the sub. Hashes and arrays within the code snippet are converted to hashrefs and arrayrefs. If the syntax_check argument is true then a sytax check is performed on the refactored code. Example: $new_name = 'newSub'; $old_code = <<'eos'; my @results; my %hash; my $date = localtime; $hash{foo} = 'value 1'; $hash{bar} = 'value 2'; for my $loopvar (@array) { print "Checking $loopvar "; push @results, $hash{$loopvar} || ''; } eos ($new_sub_call,$new_code) = $refactory->extract_subroutine($new_name,$old_code); # $new_sub_call is 'my ($date, $hash, $results) = newSub (@array);' # $new_code is # sub newSub { # my $array = shift; # # my @results; # my %hash; # my $date = localtime; # $hash{foo} = 'value 1'; # $hash{bar} = 'value 2'; # for my $loopvar (@$array) { # print "Checking $loopvar "; # push @results, $hash{$loopvar} || ''; # } # # # return ($date, \%hash, @results); # } Included in the examples directory is a script for use in KDE under Linux. The script gets its code snippet from the KDE clipboard and returns the transformed code the same way. The new sub name is prompted for via STDIN. rename_subroutine($where,$old_name,$new_name,[$max_depth]) where is one of: path-to-file path-to-directory If where is a directory then all Perl files (default is ".pl", ".pm", and ".pod" See the perl_file_extensions method.) in that directory and its' descendents (to max_depth deep,) are searched. Default for max_depth is 0 -- just the directory itself; max_depth of 1 means the specified directory, and it's immeadiate sub-directories; max_depth of 2 means the specified directory, it's sub-directories, and their sub-directrories, and so forth. If you want to scan very deep, use a high number like 99. If no matches are found then returns undef, otherwise: Returns a hashref that tells you which files you might want to change, and for each file gives you the line numbers and proposed new text for that line. The hashref looks like this, where old_name was found on two lines in the first file and on one line in the second file: { ./path/to/file1.pl => [ { 11 => "if (myClass->newName($x)) { " }, { 27 => "my $result = myClass->newName($foo); "}, ], ./path/to/file2.pm => [ { 235 => "sub newName { "}, ], } The keys are paths to individual files. The values are arraryrefs containing hashrefs where the keys are the line numbers where old_name was found and the values are the proposed new line, with old_name changed to new_name. is_perlfile($filename) Takes a filename or path and returns true if the file has one of the extensions in perl_file_extensions, otherwise returns false. OBJECT ACCESSORS
These object methods return various data structures that may be stored in a Devel::Refactor object. In some cases the method also allows setting the property, e.g. perl_file_extensions. get_new_code Returns the return_snippet object property. get_eval_results Returns the eval_err object property. get_sub_call Returns the return_sub_call object property. get_scalars Returns an array of the keys from scalar_vars object property. get_arrays Returns an array of the keys from the array_vars object property. get_hashes Returns an array of the keys from the hash_vars object property. get_local_scalars Returns an array of the keys from the local_scalars object property. get_local_arrays Returns an array of the keys from the local_arrays object property. get_local_hashes Returns an array of the keys from the local_hashes object property. perl_file_extensions([$arrayref|$hashref]) Returns a hashref where the keys are regular expressions that match filename extensions that we think are for Perl files. Default are ".pl", ".pm", and ".pod" If passed a hashref then it replaces the current values for this object. The keys should be regular expressions, e.g. ".cgi$". If passed an arrayref then the list of values are added as valid Perl filename extensions. The list should be filename extensions, NOT regular expressions, For example: my @additonal_filetypes = qw( .ipl .cgi ); my $new_hash = $refactory->perl_file_extensions(@additional_filetypes); # $new_hash = { # '.pl$' => 1, # '.pm$' => 1, # '.pod$' => 1, # '.ipl$' => 1, # '.cgi$' => 1, # '.t$' => 1, # } TODO LIST
Come up with a more uniform approach to ACCESSORS. Add more refactoring features, such as add_parameter. Add a SEE ALSO section with URLs for eclipse/EPIC, refactoring.com, etc. AUTHOR
Scott Sotka, <ssotka@barracudanetworks.com> COPYRIGHT AND LICENSE
Copyright 2005 by Scott Sotka This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.0 2005-03-17 Refactor(3pm)
All times are GMT -4. The time now is 11:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy