On Sun, Oct 23, 2005 at 10:49:18AM +0200, Erik van Konijnenburg wrote: > On Sun, Oct 23, 2005 at 08:08:50AM +0200, Sven Luther wrote: > > On Sun, Oct 23, 2005 at 03:00:12AM +0200, Jonas Smedegaard wrote: > > > On Sat, 22 Oct 2005 23:50:10 +0200 Sven Luther <[EMAIL PROTECTED]> wrote: > > > > 1) how can i check if there is only one entry in the ramdisk= > > > > line ? Reading the length of the list, or doing a shift and checking > > > > for and empty list ? > > > > > > split it with the delimiting character (I proposed colon - as in > > > $PATH - but don't know if it makes better sense to use comma or space). > > > > > > > > > Here's what you deciphered yourself tonight in yaird, splitting a path > > > into directoy/file components: > > > > > > my @components = split (/\/+/, $path); > > > > > > > > > If you want _either_ colon, comma or whitespace as delimiter (not sure > > > that is a good idea though) then something like this should work: > > > > > > my @entries = split (/[:,\s]+/, $line); > > > > Well, we already do that, in fact : > > > > (split (/ /, $ramdisk)); > > > > But the problem is not how to split it, but how to detect it is of length 1, > > that is having the legacy single entry in the field. > > Two options: > > a) for array @entries, $#entries will contain index of last element. > if that is -1, there were no elements, if 0, there's exactly > one, named $entries[0]. > > b) if @entries is used in a scalar context, it will be interpreted as > number of elements in the array: > > if (@entries == 1) {print "Just one\n"; }
I implemented something using scalar(@ramdisklist). Works but maybe not as nice. BTW, can i do : if ((scalar @ramdisklist) == 1) ... ? Friendly, Sven Luther -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]