•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Perl section within the Software Development category of DaniWeb, a massive community of 374,157 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,441 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Perl advertiser:
Views: 587 | Replies: 4 | Solved
![]() |
•
•
Join Date: Oct 2007
Posts: 246
Reputation:
Rep Power: 1
Solved Threads: 26
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)
•
•
•
•
•
•
•
•
DaniWeb Perl Marketplace
Similar Threads
- Help with problem (Java)
- Need help with the program i have written i am unable to correct the problems. please (C++)
- Program Problem with a select statement to access Data base (C)
- how will i repeat my whole game program? (Java)
- Urgent - problem with links (Windows NT / 2000 / XP / 2003)
- *Pointer program problem. (C++)
- File processing problem (C++)
- It's Alive!! Program with a mind of it's own.... (Computer Science and Software Design)
Other Threads in the Perl Forum
- Previous Thread: Perl problem
- Next Thread: Tic Tac Toe


Linear Mode