Hi,

I am currently learning Perl. I have a problem that seems to be
related to the scoping of variables. Basically the program below
breaks a string up into an array. However, the array @words does
not seem to be accessible inside the code block starting with

           if ( $string = /,/ == 0 )

Presumably it's some kind of scoping problem, but I don't seem to
be able to get a coherent answer from perldoc.

---------------------------------------------------
#!/usr/bin/perl

use strict;
my @words = ();

my $string="This,is,separated,by,commas";
if ( $string = /,/ == 0 ) {
    @words=split(/,/,$string);
}
else {
    @words=split(/ /,$string);
}

my $i;
for ($i=0;$i<@words;$i++) {
   print("$i\n");
   print("@words[$i]\n");
}
---------------------------------------------------

Any help or advice would be greatly appreciated.

cheers,

Bernard Doyle



-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to