Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

retriving an element from the scalar

Status
Not open for further replies.

1surya

Programmer
Jul 14, 2002
25
CA
this is part of my code

I am taking the 3rd element from each line in a file by using foreach loop and I want to take the 2nd charecter from the scalar variable.But I am not abel to access the 2nd element. can any one help me.


@bhits=split(/ /,$line);
$res=$bhits[2];
$value=substr($res,1,1);


When I want to take the 2nd element from the $res it is giving an error like Bareword.

 
The error must be somewhere else in your script because the code that you posted is ok. It worked when i tested it.

The 'Bareword' error is usually caused by a string not being quoted somewhere.

jaa
 
hi Jaa
thanks you for your reply
I didn't solve my problem.
For example
If I take
$line=ABC
can I access the B letter from the $line variable
If I assign $line = "ABC"
then I can access the B letter by
$ref=substr($line,1,1);
but I am retiving the $line from a file so I can't assign it in quots.
Can you give some more sujjestions
 
The error message should tell you what the Bareword is that it has a problem with. Something like 'Bareword "bark" not allowed while "strict subs" in use at ./commentout.pl line 8'. Look for that word in your script. The problem should be nearby.

If its not a string assignment then most likely you have a variable without a $,@, or %, or you are calling a subroutine that Perl doesn't know about or in a way that it doesn't like

jaa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top