The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Storing Multiple Values in a Variable sandeep_1105 UNIX for Dummies Questions & Answers 1 03-03-2009 01:10 AM
Testing for multiple words in a Variable eltinator UNIX for Dummies Questions & Answers 1 02-17-2009 05:17 AM
How do I write multiple variable syntax? Captain Shell Programming and Scripting 1 11-11-2008 04:46 PM
usage of same variable in multiple scripts risshanth UNIX for Dummies Questions & Answers 1 07-01-2008 01:03 PM
put the contents of this file into a variable with multiple lines Nomaad Shell Programming and Scripting 3 04-23-2008 01:39 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-04-2009
Raynon Raynon is offline
Registered User
  
 

Join Date: Sep 2006
Location: Sg
Posts: 350
Multiple variable in a variable in Perl

Hi All,

I am trying to convert the below Csh while loop into Perl while loop but the problem is that in this csh script, i have 2 variables inside a variable -> $count is a variable {SB$count} as a whole is another variable. Csh is able to assign values to such variable like the below but i do not know if this is possible in Perl.
Can any expert give some advice?


[code]
while ( $count <= 5 ) then
set SB$count = `cat $files_extracted.txt|grep -c "x= $count"`
@ count = $count + 1
end
[code]
  #2 (permalink)  
Old 05-04-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,947
This isn't a "variable inside a variable" (which is possible in Perl using references for example), but a bad excuse for an array. A literal translation of your code would be something like
Code:
for($i=0;$i<=5;$i++) {
    $SB[$count] = `grep -c "x=$count" $files_extracted.txt`;
}

Even shaved off a line and one unnecessary cat. Be prepared to do away with a lot of CSH workarounds now that you use a real scripting language.
  #3 (permalink)  
Old 05-04-2009
Raynon Raynon is offline
Registered User
  
 

Join Date: Sep 2006
Location: Sg
Posts: 350
Hi Pludi,

Thks for the advice.
But if my csh statement is the below. How can i convert the below to Perl ?


Code:
set SB$count = `cat $tester_dir/files_extracted.txt|grep "HARD_BIN:"|awk '{print ($2)}'|grep -c $count`

  #4 (permalink)  
Old 05-04-2009
durden_tyler's Avatar
durden_tyler durden_tyler is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2009
Posts: 548

Code:
$SB1 = `cat $tester_dir/files_extracted.txt|grep "HARD_BIN:"|awk '{print \$2}'|grep -c $count`;

tyler_durden
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:45 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0