Hello,
I'm having a lot of trouble getting a program working. I'm trying to open a file, seperate it into an array of words.
I've opened the file and split it into an array of
words. Then I need to take out the punctuation and test to see if any of the words begin with '[' and end in ']'. I'm not sure how to do this with regular expressions. This is what I have so far:
########Code Begin
open($fh,$param) or die "Cannot open file";
$file=<$fh>;
chomp $file;
@words=split(/ /,$file);
$size=@words;
########Code End
I'm then trying to cycle through the array and pull
the punctuation or test for a beginning/ending
character of '[' and ']'
It's not working...and I can't figure out why
########Code Begin
for($ct=0;$ct<$size;$ct++)
{
$theword=@words[$ct];
$_ = $theword;
if (/.,;!?$/)
{
print "test";
}
#######Code End
What am I doing wrong?
Using the regular expression on the $_ variable, it
should notice these punctuation marks at the end of
the word. Also, I'm wondering why I can't access the
first element of a scalar.....like the first
letter....or for this program, the first and last
being brackets.
Please help,
Very Confused,
Justin
I'm having a lot of trouble getting a program working. I'm trying to open a file, seperate it into an array of words.
I've opened the file and split it into an array of
words. Then I need to take out the punctuation and test to see if any of the words begin with '[' and end in ']'. I'm not sure how to do this with regular expressions. This is what I have so far:
########Code Begin
open($fh,$param) or die "Cannot open file";
$file=<$fh>;
chomp $file;
@words=split(/ /,$file);
$size=@words;
########Code End
I'm then trying to cycle through the array and pull
the punctuation or test for a beginning/ending
character of '[' and ']'
It's not working...and I can't figure out why
########Code Begin
for($ct=0;$ct<$size;$ct++)
{
$theword=@words[$ct];
$_ = $theword;
if (/.,;!?$/)
{
print "test";
}
#######Code End
What am I doing wrong?
Using the regular expression on the $_ variable, it
should notice these punctuation marks at the end of
the word. Also, I'm wondering why I can't access the
first element of a scalar.....like the first
letter....or for this program, the first and last
being brackets.
Please help,
Very Confused,
Justin