Trouble using shift
From: Oisin Peavoy (oisinpeavoy_at_eircom.net)
Date: 12/31/04
- Next message: Jim: "RE: :Socket::UNIX questions"
- Previous message: Octavian Rasnita: "Re: Copying a hash-of-hashes"
- Next in thread: Paul Johnson: "Re: Trouble using shift"
- Reply: Paul Johnson: "Re: Trouble using shift"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 31 Dec 2004 15:25:53 +0000 To: beginners@perl.org
Hi,
I have a Perl program which I'm having some difficulty with,
essentially I'm
trying to `shift()' all the ellements in an array untill an element
containing a forward slash is encountered. Howerver, the method I'm
using is
producing incorrect results.
If the forward slash is placed infront of "fairy" or "dust" the program
executes correctly, if it's placed infront of one of the other words in
the
list the program doesn't produce the correct results.
Can anyone help with this? What am I doing wrong?
If it matters, I'm using MacOS X.
---CODE---
#!/usr/bin/perl -w
use strict;
my @array = ("fairy", "goblin", "emerald","dust","/dice");
foreach (@array){
if(/(\/)+.+/){
print "last\n";
last;
}else{
print "shift\n";
shift @array;
}
}
print "@array";
- Next message: Jim: "RE: :Socket::UNIX questions"
- Previous message: Octavian Rasnita: "Re: Copying a hash-of-hashes"
- Next in thread: Paul Johnson: "Re: Trouble using shift"
- Reply: Paul Johnson: "Re: Trouble using shift"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]