User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Perl section within the Software Development category of DaniWeb, a massive community of 397,627 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 2,360 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:

Program Problem

Join Date: Oct 2007
Posts: 264
Reputation: eggi is on a distinguished road 
Rep Power: 1
Solved Threads: 26
eggi eggi is offline Offline
Posting Whiz in Training

Re: Program Problem

  #2  
Apr 23rd, 2008
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

#!/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!
Reply With Quote  
All times are GMT -4. The time now is 9:14 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC