LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Push All Special Varible Before Calling a Fucnction (https://www.linuxquestions.org/questions/programming-9/push-all-special-varible-before-calling-a-fucnction-842285/)

smc2 11-04-2010 05:17 AM

Push All Special Varible Before Calling a Fucnction
 
Hi...

I have a code like this:
Code:

open (INPUT,"<file"){

while (<INPUT>){
.
.
.
}
if ($_=~/(?:(Error|exception))/){
  $error=$1;
  save_error($error);   
  }
if ($_=~ /somthinelse/)  {
.
.
.
sub save_error($error){
 open(ERRINP,">Err.txt") #open another file and save the error to that file
 print ERRINP $error
 close ERRINP;
  open(ERRINP,"<Err.txt") # open the error log file
 whlie (<ERRINP>){    # for checking  some other condition in error file
 if $_=~/..../ {
  do_some_thing
 }
 pro
.
.
}

opening another file while we have an open file will replace $_ and this cause problem for the second if becuase now $_ has been changed,

is there any way that I can push $_ and other file pointers and pop them after calling a function?


Thanks in advance..

paulsm4 11-05-2010 02:29 PM

Hi -

It looks like you're writing in Perl.

Perl arrays can be used as stacks; you can "push" and "pop" anything you want, to your heart's content:

http://www.ebb.org/PickingUpPerl/pickingUpPerl_4.html

'Hope that helps!


All times are GMT -5. The time now is 02:48 PM.