Re: What are these?
by snafu (Chaplain) on Apr 20, 2002 at 07:28 UTC
|
$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... | [reply] [d/l] [select] |
Re: What are these?
by Fletch (Bishop) on Apr 20, 2002 at 04:06 UTC
|
- foo
- bar
- perldoc -f shift explains quite thoroughly.
| [reply] [d/l] |
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&&&' | [reply] [d/l] |
|
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
| [reply] |
|
Situatinck Nrcknal? ;-)
After Compline, Zaxo
| [reply] |
|
s/o(.)l/$1ck/;
does the trick :)
cLive ;-) | [reply] [d/l] |
|
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).
| [reply] |
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. | [reply] |
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!) | [reply] |
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. | [reply] |
|
| [reply] |