LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] Perl Problem

[ILUG] Perl Problem

Kevin O Riordan kor at compsoc.com
Thu Feb 7 20:01:41 GMT 2002


Can't give a good explanation, probably something to do with autovivifying
references or something, but if you predeclare the two functions, the code
runs as intended (I've added the two lines in below) ...

-kev


On Pungenday, the 38th day of Chaos, Gavin McCullagh squawked:
> Hi
> 
[liberal snipping]
> 
> #!/usr/bin/perl
> 
> use strict;
> 

# Subroutine declarations.
sub shift2 (\@);
sub pop2 (\@);

> 
> my @friends = qw(Peter Paul Mary Jim Tim);
> (my $this,my $that) = shift2(@friends);
> # $this contains Peter, $that has Paul, and
> # @friends has Mary, Jim, and Tim 
> print "$this | $that\n";
> print "@friends\n";
> 
> my @beverages = qw(Dew Jolt Cola Sprite Fresca);
> my @pair = pop2(@beverages);
> 
> # $pair[0] contains Sprite, $pair[1] has Fresca,
> # and @beverages has (Dew, Jolt, Cola)
> print "@pair\n";
> print "@beverages\n";
> 
> 
> sub shift2 (\@) {
> 	return splice(@{$_[0]}, 0, 2);
> } 
> 
> sub pop2 (\@) {
> 	return splice(@{$_[0]}, -2);
> }




More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell