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
how to get the string stored in a variable in a line??? jisha Shell Programming and Scripting 4 04-05-2008 01:50 PM
function call kamel.seg Shell Programming and Scripting 2 12-28-2007 02:58 PM
call function Jamil Qadir Shell Programming and Scripting 4 03-20-2007 05:07 AM
Help with a function call Stevhp High Level Programming 6 03-05-2007 02:44 AM
function call forever_49ers Shell Programming and Scripting 3 09-13-2006 07:26 PM

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 09-15-2008
madhaviece madhaviece is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 7
Question How to use a stored string in function call

Hi All
I have written code for storing data in a string based on pattern.
whenever i tried to use in a function call its not getting there.
Actually the same logic was applied for another string..then i can use the
string at any function.

the code goes like this

/mp metadata/{
start=index($0,"metadata");
if ($2=="metadata")
flow_string=substr($0,start);
print(flow_string);
}
I can print the data in this search block

If i tried to use in any function the data in the flow_string is not retrieving
like
function retrieve_data(){
print(flow_string);
}
It is not working..
but the same thing is working for some other pattern.

Please can anyone have an idea whats may be the reason that iam not able to use that string..any globally declaration is need to be done..
for one string the logic is working and why its not working for other string?
while parsing data any problem?


please help me out...
  #2 (permalink)  
Old 09-16-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Whatever the reason, an improvement (not merely a workaround!) would be to make sure you always use local variables in functions. This is a basic principle of modular coding; it helps keep code complexity down and reduces the risk that you end up with spaghetti code.

So, in other words, refactor retrieve_data() so that it receives the flow_string as an argument.

(We infer from the syntax that this is awk you are talking about.)
Closed Thread

Bookmarks

Tags
awk, awk function

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 06:35 AM.


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