Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: **HomeWork** Printing the found input from an array

by pKai (Priest)
on Apr 02, 2008 at 21:11 UTC ( #678044=note: print w/replies, xml ) Need Help??


in reply to Re: **HomeWork** Printing the found input from an array
in thread **HomeWork** Printing the found input from an array

# works as expected!

Which depends on you expectations:

my @myCities = (1 .. 2); my $city = "before"; # now is scoped to the whole package! foreach $city ( @myCities ) { # do your stuff $city = "after"; } print "$city"; # works as expected! # ... unless you expected it to print "after" # ... actually it prints "before"

This is a Perl peculiarity I was once also bitten by.

Actually Perl will localize the $city for the scope of the for-loop. See perldoc perlsyn.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://678044]
help
Chatterbox?
[Cosmic37]: when slurping one can undef the record separator thingy; but presumably one should redefine it afterwards? how?
[Cosmic37]: I'm wondering whether there is a specific/(or at least "usual") command or does one take a copy before undefining and then copy it back after slurping file into a string?
[BarApp]: I need help accessing perl files. I need permission!!!
[Cosmic37]: I wish thee a peachy life and express gratitude for considering my pathetic questions

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2017-06-29 16:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (672 votes). Check out past polls.