Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

What are these?

by Anonymous Monk
on Apr 20, 2002 at 04:00 UTC ( #160727=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

What does foo and bar mean? Also, what does shift do in the context: $whatever = shift;?

Replies are listed 'Best First'.
Re: What are these?
by snafu (Chaplain) on Apr 20, 2002 at 07:28 UTC
    Think of shift and unshift as the opposites of push and pop except in the sense that shift and unshift work from the 'left' of an array and push and pop work from the 'right' of the array.

    eg: Given the list called @foo:

    $foo[0] = 'one'; $foo[1] = 'two'; $foo[2] = 'three';
    If I were to shift on @foo I'd get the a scalar (assuming that is what I am declaring) equal to the value "one" and now @list would be renumbered so that index 0 of @foo would now be "two" and index 1 of @foo would be "three". This goes the same for unshift. You can unshift the old value back to @foo by unshift(@foo,"one");.

    Now, if I push to an array I am actually appending data to the list. If I pop from the array I am taking away from what I just appended thus shifting and unshifting is to add via a prepending of data or taking away what was just prepended.

    _ _ _ _ _ _ _ _ _ _
    - Jim
    Insert clever comment here...

Re: What are these?
by Fletch (Bishop) on Apr 20, 2002 at 04:06 UTC
    • foo
    • bar
    • perldoc -f shift explains quite thoroughly.
Re: What are these?
by qslack (Scribe) on Apr 20, 2002 at 05:56 UTC
    Foo and bar are just demonstration variables. They are used just in examples, when the thing being demonstrated is not the actual implementation of the code, but just a concept.

    Shift removes the first item from the @_ array (or another array if one is provided to the function, or @ARGV if not used in a subroutine) and puts it in $whatever. So if you had this:
    my @foo = ('bar', 'quux'); my $whatever = shift @foo;
    $whatever would contain 'bar,' and @foo would contain only the 'quux' element.

    edit: thanks thelenm - fixed

    Quinn Slack
    perl -e 's ssfhjok qupyrqs&&tr sfjkohpyuqrspitnrapj"hs&&eval&&s&&&'

      Yes, but the actual names 'foo' and 'bar' come from the acronym, 'fubar' (i.e., foobar), which stands for

      Fouled Up Beyond All Recognition.
      Not sure of the actual etymology of the expression, but I heard this from people who are (or have been) in the military (all of whom seem to have heard it).

      Update:: Another acronym in the same family is, 'snafu':

      Situation Normal: All Fouled Up.

      dmm

        Situatinck Nrcknal? ;-)

        After Compline,
        Zaxo

        surely you're just being polite:

        s/o(.)l/$1ck/;
        does the trick :)

        cLive ;-)

      Of course, if you're not in the lexical scope of a subroutine or format, then shift uses @ARGV by default, and not @_ (as explained in perldoc -f shift).
Re: What are these?
by Beatnik (Parson) on Apr 20, 2002 at 23:49 UTC
    Ofcourse don't forget about RFC 3092 which has some definition and the etymology...

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.
Re: What are these?
by mt2k (Hermit) on Apr 20, 2002 at 18:44 UTC
    Mmm... Sure, foo and bar are used as mock-up variable names.
    But if an example requires four variables, are we suppose to make up new variable names or are we suppose to continue, going in the order of foo, bar, baz, qux, etc.? (Bet I fooled ya! No, the 'etc' does not come after 'qux', it stands for what 'etc.' usually means!)
Re: What are these?
by Anonymous Monk on Apr 21, 2002 at 11:43 UTC
    In the movie Saving Private Ryan, the word FUBAR was used to describe anything that depressed the soldiers. FUBAR was an acronym for "Fucked Up Beyond Belief". How FUBAR is related to FOO BAR, I'm not really sure.

      It's 'Beyond All Recognition', not 'Beyond Belief'. AR is a silly acronym for Belief, now isn't it?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2023-11-28 13:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?