Please support our Perl advertiser: Programming Forums
Views: 829 | Replies: 4 | Solved
![]() |
•
•
Join Date: Oct 2007
Posts: 337
Reputation:
Rep Power: 2
Solved Threads: 32
Hey There,
Are you having problems modifying a variable you declare outside of the loop?
This code will increment the variable in the foreach loop and change it's value outside the loop.
Let me know if I'm misunderstanding you
Best Wishes,
Mike
I called it "poil" and this is the output below
Are you having problems modifying a variable you declare outside of the loop?
This code will increment the variable in the foreach loop and change it's value outside the loop.
Let me know if I'm misunderstanding you

Best Wishes,
Mike
#!/usr/bin/perl
$fancy=0;
print "BEFORE $fancy\n";
@loop = qw(1 2 3 4 5 6 7);
foreach $loop (@loop) {
$fancy++;
}
print "AFTER $fancy\n";I called it "poil" and this is the output below
-bash-3.2$ ./poil BEFORE 0 AFTER 7
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)





Linear Mode