Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getline question 1

Status
Not open for further replies.

SpongeBob1

Programmer
Mar 1, 2002
49
0
0
US
This question concerns getlinel;

My understanding of getline is that once it is used; the new value of $0 is used in testing against the patterns of any subsequent rules, may this e prevented & if so how?
 
You can prevent it by getting the input data into a variable, e.g

getline arr gets data from the current file into array arr and leaves $0 undisturbed

getline arr "file.dat" gets data from file.dat into array arr.

See this link for a complete description.

CaKiwi
 
Thanks CaKiwi,

One more question; If I am not using the getline function and am just using

eg.

if ($0 ~ /error/ )

I believe this sets my next usage of $0 to the line containing error; how do I escape this /avoid this & next time I use $0 use the entire ( original )file...
 
Sorry, that should have been

getline arr < &quot;file.dat&quot;

if ($0 ~ /error/ ) does not change $0, it just tests whether $0 contains the string &quot;error&quot;. CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top