Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: scoping problems

by naturalsciences (Beadle)
on Jun 03, 2013 at 11:30 UTC ( #1036725=note: print w/replies, xml ) Need Help??


in reply to Re: scoping problems
in thread scoping problems

OK. Thanks for pointing out the $saba and @saba not being related. It is probably bug out of convenience - I seem to have used an array in scalar context easily getting an array length but it seems that a shorthand like this cant travel well around different loops etc.? I did put

for(my $i=0;$i<@saba;++$i) {my $sabasize=scalar(@saba);

on the top of the for loop and it seems to be almost getting somewhere from there. :D so it seems to be that you led me to a better path here.

Replies are listed 'Best First'.
Re^3: scoping problems
by AnomalousMonk (Chancellor) on Jun 03, 2013 at 14:47 UTC

    Further to hdb's reply:

    ... it seems that a shorthand like [evaluating an array in scalar context] cant travel well around different loops etc.?

    It travels perfectly well. hdb and others have already pointed out that  @saba and  $saba are quite different things and are in no way inherently related.

    What may be confusing you is the fact that an element of the  @array array is accessed by the syntax  $array[n] (note the  $ sigil). The logic of this, determined by Larry at the Dawn of Time (Perl version 1.0), is that the elements of arrays (and also of hashes – associative arrays) are always and only scalars. But you always have to distinguish between an array, which contains (like a hash) a certain number of elements and thus has, among other properties, a size, and an element of an array.

      The logic of this, determined by Larry at the Dawn of Time (Perl version 1.0), is that the elements of arrays (and also of hashes associative arrays) are always and only scalars.

      Interestingly, this logic (which sounds perfectly sane to me) has been abandoned in Perl 6. I don't understand why.

      -- FloydATC

      Time flies when you don't know what you're doing

Re^3: scoping problems
by hdb (Monsignor) on Jun 03, 2013 at 11:33 UTC

    If you use @saba, not $saba, in scalar context, you get the arraysize indeed. This is why your $i<@saba works.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1036725]
help
Chatterbox?
choroba played with the band on Saturday, so Sunday was very sleepy
[choroba]: managed to release Syntax::Construct with 5.28 support in the night, though
[Corion]: choroba: Whee ;)
[Corion]: marto: Ouch - I would've thought that kids adapt much better, but that's obviously not the case...
[marto]: well, their mother let them sleep till 15:00 & 12:00 last week, which didn't help them adjust :P
[Corion]: I was "productive" over the weekend in the sense that I revived my old "Perlmonks on SQLite" code, which likely means I can get a test instance back up running on my webhost. Small steps :)
[Corion]: marto: Ow, no, that doesn't help at all :)
[choroba]: Related to the new release, anyone could explain this or this tester report?
[Discipulus]: hello crew! marto thanks for the message: but I how can I help? i'm testing cpan Padre atm problem with Client::Debug
[choroba]: I don't happen to have 5.10.0 nor 5.8.5 handy...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2018-06-25 08:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (126 votes). Check out past polls.

    Notices?