Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Parameters, subs and the shift function

by davorg (Chancellor)
on Aug 19, 2003 at 14:13 UTC ( [id://284900]=note: print w/replies, xml ) Need Help??


in reply to Parameters, subs and the shift function

How does the sub manage to figure out what's the size of @a and @b

It doesn't

Update: Yes, as 3dan points out below, there was some incorrect nonsense in this node for about 30 seconds after I posted it. When I realised my error I removed it immediately. Sorry for any confusion caused.

--
<http://www.dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Replies are listed 'Best First'.
Re: Re: Parameters, subs and the shift function
by edan (Curate) on Aug 19, 2003 at 14:22 UTC

    Update: This node is in response to davorg's post, which he has subsequently updated by removing the offending material, so this response as well as the response of Foggy Bottoms becomes garbage. I think in the future, davorg, you should strike out or otherwise update your node, instead of just deleting material that people have already related to.

    so that when you use the shift tool you don't end up with @array1 being "mary","had","a","little","lamb","!","London","Bridge","is"); and @array2 nothing...

    With your code, that's exactly what would happen.

    No, you're wrong. shift returns the first value in the flattened argument list each time it is called, and removes it, so @array1 will be ("mary"), and @array2 will be ("had"). If the code would have been written like this:

    my ($number, @array1, @array2) = @_;

    ... then you'd be right.

    --
    3dan
Re: Re: Parameters, subs and the shift function
by Foggy Bottoms (Monk) on Aug 19, 2003 at 14:17 UTC
    That's not what I understand from what 3dan said, so I'm a bit puzzled. Anyway, I updated my code and the arrays work fine now (cuz I actually had the problem but since I hadn't bothered printing out @array1 and @array2 I hadn't noticed the error, not until I felt the urge to satisfy my curiosity and ask the question here...)
    Thanks

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://284900]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-03-29 00:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found